Skip to content

Commit

Permalink
test: use assert.match instead of regexp.test
Browse files Browse the repository at this point in the history
PR-URL: #39928
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Zijian Liu <[email protected]>
  • Loading branch information
targos committed Aug 31, 2021
1 parent 162f07b commit 508890d
Show file tree
Hide file tree
Showing 98 changed files with 260 additions and 260 deletions.
10 changes: 5 additions & 5 deletions test/abort/test-addon-uv-handle-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ if (process.argv[2] === 'child') {

switch (state) {
case 'initial':
assert(/^uv loop at \[.+\] has open handles:$/.test(line), line);
assert.match(line, /^uv loop at \[.+\] has open handles:$/);
state = 'handle-start';
break;
case 'handle-start':
if (/^uv loop at \[.+\] has \d+ open handles in total$/.test(line)) {
state = 'assertion-failure';
break;
}
assert(/^\[.+\] timer( \(active\))?$/.test(line), line);
assert.match(line, /^\[.+\] timer( \(active\))?$/);
state = 'close-callback';
break;
case 'close-callback':
assert(/^Close callback:/.test(line), line);
assert.match(line, /^Close callback:/);
state = 'data';
break;
case 'data':
assert(/^Data: .+$/.test(line), line);
assert.match(line, /^Data: .+$/);
state = 'maybe-first-field';
break;
case 'maybe-first-field':
Expand All @@ -116,7 +116,7 @@ if (process.argv[2] === 'child') {
state = 'handle-start';
break;
case 'assertion-failure':
assert(/Assertion .+ failed/.test(line), line);
assert.match(line, /Assertion .+ failed/);
state = 'done';
break;
case 'done':
Expand Down
2 changes: 1 addition & 1 deletion test/addons/errno-exception/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ const err = binding.errno();
assert.strictEqual(err.syscall, 'syscall');
assert.strictEqual(err.errno, 10);
assert.strictEqual(err.path, 'päth');
assert.ok(/^Error:\s\w+, some error msg 'päth'$/.test(err.toString()));
assert.match(err.toString(), /^Error:\s\w+, some error msg 'päth'$/);
12 changes: 6 additions & 6 deletions test/async-hooks/test-emit-after-on-destroyed.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ if (process.argv[2] === 'child') {

child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
12 changes: 6 additions & 6 deletions test/async-hooks/test-emit-before-on-destroyed.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ if (process.argv[2] === 'child') {

child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
12 changes: 6 additions & 6 deletions test/async-hooks/test-improper-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ if (process.argv[2] === 'child') {

child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
12 changes: 6 additions & 6 deletions test/async-hooks/test-improper-unwind.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ if (process.argv[2] === 'child') {

child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
2 changes: 1 addition & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ function _expectWarning(name, expected, code) {
if (typeof message === 'string') {
assert.strictEqual(warning.message, message);
} else {
assert(message.test(warning.message));
assert.match(warning.message, message);
}
assert.strictEqual(warning.code, code);
}, expected.length);
Expand Down
6 changes: 3 additions & 3 deletions test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function _validateContent(report, fields = []) {
header.networkInterfaces.forEach((iface) => {
assert.strictEqual(typeof iface.name, 'string');
assert.strictEqual(typeof iface.internal, 'boolean');
assert(/^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i.test(iface.mac));
assert.match(iface.mac, /^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i);

if (iface.family === 'IPv4') {
assert.strictEqual(net.isIPv4(iface.address), true);
Expand All @@ -171,7 +171,7 @@ function _validateContent(report, fields = []) {
assert(typeof frame === 'object' && frame !== null);
checkForUnknownFields(frame, ['pc', 'symbol']);
assert.strictEqual(typeof frame.pc, 'string');
assert(/^0x[0-9a-f]+$/.test(frame.pc));
assert.match(frame.pc, /^0x[0-9a-f]+$/);
assert.strictEqual(typeof frame.symbol, 'string');
});

Expand Down Expand Up @@ -250,7 +250,7 @@ function _validateContent(report, fields = []) {
report.libuv.forEach((resource) => {
assert.strictEqual(typeof resource.type, 'string');
assert.strictEqual(typeof resource.address, 'string');
assert(/^0x[0-9a-f]+$/.test(resource.address));
assert.match(resource.address, /^0x[0-9a-f]+$/);
assert.strictEqual(typeof resource.is_active, 'boolean');
assert.strictEqual(typeof resource.is_referenced,
resource.type === 'loop' ? 'undefined' : 'boolean');
Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-dns-ipv6.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ TEST(function test_lookup_ipv6_hint(done) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'EAI_BADFLAGS');
assert.strictEqual(err.hostname, addresses.INET_HOST);
assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message));
assert.match(err.message, /getaddrinfo EAI_BADFLAGS/);
done();
return;
}
Expand Down
6 changes: 3 additions & 3 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ TEST(function test_lookup_failure(done) {
assert.ok(err instanceof Error);
assert.strictEqual(err.code, dns.NOTFOUND);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.ok(!/ENOENT/.test(err.message));
assert.doesNotMatch(err.message, !/ENOENT/);
assert.ok(err.message.includes(addresses.NOT_FOUND));

done();
Expand Down Expand Up @@ -640,7 +640,7 @@ TEST(function test_lookupservice_invalid(done) {
const req = dns.lookupService('1.2.3.4', 80, (err) => {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.ok(/1\.2\.3\.4/.test(err.message));
assert.match(err.message, /1\.2\.3\.4/);

done();
});
Expand All @@ -662,7 +662,7 @@ TEST(function test_reverse_failure(done) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
assert.strictEqual(err.hostname, '203.0.113.0');
assert.ok(/203\.0\.113\.0/.test(err.message));
assert.match(err.message, /203\.0\.113\.0/);

done();
});
Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-inspector-help-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function check(url, cb) {
});

res.on('end', common.mustCall(() => {
assert(/>Debugging Guide</.test(result));
assert.match(result, />Debugging Guide</);
cb();
}));
})).on('error', common.mustNotCall);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-assert-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ promises.push(assert.rejects(
assert.strictEqual(err.code, 'ERR_ASSERTION');
assert.strictEqual(err.actual, actual);
assert.strictEqual(err.operator, 'rejects');
assert(/rejects/.test(err.stack));
assert.match(err.stack, /rejects/);
return true;
};
const err = new Error();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ assert.throws(
assert.deepStrictEqual(Array(100).fill(1), 'foobar');
} catch (err) {
threw = true;
assert(/actual: \[Array],\n expected: 'foobar',/.test(inspect(err)));
assert.match(inspect(err), /actual: \[Array],\n expected: 'foobar',/);
}
assert(threw);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-async-wrap-pop-id-during-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ const ret = spawnSync(
assert.strictEqual(ret.status, 0,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.ok(!/async.*hook/i.test(stderr));
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-prototype-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ const util = require('util');

{
const buf = Buffer.from('x'.repeat(51));
assert.ok(/^<Buffer (?:78 ){50}\.\.\. 1 more byte>$/.test(util.inspect(buf)));
assert.match(util.inspect(buf), /^<Buffer (?:78 ){50}\.\.\. 1 more byte>$/);
}
4 changes: 2 additions & 2 deletions test/parallel/test-cli-syntax-piped-bad.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ syntaxArgs.forEach(function(arg) {
assert.strictEqual(c.stdout, '');

// stderr should have a syntax error message
assert(syntaxErrorRE.test(c.stderr), `${syntaxErrorRE} === ${c.stderr}`);
assert.match(c.stderr, syntaxErrorRE);

assert.strictEqual(c.status, 1);
});
Expand All @@ -50,7 +50,7 @@ syntaxArgs.forEach(function(arg) {
assert.strictEqual(c.stdout, '');

// stderr should have a syntax error message
assert(syntaxErrorRE.test(c.stderr), `${syntaxErrorRE} === ${c.stderr}`);
assert.match(c.stderr, syntaxErrorRE);

assert.strictEqual(c.status, 1);
});
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-fork-windowsHide.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (!process.argv[2]) {
workerOnline: common.mustCall((msg) => {
}),
mainWindowHandle: common.mustCall((msg) => {
assert.ok(/0\s*/.test(msg.value));
assert.match(msg.value, /0\s*/);
}),
workerExit: common.mustCall((msg) => {
assert.strictEqual(msg.code, 0);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const { join } = require('path');
const p = fixtures.path('leakedGlobal.js');
execFile(process.execPath, [p], common.mustCall((err, stdout, stderr) => {
assert.notStrictEqual(err.code, 0);
assert.ok(/\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/.test(stderr));
assert.match(stderr, /\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/);
}));
}

Expand Down Expand Up @@ -130,7 +130,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
// Test `tmpdir`.
{
tmpdir.refresh();
assert.ok(/\.tmp\.\d+/.test(tmpdir.path));
assert.match(tmpdir.path, /\.tmp\.\d+/);
const sentinelPath = join(tmpdir.path, 'gaga');
writeFileSync(sentinelPath, 'googoo');
tmpdir.refresh();
Expand Down
35 changes: 19 additions & 16 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,24 +246,27 @@ assert.ok(strings[0].includes('foo: { bar: { baz:'));
assert.ok(strings[0].includes('quux'));
assert.ok(strings.shift().includes('quux: true'));

assert.ok(/^label: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^__proto__: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^constructor: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^hasOwnProperty: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.match(strings.shift().trim(), /^label: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^__proto__: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^constructor: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^hasOwnProperty: \d+(\.\d{1,3})?(ms|s)$/);

// Verify that console.time() coerces label values to strings as expected
assert.ok(/^: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^null: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^NaN: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));

assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) test$/.test(strings.shift().trim()));
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/.test(strings.shift().trim()));
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.match(strings.shift().trim(), /^: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(),
/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(),
/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^null: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^NaN: \d+(\.\d{1,3})?(ms|s)$/);

assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s) test$/);
assert.match(strings.shift().trim(),
/^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/);
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/);

// Make sure that we checked all strings
assert.strictEqual(strings.length, 0);
Expand Down
Loading

0 comments on commit 508890d

Please sign in to comment.