test: remove common.globalCheck
This flag is partially used in tests where it was not necessary and it is always possible to replace this flag with `common.allowGlobals`. This makes sure all globals are truly tested for. PR-URL: https://github.com/nodejs/node/pull/20717 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
f954aba39e
commit
becc3ec372
@ -150,11 +150,6 @@ Attempts to get a valid TTY file descriptor. Returns `-1` if it fails.
|
|||||||
|
|
||||||
The TTY file descriptor is assumed to be capable of being writable.
|
The TTY file descriptor is assumed to be capable of being writable.
|
||||||
|
|
||||||
### globalCheck
|
|
||||||
* [<boolean>]
|
|
||||||
|
|
||||||
Set to `false` if the test should not check for global leaks.
|
|
||||||
|
|
||||||
### hasCrypto
|
### hasCrypto
|
||||||
* [<boolean>]
|
* [<boolean>]
|
||||||
|
|
||||||
|
@ -366,21 +366,15 @@ function leakedGlobals() {
|
|||||||
}
|
}
|
||||||
exports.leakedGlobals = leakedGlobals;
|
exports.leakedGlobals = leakedGlobals;
|
||||||
|
|
||||||
// Turn this off if the test should not check for global leaks.
|
|
||||||
exports.globalCheck = true;
|
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
if (!exports.globalCheck) return;
|
|
||||||
const leaked = leakedGlobals();
|
const leaked = leakedGlobals();
|
||||||
if (leaked.length > 0) {
|
if (leaked.length > 0) {
|
||||||
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
|
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const mustCallChecks = [];
|
const mustCallChecks = [];
|
||||||
|
|
||||||
|
|
||||||
function runCallChecks(exitCode) {
|
function runCallChecks(exitCode) {
|
||||||
if (exitCode !== 0) return;
|
if (exitCode !== 0) return;
|
||||||
|
|
||||||
|
@ -63,11 +63,7 @@ export function leakedGlobals() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn this off if the test should not check for global leaks.
|
|
||||||
export let globalCheck = true; // eslint-disable-line
|
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
if (!globalCheck) return;
|
|
||||||
const leaked = leakedGlobals();
|
const leaked = leakedGlobals();
|
||||||
if (leaked.length > 0) {
|
if (leaked.length > 0) {
|
||||||
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
|
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
|
||||||
|
@ -29,7 +29,7 @@ if (!common.hasCrypto)
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
// Pollution of global is intentional as part of test.
|
// Pollution of global is intentional as part of test.
|
||||||
common.globalCheck = false;
|
common.allowGlobals(require('domain'));
|
||||||
// See https://github.com/nodejs/node/commit/d1eff9ab
|
// See https://github.com/nodejs/node/commit/d1eff9ab
|
||||||
global.domain = require('domain');
|
global.domain = require('domain');
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ const fixtures = require('../common/fixtures');
|
|||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
common.globalCheck = false;
|
common.allowGlobals('bar', 'foo');
|
||||||
|
|
||||||
baseFoo = 'foo'; // eslint-disable-line no-undef
|
baseFoo = 'foo'; // eslint-disable-line no-undef
|
||||||
global.baseBar = 'bar';
|
global.baseBar = 'bar';
|
||||||
|
@ -25,9 +25,6 @@ const assert = require('assert');
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
|
|
||||||
// This test adds global variables
|
|
||||||
common.globalCheck = false;
|
|
||||||
|
|
||||||
const putIn = new common.ArrayStream();
|
const putIn = new common.ArrayStream();
|
||||||
repl.start('', putIn, null, true);
|
repl.start('', putIn, null, true);
|
||||||
|
|
||||||
@ -65,6 +62,7 @@ function test2() {
|
|||||||
};
|
};
|
||||||
const val = {};
|
const val = {};
|
||||||
global.url = val;
|
global.url = val;
|
||||||
|
common.allowGlobals(val);
|
||||||
assert(!gotWrite);
|
assert(!gotWrite);
|
||||||
putIn.run(['url']);
|
putIn.run(['url']);
|
||||||
assert(gotWrite);
|
assert(gotWrite);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// Flags: --expose-internals
|
// Flags: --expose-internals
|
||||||
|
|
||||||
const common = require('../common');
|
require('../common');
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const REPL = require('internal/repl');
|
const REPL = require('internal/repl');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
@ -47,9 +47,6 @@ function run(test) {
|
|||||||
REPL.createInternalRepl(env, opts, function(err, repl) {
|
REPL.createInternalRepl(env, opts, function(err, repl) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
// The REPL registers 'module' and 'require' globals
|
|
||||||
common.allowGlobals(repl.context.module, repl.context.require);
|
|
||||||
|
|
||||||
assert.strictEqual(expected.terminal, repl.terminal,
|
assert.strictEqual(expected.terminal, repl.terminal,
|
||||||
`Expected ${inspect(expected)} with ${inspect(env)}`);
|
`Expected ${inspect(expected)} with ${inspect(env)}`);
|
||||||
assert.strictEqual(expected.useColors, repl.useColors,
|
assert.strictEqual(expected.useColors, repl.useColors,
|
||||||
|
@ -38,9 +38,6 @@ const replHistoryPath = path.join(tmpdir.path, '.node_repl_history');
|
|||||||
const checkResults = common.mustCall(function(err, r) {
|
const checkResults = common.mustCall(function(err, r) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
// The REPL registers 'module' and 'require' globals
|
|
||||||
common.allowGlobals(r.context.module, r.context.require);
|
|
||||||
|
|
||||||
r.input.end();
|
r.input.end();
|
||||||
const stat = fs.statSync(replHistoryPath);
|
const stat = fs.statSync(replHistoryPath);
|
||||||
const fileMode = stat.mode & 0o777;
|
const fileMode = stat.mode & 0o777;
|
||||||
|
@ -216,9 +216,6 @@ function runTest(assertCleaned) {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The REPL registers 'module' and 'require' globals
|
|
||||||
common.allowGlobals(repl.context.module, repl.context.require);
|
|
||||||
|
|
||||||
repl.once('close', () => {
|
repl.once('close', () => {
|
||||||
if (repl._flushing) {
|
if (repl._flushing) {
|
||||||
repl.once('flushHistory', onClose);
|
repl.once('flushHistory', onClose);
|
||||||
|
@ -26,6 +26,8 @@ const assert = require('assert');
|
|||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
|
common.allowGlobals(42);
|
||||||
|
|
||||||
// Create a dummy stream that does nothing
|
// Create a dummy stream that does nothing
|
||||||
const dummy = new common.ArrayStream();
|
const dummy = new common.ArrayStream();
|
||||||
|
|
||||||
|
@ -18,9 +18,6 @@ const globalTest = (useGlobal, cb, output) => (err, repl) => {
|
|||||||
if (err)
|
if (err)
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
|
||||||
// The REPL registers 'module' and 'require' globals
|
|
||||||
common.allowGlobals(repl.context.module, repl.context.require);
|
|
||||||
|
|
||||||
let str = '';
|
let str = '';
|
||||||
output.on('data', (data) => (str += data));
|
output.on('data', (data) => (str += data));
|
||||||
global.lunch = 'tacos';
|
global.lunch = 'tacos';
|
||||||
|
@ -26,7 +26,6 @@ const assert = require('assert');
|
|||||||
const net = require('net');
|
const net = require('net');
|
||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
|
|
||||||
common.globalCheck = false;
|
|
||||||
common.crashOnUnhandledRejection();
|
common.crashOnUnhandledRejection();
|
||||||
|
|
||||||
const message = 'Read, Eval, Print Loop';
|
const message = 'Read, Eval, Print Loop';
|
||||||
@ -41,7 +40,6 @@ global.invoke_me = function(arg) {
|
|||||||
return `invoked ${arg}`;
|
return `invoked ${arg}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Helpers for describing the expected output:
|
// Helpers for describing the expected output:
|
||||||
const kArrow = /^ *\^+ *$/; // Arrow of ^ pointing to syntax error location
|
const kArrow = /^ *\^+ *$/; // Arrow of ^ pointing to syntax error location
|
||||||
const kSource = Symbol('kSource'); // Placeholder standing for input readback
|
const kSource = Symbol('kSource'); // Placeholder standing for input readback
|
||||||
@ -779,6 +777,7 @@ const tcpTests = [
|
|||||||
|
|
||||||
socket.end();
|
socket.end();
|
||||||
}
|
}
|
||||||
|
common.allowGlobals(...Object.values(global));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function startTCPRepl() {
|
function startTCPRepl() {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
// The v8 modules when imported leak globals. Disable global check.
|
|
||||||
common.globalCheck = false;
|
|
||||||
|
|
||||||
const deprecatedModules = [
|
const deprecatedModules = [
|
||||||
'node-inspect/lib/_inspect',
|
'node-inspect/lib/_inspect',
|
||||||
@ -53,3 +51,6 @@ for (const m of deps) {
|
|||||||
}
|
}
|
||||||
assert.notStrictEqual(path, m);
|
assert.notStrictEqual(path, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The V8 modules add the WebInspector to the globals.
|
||||||
|
common.allowGlobals(global.WebInspector);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
common.globalCheck = false;
|
|
||||||
global.process = {}; // Boom!
|
global.process = {}; // Boom!
|
||||||
|
common.allowGlobals(global.process);
|
||||||
setImmediate(common.mustCall());
|
setImmediate(common.mustCall());
|
||||||
|
@ -24,8 +24,6 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const Script = require('vm').Script;
|
const Script = require('vm').Script;
|
||||||
|
|
||||||
common.globalCheck = false;
|
|
||||||
|
|
||||||
// Run a string
|
// Run a string
|
||||||
let script = new Script('\'passed\';');
|
let script = new Script('\'passed\';');
|
||||||
const result = script.runInThisContext(script);
|
const result = script.runInThisContext(script);
|
||||||
@ -60,3 +58,11 @@ global.f = function() { global.foo = 100; };
|
|||||||
script = new Script('f()');
|
script = new Script('f()');
|
||||||
script.runInThisContext(script);
|
script.runInThisContext(script);
|
||||||
assert.strictEqual(100, global.foo);
|
assert.strictEqual(100, global.foo);
|
||||||
|
|
||||||
|
common.allowGlobals(
|
||||||
|
global.hello,
|
||||||
|
global.code,
|
||||||
|
global.foo,
|
||||||
|
global.obj,
|
||||||
|
global.f
|
||||||
|
);
|
||||||
|
@ -29,8 +29,6 @@ const vm = require('vm');
|
|||||||
assert.strictEqual(typeof global.gc, 'function',
|
assert.strictEqual(typeof global.gc, 'function',
|
||||||
'Run this test with --expose-gc');
|
'Run this test with --expose-gc');
|
||||||
|
|
||||||
common.globalCheck = false;
|
|
||||||
|
|
||||||
// Run a string
|
// Run a string
|
||||||
const result = vm.runInNewContext('\'passed\';');
|
const result = vm.runInNewContext('\'passed\';');
|
||||||
assert.strictEqual(result, 'passed');
|
assert.strictEqual(result, 'passed');
|
||||||
@ -93,3 +91,10 @@ fn();
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
common.allowGlobals(
|
||||||
|
global.hello,
|
||||||
|
global.code,
|
||||||
|
global.foo,
|
||||||
|
global.obj
|
||||||
|
);
|
||||||
|
@ -24,8 +24,6 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
|
|
||||||
common.globalCheck = false;
|
|
||||||
|
|
||||||
// Run a string
|
// Run a string
|
||||||
const result = vm.runInThisContext('\'passed\';');
|
const result = vm.runInThisContext('\'passed\';');
|
||||||
assert.strictEqual('passed', result);
|
assert.strictEqual('passed', result);
|
||||||
@ -58,3 +56,10 @@ assert.strictEqual(1, global.foo);
|
|||||||
global.f = function() { global.foo = 100; };
|
global.f = function() { global.foo = 100; };
|
||||||
vm.runInThisContext('f()');
|
vm.runInThisContext('f()');
|
||||||
assert.strictEqual(100, global.foo);
|
assert.strictEqual(100, global.foo);
|
||||||
|
|
||||||
|
common.allowGlobals(
|
||||||
|
global.hello,
|
||||||
|
global.foo,
|
||||||
|
global.obj,
|
||||||
|
global.f
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user