Skip to content

Commit bca5a39

Browse files
ricardobeatlukeapage
authored andcommitted
Check for global variable leaks
1 parent 6d160a2 commit bca5a39

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/less-test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var path = require('path'),
55
var less = require('../lib/less');
66
var stylize = require('../lib/less/lessc_helper').stylize;
77

8+
var globals = Object.keys(global);
9+
810
var oneTestOnly = process.argv[2];
911

1012
var totalTests = 0,
@@ -77,6 +79,12 @@ function globalReplacements(input, directory) {
7779
.replace(/\r\n/g, '\n');
7880
}
7981

82+
function checkGlobalLeaks() {
83+
return Object.keys(global).filter(function(v) {
84+
return globals.indexOf(v) < 0;
85+
});
86+
}
87+
8088
function runTestSet(options, foldername, verifyFunction, nameModifier, doReplacements) {
8189
foldername = foldername || "";
8290

@@ -147,6 +155,7 @@ function ok(msg) {
147155
}
148156

149157
function endTest() {
158+
var leaked = checkGlobalLeaks();
150159
if (failedTests + passedTests === totalTests) {
151160
sys.puts("");
152161
sys.puts("");
@@ -158,6 +167,12 @@ function endTest() {
158167
sys.print(stylize("All Passed ", "green"));
159168
sys.print(passedTests + " run");
160169
}
170+
if (leaked.length > 0) {
171+
sys.puts("");
172+
sys.puts("");
173+
sys.print(stylize("Global leak detected: ", "red") + leaked.join(', '));
174+
sys.print("\n");
175+
}
161176
}
162177
}
163178

@@ -196,4 +211,4 @@ function testNoOptions() {
196211
return;
197212
}
198213
ok(stylize("OK\n", "green"));
199-
}
214+
}

0 commit comments

Comments
 (0)