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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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
});

0 commit comments

Comments
 (0)