Check for global leaks in all tests

This commit is contained in:
Ryan Dahl
2010-12-04 13:40:39 -08:00
parent 92789b16e5
commit 02cc39f221
8 changed files with 45 additions and 31 deletions

View File

@@ -24,3 +24,35 @@ exports.indirectInstanceOf = function (obj, cls) {
var objChain = protoCtrChain(obj);
return objChain.slice(-clsChain.length) === clsChain;
};
// Turn this off if the test should not check for global leaks.
exports.globalCheck = true;
process.on('exit', function () {
if (!exports.globalCheck) return;
var knownGlobals = [ setTimeout,
setInterval,
clearTimeout,
clearInterval,
console,
Buffer,
process,
global ];
for (var x in global) {
var found = false;
for (var y in knownGlobals) {
if (global[x] === knownGlobals[y]) {
found = true;
break;
}
}
if (!found) {
console.error("Unknown global: %s", x);
exports.assert.ok(false);
}
}
});

View File

@@ -1,27 +0,0 @@
var assert = require('assert');
var knownGlobals = [ setTimeout
, setInterval
, clearTimeout
, clearInterval
, console
, Buffer
, process
, global
];
for (var x in global) {
var found = false;
for (var y in knownGlobals) {
if (global[x] === knownGlobals[y]) {
found = true;
break;
}
}
if (!found) {
console.error("Unknown global: %s", x);
assert.ok(false);
}
}

View File

@@ -1,6 +1,8 @@
var common = require('../common');
var assert = require('assert');
common.globalCheck = false;
baseFoo = "foo";
global.baseBar = "bar";

View File

@@ -1,6 +1,8 @@
var common = require('../common');
var assert = require('assert');
common.globalCheck = false;
var net = require("net"),
repl = require("repl"),
message = "Read, Eval, Print Loop",

View File

@@ -1,7 +1,9 @@
var common = require('../common');
var assert = require('assert');
var Script = require('vm').Script;
common.globalCheck = false;
common.debug('run a string');
var script = new Script('"passed";');
common.debug('script created');

View File

@@ -1,8 +1,9 @@
var common = require('../common');
var assert = require('assert');
var Script = require('vm').Script;
common.globalCheck = false;
common.debug('run a string');
var result = Script.runInNewContext('"passed";');
assert.equal('passed', result);

View File

@@ -1,8 +1,9 @@
var common = require('../common');
var assert = require('assert');
var Script = require('vm').Script;
common.globalCheck = false;
common.debug('run a string');
var result = Script.runInThisContext('"passed";');
assert.equal('passed', result);

View File

@@ -1,8 +1,9 @@
var common = require('../common');
var assert = require('assert');
var Script = require('vm').Script;
common.globalCheck = false;
common.debug('run a string');
var script = new Script('"passed";');
var result = script.runInThisContext(script);