<commit_before>//
//  Author: <NAME> <EMAIL>
//  backendjs 2018
//

const cluster = require('cluster');
const core = require(__dirname + "/../core");
const lib = require(__dirname + "/../lib");
const logger = require(__dirname + "/../logger");
const shell = core.modules.shell;

shell.help.push("-test-run CMD [-test-file FILE] - run a test command in the shell, autoload ./tools/tests.js if exists, optinally can load other file with tests, all other test params will be used as well");

// To be used in the tests, this function takes the following arguments:
//
// expect(ok, ....)
//
//  - ok - it must be true or non empty value in order to continue
//  - all other arguments will be printed to stderr before exiting including the backtrace
//
// assert(failed, ....)
//
//  - failed - it must be false or empty value in order to continue
//  - all arguments will be printed to stderr before exiting including the backtrace
//
// Example
//
//          function testGetUser(next) {
//              db.get("bk_user", { login: "123" }, function(err, row) {
//                   tests.assert(err, "no error expected", row);
//                   tests.expect(row?.id == "123", `id must be 123`, row);
//                   next();
//              });
//          }
shell.expect = function(ok, ...args)
{
    if (ok) return;
    console.error("\n");
    if (this.test) console.error(logger.prefix("TEST"), "FAILED:", cluster.isMaster ? "master" : "worker", this.test.run, this.test.file);
    console.error("Expectation failed:");
    this.die(args);
}

shell.assert = function(...args)
{
    if (!args[0]) return;
    console.error("\n");
    if (this.test) console.error(logger.prefix("TEST"), "FAILED:", cluster.isMaster ? "master" : "worker", this.test.run, this.test.file);
    console.error("Assertion occured:");
    this.die(args);
}

shell.initTests = function()<commit_msg>always print test obj on error<commit_after>//
//  Author: <NAME> <EMAIL>
//  backendjs 2018
//

const cluster = require('cluster');
const core = require(__dirname + "/../core");
const lib = require(__dirname + "/../lib");
const logger = require(__dirname + "/../logger");
const shell = core.modules.shell;

shell.help.push("-test-run CMD [-test-file FILE] - run a test command in the shell, autoload ./tools/tests.js if exists, optinally can load other file with tests, all other test params will be used as well");

// To be used in the tests, this function takes the following arguments:
//
// expect(ok, ....)
//
//  - ok - it must be true or non empty value in order to continue
//  - all other arguments will be printed to stderr before exiting including the backtrace
//
// assert(failed, ....)
//
//  - failed - it must be false or empty value in order to continue
//  - all arguments will be printed to stderr before exiting including the backtrace
//
// Example
//
//          function testGetUser(next) {
//              db.get("bk_user", { login: "123" }, function(err, row) {
//                   tests.assert(err, "no error expected", row);
//                   tests.expect(row?.id == "123", `id must be 123`, row);
//                   next();
//              });
//          }
shell.expect = function(ok, ...args)
{
    if (ok) return;
    console.error("\n");
    if (this.test) {
        console.error(logger.prefix("TEST"), "FAILED:", cluster.isMaster ? "master" : "worker", this.test.run, this.test.file);
        args.push(this.test);
    }
    console.error("Expectation failed:");
    this.die(args);
}

shell.assert = function(...args)
{
    if (!args[0]) return;
    console.error("\n");
    if (this.test) {
        console.error(logger.prefix("TEST"), "FAILED:", cluster.isMaster ? "master" : "worker", this.test.run, this.test.file);
        args.push(this.test);
    }
    console.error("Assertion occured:");
    this.die(args);
}

shell.initTests = function()
{'fraction_non_alphanumeric': 0.16834495223341078, 'fraction_numerical': 0.007229537825974697, 'mean_word_length': 2.587037037037037, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1256451', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1147, 'n_words': 364}