<commit_before>/*jslint indent: 2, nomen: true, maxlen: 120, regexp: true, todo: true */
/*global module, require, exports, print */
var RunTest = require('jsunity').runTest;
var _ = require("underscore");
var internal = require('internal');
var fs = require('fs');

////////////////////////////////////////////////////////////////////////////////
/// @brief runs all jsunity tests
////////////////////////////////////////////////////////////////////////////////

function RunJSUnityTests (tests) {
  var result = true,
    i,
    file,
    ok;

  for (i = 0;  i < tests.length;  ++i) {
    file = tests[i];
    print();
    print("running tests from file '" + file + "'");

    try {
      ok = RunTest(file);
      result = result && ok;
    }
    catch (err) {
      print("cannot run test file '" + file + "': " + err);
      print(err.stack);
      result = false;
    }

    internal.wait(0); // force GC
  }

  return result;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief runs all jsunity tests
////////////////////////////////////////////////////////////////////////////////

function RunJasmineTests (testFiles) {
  var result = true;

  if (testFiles.length > 0) {
    var tests = _.map(testFiles, function (x) { return fs.read(x); }),
      jasmine = require('jasmine');

    print('\nRunning Jasmine Tests: ' + testFiles.join(', '));
    result = jasmine.executeTestSuite(tests);
  }

  return result;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief runs tests from command-line
////////////////////////////////////////////////////////////////////////////////

function runCommandLineTests () {
  var result = true,
    unitTests = internal.unitTests(),
    isSpecRegEx = /.+spec.js/,
    isSpec = function(unitTest) {
      return isSpecRegEx.test(unitTest);
    },
    jasmine = _.filter(unitTests, isSpec),
    jsUnity = _.reject(unitTests, isSpec);

  result = RunJSUnityTests(jsUnity) && RunJasmineTests(jasmine);

  internal.setUnitTestsResult(result);
}

exports.runCommandLineTests = runCommandLineTests;<commit_msg>Refactor Test Runner<commit_after>/*jslint indent: 2, nomen: true, maxlen: 120, regexp: true, todo: true */
/*global module, require, exports, print */

var runTest = require('jsunity').runTest,
  _ = require('underscore'),
  internal = require('internal'),
  fs = require('fs'),
  runJSUnityTests,
  runJasmineTests,
  runCommandLineTests;

////////////////////////////////////////////////////////////////////////////////
/// @brief runs all jsunity tests
////////////////////////////////////////////////////////////////////////////////

runJSUnityTests = function (tests) {
  'use strict';
  var result = true;

  _.each(tests, function (file) {
    print("\nRunning JSUnity test from file '" + file + "'");

    try {
      result = result && runTest(file);
    } catch (err) {
      print("cannot run test file '" + file + "': " + err);
      print(err.stack);
      result = false;
    }

    internal.wait(0); // force GC
  });

  return result;
};

////////////////////////////////////////////////////////////////////////////////
/// @brief runs all jsunity tests
////////////////////////////////////////////////////////////////////////////////

runJasmineTests = function (testFiles) {
  'use strict';
  var result = true,
    tests,
    jasmine;

  if (testFiles.length > 0) {
    tests = _.map(testFiles, function (x) { return fs.read(x); });
    jasmine = require('jasmine');

    print('\nRunning Jasmine Tests: ' + testFiles.join(', '));
    result = jasmine.executeTestSuite(tests);
  }

  return result;
};

////////////////////////////////////////////////////////////////////////////////
/// @brief runs tests from command-line
////////////////////////////////////////////////////////////////////////////////

runCommandLineTests = function () {
  'use strict';
  var result = true,
    unitTests = internal.unitTests(),
    isSpecRegEx = /.+spec.js/,
    isSpec = function (unitTest) {
      return isSpecRegEx.test(unitTest);
    },
    jasmine = _.filter(unitTests, isSpec),
    jsUnity = _.reject(unitTests, isSpec);

  result = runJSUnityTests(jsUnity) && runJasmineTests(jasmine);

  internal.setUnitTestsResult(result);
};

exports.runCommandLineTests = runCommandLineTests;
{'fraction_non_alphanumeric': 0.337029337029337, 'fraction_numerical': 0.003003003003003003, 'mean_word_length': 1.4518686296715742, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '4989354', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1104, 'n_words': 275}