<commit_before>/*
*******
RUN ME WITH mocha mutator.js
*******
*/


var fs = require('fs-extra'),
    path = require('path'),
    acorn = require('acorn'),
    escodegen = require('escodegen'),
    esrecurse = require('esrecurse');

function parse(o) { return acorn.parse(o, { ranges: true }); }
function unparse(o) { return escodegen.generate(o); }

function mutateTrue(ast) {
  esrecurse.visit(ast, {
    Literal: function(node) {
      node.value = false;
    }
  });
}

var contents = fs.readFileSync('./source.js', 'utf8');
var ast = parse(contents);
mutateTrue(ast);
var mutant = unparse(ast);

var vm = require('vm');
var code = [
  fs.readFileSync('test.js', 'utf8'),
  'var Mocha = require(\'mocha\');',
  'new Mocha({',
  '  reporter: path.resolve(__dirname, \'reporter\')',
  '}).addFile(\'./test\').run()'
].join('\n');

var mock = require('mock-require');
mock('./source', eval(mutant));

global.module = module;
global.require = require;
global.path = path;
global.__dirname = __dirname;
new vm.Script(code).runInThisContext();
<commit_msg>refactored the application of the mutator to use the lib<commit_after>/*
*******
RUN ME WITH mocha mutator.js
*******
*/

var fs = require('fs-extra'),
    path = require('path'),
    acorn = require('acorn'),
    escodegen = require('escodegen'),
    trueToFalse = require('../../../lib/mutators/true-to-false');

function parse(o) { return acorn.parse(o, { ranges: true }); }
function unparse(o) { return escodegen.generate(o); }

var contents = fs.readFileSync('./source.js', 'utf8'),
    ast = parse(contents);

var mutant = unparse(trueToFalse.mutants(ast)[0]);

var vm = require('vm');
var code = [
  fs.readFileSync('test.js', 'utf8'),
  'var Mocha = require(\'mocha\');',
  'new Mocha({',
  '  reporter: path.resolve(__dirname, \'reporter\')',
  '}).addFile(\'./test\').run()'
].join('\n');

var mock = require('mock-require');
mock('./source', eval(mutant));

global.module = module;
global.require = require;
global.path = path;
global.__dirname = __dirname;
new vm.Script(code).runInThisContext();

{'fraction_non_alphanumeric': 0.21328162869607367, 'fraction_numerical': 0.0024236548715462916, 'mean_word_length': 4.278772378516624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '813275', 'n_tokens_mistral': 720, 'n_tokens_neox': 717, 'n_words': 154}