Skip to content

Commit ca9b781

Browse files
committed
test: use assert.match instead of regexp.test
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]>
1 parent 29c4b07 commit ca9b781

File tree

98 files changed

+260
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+260
-260
lines changed

test/abort/test-addon-uv-handle-leak.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ if (process.argv[2] === 'child') {
9090

9191
switch (state) {
9292
case 'initial':
93-
assert(/^uv loop at \[.+\] has open handles:$/.test(line), line);
93+
assert.match(line, /^uv loop at \[.+\] has open handles:$/);
9494
state = 'handle-start';
9595
break;
9696
case 'handle-start':
9797
if (/^uv loop at \[.+\] has \d+ open handles in total$/.test(line)) {
9898
state = 'assertion-failure';
9999
break;
100100
}
101-
assert(/^\[.+\] timer( \(active\))?$/.test(line), line);
101+
assert.match(line, /^\[.+\] timer( \(active\))?$/);
102102
state = 'close-callback';
103103
break;
104104
case 'close-callback':
105-
assert(/^Close callback:/.test(line), line);
105+
assert.match(line, /^Close callback:/);
106106
state = 'data';
107107
break;
108108
case 'data':
109-
assert(/^Data: .+$/.test(line), line);
109+
assert.match(line, /^Data: .+$/);
110110
state = 'maybe-first-field';
111111
break;
112112
case 'maybe-first-field':
@@ -116,7 +116,7 @@ if (process.argv[2] === 'child') {
116116
state = 'handle-start';
117117
break;
118118
case 'assertion-failure':
119-
assert(/Assertion .+ failed/.test(line), line);
119+
assert.match(line, /Assertion .+ failed/);
120120
state = 'done';
121121
break;
122122
case 'done':

test/addons/errno-exception/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ const err = binding.errno();
1212
assert.strictEqual(err.syscall, 'syscall');
1313
assert.strictEqual(err.errno, 10);
1414
assert.strictEqual(err.path, 'päth');
15-
assert.ok(/^Error:\s\w+, some error msg 'päth'$/.test(err.toString()));
15+
assert.match(err.toString(), /^Error:\s\w+, some error msg 'päth'$/);

test/async-hooks/test-emit-after-on-destroyed.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ if (process.argv[2] === 'child') {
5454

5555
child.on('close', common.mustCall((code) => {
5656
assert.strictEqual(code, 1);
57-
assert.ok(heartbeatMsg.test(outData.toString()),
58-
'did not crash until we reached offending line of code ' +
59-
`(found ${outData})`);
60-
assert.ok(corruptedMsg.test(errData.toString()),
61-
'printed error contains corrupted message ' +
62-
`(found ${errData})`);
57+
assert.match(outData.toString(), heartbeatMsg,
58+
'did not crash until we reached offending line of code ' +
59+
`(found ${outData})`);
60+
assert.match(errData.toString(), corruptedMsg,
61+
'printed error contains corrupted message ' +
62+
`(found ${errData})`);
6363
}));
6464
}

test/async-hooks/test-emit-before-on-destroyed.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ if (process.argv[2] === 'child') {
5454

5555
child.on('close', common.mustCall((code) => {
5656
assert.strictEqual(code, 1);
57-
assert.ok(heartbeatMsg.test(outData.toString()),
58-
'did not crash until we reached offending line of code ' +
59-
`(found ${outData})`);
60-
assert.ok(corruptedMsg.test(errData.toString()),
61-
'printed error contains corrupted message ' +
62-
`(found ${errData})`);
57+
assert.match(outData.toString(), heartbeatMsg,
58+
'did not crash until we reached offending line of code ' +
59+
`(found ${outData})`);
60+
assert.match(errData.toString(), corruptedMsg,
61+
'printed error contains corrupted message ' +
62+
`(found ${errData})`);
6363
}));
6464
}

test/async-hooks/test-improper-order.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ if (process.argv[2] === 'child') {
5353

5454
child.on('close', common.mustCall((code) => {
5555
assert.strictEqual(code, 1);
56-
assert.ok(heartbeatMsg.test(outData.toString()),
57-
'did not crash until we reached offending line of code ' +
58-
`(found ${outData})`);
59-
assert.ok(corruptedMsg.test(errData.toString()),
60-
'printed error contains corrupted message ' +
61-
`(found ${errData})`);
56+
assert.match(outData.toString(), heartbeatMsg,
57+
'did not crash until we reached offending line of code ' +
58+
`(found ${outData})`);
59+
assert.match(errData.toString(), corruptedMsg,
60+
'printed error contains corrupted message ' +
61+
`(found ${errData})`);
6262
}));
6363
}

test/async-hooks/test-improper-unwind.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ if (process.argv[2] === 'child') {
5757

5858
child.on('close', common.mustCall((code) => {
5959
assert.strictEqual(code, 1);
60-
assert.ok(heartbeatMsg.test(outData.toString()),
61-
'did not crash until we reached offending line of code ' +
62-
`(found ${outData})`);
63-
assert.ok(corruptedMsg.test(errData.toString()),
64-
'printed error contains corrupted message ' +
65-
`(found ${errData})`);
60+
assert.match(outData.toString(), heartbeatMsg,
61+
'did not crash until we reached offending line of code ' +
62+
`(found ${outData})`);
63+
assert.match(errData.toString(), corruptedMsg,
64+
'printed error contains corrupted message ' +
65+
`(found ${errData})`);
6666
}));
6767
}

test/common/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ function _expectWarning(name, expected, code) {
547547
if (typeof message === 'string') {
548548
assert.strictEqual(warning.message, message);
549549
} else {
550-
assert(message.test(warning.message));
550+
assert.match(warning.message, message);
551551
}
552552
assert.strictEqual(warning.code, code);
553553
}, expected.length);

test/common/report.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function _validateContent(report, fields = []) {
146146
header.networkInterfaces.forEach((iface) => {
147147
assert.strictEqual(typeof iface.name, 'string');
148148
assert.strictEqual(typeof iface.internal, 'boolean');
149-
assert(/^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i.test(iface.mac));
149+
assert.match(iface.mac, /^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i);
150150

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

@@ -250,7 +250,7 @@ function _validateContent(report, fields = []) {
250250
report.libuv.forEach((resource) => {
251251
assert.strictEqual(typeof resource.type, 'string');
252252
assert.strictEqual(typeof resource.address, 'string');
253-
assert(/^0x[0-9a-f]+$/.test(resource.address));
253+
assert.match(resource.address, /^0x[0-9a-f]+$/);
254254
assert.strictEqual(typeof resource.is_active, 'boolean');
255255
assert.strictEqual(typeof resource.is_referenced,
256256
resource.type === 'loop' ? 'undefined' : 'boolean');

test/internet/test-dns-ipv6.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ TEST(function test_lookup_ipv6_hint(done) {
142142
assert(err instanceof Error);
143143
assert.strictEqual(err.code, 'EAI_BADFLAGS');
144144
assert.strictEqual(err.hostname, addresses.INET_HOST);
145-
assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message));
145+
assert.match(err.message, /getaddrinfo EAI_BADFLAGS/);
146146
done();
147147
return;
148148
}

test/internet/test-dns.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ TEST(function test_lookup_failure(done) {
527527
assert.ok(err instanceof Error);
528528
assert.strictEqual(err.code, dns.NOTFOUND);
529529
assert.strictEqual(err.code, 'ENOTFOUND');
530-
assert.ok(!/ENOENT/.test(err.message));
530+
assert.doesNotMatch(err.message, !/ENOENT/);
531531
assert.ok(err.message.includes(addresses.NOT_FOUND));
532532

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

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

667667
done();
668668
});

test/internet/test-inspector-help-page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function check(url, cb) {
2828
});
2929

3030
res.on('end', common.mustCall(() => {
31-
assert(/>Debugging Guide</.test(result));
31+
assert.match(result, />Debugging Guide</);
3232
cb();
3333
}));
3434
})).on('error', common.mustNotCall);

test/parallel/test-assert-async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ promises.push(assert.rejects(
136136
assert.strictEqual(err.code, 'ERR_ASSERTION');
137137
assert.strictEqual(err.actual, actual);
138138
assert.strictEqual(err.operator, 'rejects');
139-
assert(/rejects/.test(err.stack));
139+
assert.match(err.stack, /rejects/);
140140
return true;
141141
};
142142
const err = new Error();

test/parallel/test-assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ assert.throws(
12461246
assert.deepStrictEqual(Array(100).fill(1), 'foobar');
12471247
} catch (err) {
12481248
threw = true;
1249-
assert(/actual: \[Array],\n expected: 'foobar',/.test(inspect(err)));
1249+
assert.match(inspect(err), /actual: \[Array],\n expected: 'foobar',/);
12501250
}
12511251
assert(threw);
12521252
}

test/parallel/test-async-wrap-pop-id-during-load.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ const ret = spawnSync(
2121
assert.strictEqual(ret.status, 0,
2222
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
2323
const stderr = ret.stderr.toString('utf8', 0, 2048);
24-
assert.ok(!/async.*hook/i.test(stderr));
24+
assert.doesNotMatch(stderr, /async.*hook/i);
2525
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);

test/parallel/test-buffer-prototype-inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ const util = require('util');
1919

2020
{
2121
const buf = Buffer.from('x'.repeat(51));
22-
assert.ok(/^<Buffer (?:78 ){50}\.\.\. 1 more byte>$/.test(util.inspect(buf)));
22+
assert.match(util.inspect(buf), /^<Buffer (?:78 ){50}\.\.\. 1 more byte>$/);
2323
}

test/parallel/test-cli-syntax-piped-bad.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ syntaxArgs.forEach(function(arg) {
2929
assert.strictEqual(c.stdout, '');
3030

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

3434
assert.strictEqual(c.status, 1);
3535
});
@@ -50,7 +50,7 @@ syntaxArgs.forEach(function(arg) {
5050
assert.strictEqual(c.stdout, '');
5151

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

5555
assert.strictEqual(c.status, 1);
5656
});

test/parallel/test-cluster-fork-windowsHide.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (!process.argv[2]) {
2323
workerOnline: common.mustCall((msg) => {
2424
}),
2525
mainWindowHandle: common.mustCall((msg) => {
26-
assert.ok(/0\s*/.test(msg.value));
26+
assert.match(msg.value, /0\s*/);
2727
}),
2828
workerExit: common.mustCall((msg) => {
2929
assert.strictEqual(msg.code, 0);

test/parallel/test-common.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const { join } = require('path');
3434
const p = fixtures.path('leakedGlobal.js');
3535
execFile(process.execPath, [p], common.mustCall((err, stdout, stderr) => {
3636
assert.notStrictEqual(err.code, 0);
37-
assert.ok(/\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/.test(stderr));
37+
assert.match(stderr, /\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/);
3838
}));
3939
}
4040

@@ -130,7 +130,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
130130
// Test `tmpdir`.
131131
{
132132
tmpdir.refresh();
133-
assert.ok(/\.tmp\.\d+/.test(tmpdir.path));
133+
assert.match(tmpdir.path, /\.tmp\.\d+/);
134134
const sentinelPath = join(tmpdir.path, 'gaga');
135135
writeFileSync(sentinelPath, 'googoo');
136136
tmpdir.refresh();

test/parallel/test-console.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,27 @@ assert.ok(strings[0].includes('foo: { bar: { baz:'));
246246
assert.ok(strings[0].includes('quux'));
247247
assert.ok(strings.shift().includes('quux: true'));
248248

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

254254
// Verify that console.time() coerces label values to strings as expected
255-
assert.ok(/^: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
256-
assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
257-
assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
258-
assert.ok(/^null: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
259-
assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
260-
assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
261-
assert.ok(/^NaN: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
262-
263-
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
264-
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) test$/.test(strings.shift().trim()));
265-
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/.test(strings.shift().trim()));
266-
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
255+
assert.match(strings.shift().trim(), /^: \d+(\.\d{1,3})?(ms|s)$/);
256+
assert.match(strings.shift().trim(),
257+
/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/);
258+
assert.match(strings.shift().trim(),
259+
/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/);
260+
assert.match(strings.shift().trim(), /^null: \d+(\.\d{1,3})?(ms|s)$/);
261+
assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/);
262+
assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/);
263+
assert.match(strings.shift().trim(), /^NaN: \d+(\.\d{1,3})?(ms|s)$/);
264+
265+
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/);
266+
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s) test$/);
267+
assert.match(strings.shift().trim(),
268+
/^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/);
269+
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/);
267270

268271
// Make sure that we checked all strings
269272
assert.strictEqual(strings.length, 0);

0 commit comments

Comments
 (0)