<commit_before>// include the fs module
var fs = require("fs"),
// sandboxing module
vm = require("vm"),
// path utilities
path = require("path"),
// read options from commandline
options = JSON.parse(process.argv[2]),
// misc variables
currentmodule;

// globals needed by qunit sandbox
var sandbox = {
	require : require,
	exports : {},
	setTimeout : setTimeout,
	setInterval : setInterval,
	clearTimeout : clearTimeout,
	clearInterval : clearInterval,
	console : console,
	attachEvent : function(event, method) {
		setImmediate(function() {
			method.call(sandbox);
		});
	}
};
// window/global/root is a circualr reference
sandbox.window = sandbox;
sandbox.global = sandbox;

// create a new context
var context = vm.createContext(sandbox);

// load source and tests into the sandbox
function load(src) {
	if (!src) {
		return;
	}
	if (!Array.isArray(src)) {
		src = [ src ];
	}
	// build up the source file
	src.forEach(function(file) {
		try {
			vm.runInContext(fs.readFileSync(path.join(options.dir, file), "utf8"), context, path.join(options.dir, file));
		} catch (e) {
			console.log(e.message + " in " + file);
			process.exit(1);
		}
	});
}

// load up qunit
load("test/qunit/qunit/qunit.js");

// have a global reference to QUnit within the sandbox
context.QUnit = context.exports;
context.exports = {};
delete context.window;

// don't have qunit reorder tests
context.QUnit.config = context.QUnit.config || {};
context.QUnit.config.reorder = false;
context.QUnit.config.autorun = true;

// add event listeners to the qunit test events
context.QUnit.log(function(data) {
	data.test = this.config.current.testName;
	data.module = currentmodule;
	process.send({
		event : "assertionDone",
		data : data
	});
});
context.QUnit.testStart(function(data) {
	// use last module name if no module name defined
	currentmodule = data.module || currentmodule;
	data.test = this.config.current.testName;
	data.module = currentmodule;
	process.send({
		event : "testStart",
		data : data
	});
});
context.QUnit.testDone(function(data) {
	// use last module name if no module name defined
	data.module = data.module || currentmodule;
	process.send({
		event : "testDone",
		data : data
	});
});
context.QUnit.moduleStart(function(data) {
	process.send({
		event : "moduleStart",
		data : data
	});
});
context.QUnit.moduleDone(function(data) {
	process.send({
		event : "moduleDone",
		data : data
	});
});

// override the done function to signal back to the parent process that this unit test is done
context.QUnit.done((function() {
	var timeout = null, later = function(data) {
		timeout = null;
		process.send({
			event : "done",
			data : data
		});
	};
	return function(data) {
		clearTimeout(timeout);
		timeout = setTimeout(function() {
			later(data);
		}, 1000);
	};
})());

if (options.setUp) {
	vm.runInContext("(" + options.setUp + ").call(this);", context);
}

// load dependencies
load(options.data.deps);

// load up the source files
load(options.data.code);

// load up the test files
load(options.data.tests);
<commit_msg>nodejs 0.8 does not have setImmediate<commit_after>// include the fs module
var fs = require("fs"),
// sandboxing module
vm = require("vm"),
// path utilities
path = require("path"),
// read options from commandline
options = JSON.parse(process.argv[2]),
// misc variables
currentmodule;

// globals needed by qunit sandbox
var sandbox = {
	require : require,
	exports : {},
	setTimeout : setTimeout,
	setInterval : setInterval,
	clearTimeout : clearTimeout,
	clearInterval : clearInterval,
	console : console,
	attachEvent : function(event, method) {
		setTimeout(function() {
			method.call(sandbox);
		}, 1);
	}
};
// window/global/root is a circualr reference
sandbox.window = sandbox;
sandbox.global = sandbox;

// create a new context
var context = vm.createContext(sandbox);

// load source and tests into the sandbox
function load(src) {
	if (!src) {
		return;
	}
	if (!Array.isArray(src)) {
		src = [ src ];
	}
	// build up the source file
	src.forEach(function(file) {
		try {
			vm.runInContext(fs.readFileSync(path.join(options.dir, file), "utf8"), context, path.join(options.dir, file));
		} catch (e) {
			console.log(e.message + " in " + file);
			process.exit(1);
		}
	});
}

// load up qunit
load("test/qunit/qunit/qunit.js");

// have a global reference to QUnit within the sandbox
context.QUnit = context.exports;
context.exports = {};
delete context.window;

// don't have qunit reorder tests
context.QUnit.config = context.QUnit.config || {};
context.QUnit.config.reorder = false;
context.QUnit.config.autorun = true;

// add event listeners to the qunit test events
context.QUnit.log(function(data) {
	data.test = this.config.current.testName;
	data.module = currentmodule;
	process.send({
		event : "assertionDone",
		data : data
	});
});
context.QUnit.testStart(function(data) {
	// use last module name if no module name defined
	currentmodule = data.module || currentmodule;
	data.test = this.config.current.testName;
	data.module = currentmodule;
	process.send({
		event : "testStart",
		data : data
	});
});
context.QUnit.testDone(function(data) {
	// use last module name if no module name defined
	data.module = data.module || currentmodule;
	process.send({
		event : "testDone",
		data : data
	});
});
context.QUnit.moduleStart(function(data) {
	process.send({
		event : "moduleStart",
		data : data
	});
});
context.QUnit.moduleDone(function(data) {
	process.send({
		event : "moduleDone",
		data : data
	});
});

// override the done function to signal back to the parent process that this unit test is done
context.QUnit.done((function() {
	var timeout = null, later = function(data) {
		timeout = null;
		process.send({
			event : "done",
			data : data
		});
	};
	return function(data) {
		clearTimeout(timeout);
		timeout = setTimeout(function() {
			later(data);
		}, 1000);
	};
})());

if (options.setUp) {
	vm.runInContext("(" + options.setUp + ").call(this);", context);
}

// load dependencies
load(options.data.deps);

// load up the source files
load(options.data.code);

// load up the test files
load(options.data.tests);

{'fraction_non_alphanumeric': 0.14858451971854034, 'fraction_numerical': 0.0027818687612502046, 'mean_word_length': 3.9369951534733443, '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': '3809206', 'n_tokens_mistral': 2102, 'n_tokens_neox': 2009, 'n_words': 522}