Check for global variable leaks

This commit is contained in:
Ricardo Tomasi
2013-07-04 20:56:15 -03:00
committed by Luke Page
parent 6d160a2b9a
commit bca5a39d3b

View File

@@ -5,6 +5,8 @@ var path = require('path'),
var less = require('../lib/less');
var stylize = require('../lib/less/lessc_helper').stylize;
var globals = Object.keys(global);
var oneTestOnly = process.argv[2];
var totalTests = 0,
@@ -77,6 +79,12 @@ function globalReplacements(input, directory) {
.replace(/\r\n/g, '\n');
}
function checkGlobalLeaks() {
return Object.keys(global).filter(function(v) {
return globals.indexOf(v) < 0;
});
}
function runTestSet(options, foldername, verifyFunction, nameModifier, doReplacements) {
foldername = foldername || "";
@@ -147,6 +155,7 @@ function ok(msg) {
}
function endTest() {
var leaked = checkGlobalLeaks();
if (failedTests + passedTests === totalTests) {
sys.puts("");
sys.puts("");
@@ -158,6 +167,12 @@ function endTest() {
sys.print(stylize("All Passed ", "green"));
sys.print(passedTests + " run");
}
if (leaked.length > 0) {
sys.puts("");
sys.puts("");
sys.print(stylize("Global leak detected: ", "red") + leaked.join(', '));
sys.print("\n");
}
}
}
@@ -196,4 +211,4 @@ function testNoOptions() {
return;
}
ok(stylize("OK\n", "green"));
}
}