Skip to content

Commit 141fb82

Browse files
committed
test: ensure assertions are reached on more tests
PR-URL: #60760 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent edf90ce commit 141fb82

59 files changed

Lines changed: 354 additions & 380 deletions

File tree

Some content is hidden

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

‎test/eslint.config_partial.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export default [
205205
Array.from({length: 13},(_,i)=>String.fromCharCode(0x61+i,42)).join(',')
206206
},n*,${
207207
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
208-
Array.from({length: 7},(_,i)=>String.fromCharCode(0x61+25-i,42)).join(',')
208+
Array.from({length: 8},(_,i)=>String.fromCharCode(0x61+25-i,42)).join(',')
209209
}}.{js,mjs,cjs}`,
210210
],
211211
rules: {

‎test/parallel/test-socket-writes-before-passed-to-tls-socket.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const net = require('net');
77

88
constHEAD=Buffer.alloc(1024*1024,0);
99

10-
constserver=net.createServer((serverSock)=>{
10+
constserver=net.createServer(common.mustCallAtLeast((serverSock)=>{
1111
letrecvLen=0;
1212
constrecv=[];
1313
serverSock.on('data',common.mustCallAtLeast((chunk)=>{
@@ -21,7 +21,7 @@ const server = net.createServer((serverSock) => {
2121
process.exit(0);
2222
}
2323
},1));
24-
})
24+
}))
2525
.listen(client);
2626

2727
functionclient(){

‎test/parallel/test-socketaddress.js‎

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
'use strict';
33

44
constcommon=require('../common');
5-
const{
6-
ok,
7-
strictEqual,
8-
throws,
9-
}=require('assert');
5+
constassert=require('assert');
106
const{
117
SocketAddress,
128
}=require('net');
@@ -26,19 +22,19 @@ describe('net.SocketAddress...', () => {
2622

2723
it('is cloneable',()=>{
2824
constsa=newSocketAddress();
29-
strictEqual(sa.address,'127.0.0.1');
30-
strictEqual(sa.port,0);
31-
strictEqual(sa.family,'ipv4');
32-
strictEqual(sa.flowlabel,0);
25+
assert.strictEqual(sa.address,'127.0.0.1');
26+
assert.strictEqual(sa.port,0);
27+
assert.strictEqual(sa.family,'ipv4');
28+
assert.strictEqual(sa.flowlabel,0);
3329

3430
constmc=newMessageChannel();
3531
mc.port1.onmessage=common.mustCall(({ data })=>{
36-
ok(SocketAddress.isSocketAddress(data));
32+
assert.ok(SocketAddress.isSocketAddress(data));
3733

38-
strictEqual(data.address,'127.0.0.1');
39-
strictEqual(data.port,0);
40-
strictEqual(data.family,'ipv4');
41-
strictEqual(data.flowlabel,0);
34+
assert.strictEqual(data.address,'127.0.0.1');
35+
assert.strictEqual(data.port,0);
36+
assert.strictEqual(data.family,'ipv4');
37+
assert.strictEqual(data.flowlabel,0);
4238

4339
mc.port1.close();
4440
});
@@ -47,80 +43,80 @@ describe('net.SocketAddress...', () => {
4743

4844
it('has reasonable defaults',()=>{
4945
constsa=newSocketAddress({});
50-
strictEqual(sa.address,'127.0.0.1');
51-
strictEqual(sa.port,0);
52-
strictEqual(sa.family,'ipv4');
53-
strictEqual(sa.flowlabel,0);
46+
assert.strictEqual(sa.address,'127.0.0.1');
47+
assert.strictEqual(sa.port,0);
48+
assert.strictEqual(sa.family,'ipv4');
49+
assert.strictEqual(sa.flowlabel,0);
5450
});
5551

5652
it('interprets simple ipv4 correctly',()=>{
5753
constsa=newSocketAddress({
5854
address: '123.123.123.123',
5955
});
60-
strictEqual(sa.address,'123.123.123.123');
61-
strictEqual(sa.port,0);
62-
strictEqual(sa.family,'ipv4');
63-
strictEqual(sa.flowlabel,0);
56+
assert.strictEqual(sa.address,'123.123.123.123');
57+
assert.strictEqual(sa.port,0);
58+
assert.strictEqual(sa.family,'ipv4');
59+
assert.strictEqual(sa.flowlabel,0);
6460
});
6561

6662
it('sets the port correctly',()=>{
6763
constsa=newSocketAddress({
6864
address: '123.123.123.123',
6965
port: 80
7066
});
71-
strictEqual(sa.address,'123.123.123.123');
72-
strictEqual(sa.port,80);
73-
strictEqual(sa.family,'ipv4');
74-
strictEqual(sa.flowlabel,0);
67+
assert.strictEqual(sa.address,'123.123.123.123');
68+
assert.strictEqual(sa.port,80);
69+
assert.strictEqual(sa.family,'ipv4');
70+
assert.strictEqual(sa.flowlabel,0);
7571
});
7672

7773
it('interprets simple ipv6 correctly',()=>{
7874
constsa=newSocketAddress({
7975
family: 'ipv6'
8076
});
81-
strictEqual(sa.address,'::');
82-
strictEqual(sa.port,0);
83-
strictEqual(sa.family,'ipv6');
84-
strictEqual(sa.flowlabel,0);
77+
assert.strictEqual(sa.address,'::');
78+
assert.strictEqual(sa.port,0);
79+
assert.strictEqual(sa.family,'ipv6');
80+
assert.strictEqual(sa.flowlabel,0);
8581
});
8682

8783
it('uses the flowlabel correctly',()=>{
8884
constsa=newSocketAddress({
8985
family: 'ipv6',
9086
flowlabel: 1,
9187
});
92-
strictEqual(sa.address,'::');
93-
strictEqual(sa.port,0);
94-
strictEqual(sa.family,'ipv6');
95-
strictEqual(sa.flowlabel,1);
88+
assert.strictEqual(sa.address,'::');
89+
assert.strictEqual(sa.port,0);
90+
assert.strictEqual(sa.family,'ipv6');
91+
assert.strictEqual(sa.flowlabel,1);
9692
});
9793

9894
it('validates input correctly',()=>{
9995
[1,false,'hello'].forEach((i)=>{
100-
throws(()=>newSocketAddress(i),{
96+
assert.throws(()=>newSocketAddress(i),{
10197
code: 'ERR_INVALID_ARG_TYPE'
10298
});
10399
});
104100

105101
[1,false,{},[],'test'].forEach((family)=>{
106-
throws(()=>newSocketAddress({ family }),{
102+
assert.throws(()=>newSocketAddress({ family }),{
107103
code: 'ERR_INVALID_ARG_VALUE'
108104
});
109105
});
110106

111107
[1,false,{},[]].forEach((address)=>{
112-
throws(()=>newSocketAddress({ address }),{
108+
assert.throws(()=>newSocketAddress({ address }),{
113109
code: 'ERR_INVALID_ARG_TYPE'
114110
});
115111
});
116112

117113
[-1,false,{},[]].forEach((port)=>{
118-
throws(()=>newSocketAddress({ port }),{
114+
assert.throws(()=>newSocketAddress({ port }),{
119115
code: 'ERR_SOCKET_BAD_PORT'
120116
});
121117
});
122118

123-
throws(()=>newSocketAddress({flowlabel: -1}),{
119+
assert.throws(()=>newSocketAddress({flowlabel: -1}),{
124120
code: 'ERR_OUT_OF_RANGE'
125121
});
126122
});
@@ -135,11 +131,11 @@ describe('net.SocketAddress...', () => {
135131
constflowlabel=0;
136132
consthandle=new_SocketAddress(address,port,AF_INET,flowlabel);
137133
constaddr=newInternalSocketAddress(handle);
138-
ok(addrinstanceofSocketAddress);
139-
strictEqual(addr.address,address);
140-
strictEqual(addr.port,port);
141-
strictEqual(addr.family,'ipv4');
142-
strictEqual(addr.flowlabel,flowlabel);
134+
assert.ok(addrinstanceofSocketAddress);
135+
assert.strictEqual(addr.address,address);
136+
assert.strictEqual(addr.port,port);
137+
assert.strictEqual(addr.family,'ipv4');
138+
assert.strictEqual(addr.flowlabel,flowlabel);
143139
});
144140

145141
it('SocketAddress.parse() works as expected',()=>{
@@ -156,9 +152,9 @@ describe('net.SocketAddress...', () => {
156152

157153
good.forEach((i)=>{
158154
constaddr=SocketAddress.parse(i.input);
159-
strictEqual(addr.address,i.address);
160-
strictEqual(addr.port,i.port);
161-
strictEqual(addr.family,i.family);
155+
assert.strictEqual(addr.address,i.address);
156+
assert.strictEqual(addr.port,i.port);
157+
assert.strictEqual(addr.family,i.family);
162158
});
163159

164160
constbad=[
@@ -169,7 +165,7 @@ describe('net.SocketAddress...', () => {
169165
];
170166

171167
bad.forEach((i)=>{
172-
strictEqual(SocketAddress.parse(i),undefined);
168+
assert.strictEqual(SocketAddress.parse(i),undefined);
173169
});
174170
});
175171

‎test/parallel/test-spawn-cmd-named-pipe.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ if (!process.argv[2]) {
1616
conststdinPipeName=`\\\\.\\pipe\\${pipeNamePrefix}.stdin`;
1717
conststdoutPipeName=`\\\\.\\pipe\\${pipeNamePrefix}.stdout`;
1818

19-
conststdinPipeServer=net.createServer(function(c){
19+
conststdinPipeServer=net.createServer(common.mustCall((c)=>{
2020
c.on('end',common.mustCall());
2121
c.end('hello');
22-
});
22+
}));
2323
stdinPipeServer.listen(stdinPipeName);
2424

2525
constoutput=[];
2626

27-
conststdoutPipeServer=net.createServer(function(c){
27+
conststdoutPipeServer=net.createServer(common.mustCallAtLeast((c)=>{
2828
c.on('data',function(x){
2929
output.push(x);
3030
});
3131
c.on('end',common.mustCall(function(){
3232
assert.strictEqual(output.join(''),'hello');
3333
}));
34-
});
34+
}));
3535
stdoutPipeServer.listen(stdoutPipeName);
3636

3737
constargs=

‎test/parallel/test-sqlite-custom-functions.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const{ skipIfSQLiteMissing }=require('../common');
2+
const{ skipIfSQLiteMissing, mustCall}=require('../common');
33
skipIfSQLiteMissing();
44
constassert=require('node:assert');
55
const{ DatabaseSync }=require('node:sqlite');
@@ -376,14 +376,14 @@ suite('DatabaseSync.prototype.function()', () => {
376376

377377
test('supported argument types',()=>{
378378
constdb=newDatabaseSync(':memory:');
379-
db.function('arguments',(i,f,s,n,b)=>{
379+
db.function('arguments',mustCall((i,f,s,n,b)=>{
380380
assert.strictEqual(i,5);
381381
assert.strictEqual(f,3.14);
382382
assert.strictEqual(s,'foo');
383383
assert.strictEqual(n,null);
384384
assert.deepStrictEqual(b,newUint8Array([254]));
385385
return42;
386-
});
386+
}));
387387
conststmt=db.prepare(
388388
'SELECT arguments(5, 3.14, \'foo\', null, x\'fe\') as result'
389389
);

‎test/parallel/test-stdin-pipe-resume.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
// This tests that piping stdin will cause it to resume() as well.
3-
require('../common');
3+
constcommon=require('../common');
44
constassert=require('assert');
55

66
if(process.argv[2]==='child'){
@@ -12,11 +12,11 @@ if (process.argv[2] === 'child') {
1212
child.stdout.on('data',function(c){
1313
buffers.push(c);
1414
});
15-
child.stdout.on('close',function(){
15+
child.stdout.on('close',common.mustCall(()=>{
1616
constb=Buffer.concat(buffers).toString();
1717
assert.strictEqual(b,'Hello, world\n');
1818
console.log('ok');
19-
});
19+
}));
2020
child.stdin.write('Hel');
2121
child.stdin.write('lo,');
2222
child.stdin.write(' wo');

‎test/parallel/test-stdio-pipe-stderr.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
constcommon=require('../common');
33
consttmpdir=require('../common/tmpdir');
44
constassert=require('assert');
55
constfs=require('fs');
@@ -19,7 +19,7 @@ const stream = fs.createWriteStream(stderrOutputPath);
1919
// non-built-in module.
2020
fs.writeFileSync(fakeModulePath,'','utf8');
2121

22-
stream.on('open',()=>{
22+
stream.on('open',common.mustCall(()=>{
2323
spawnSync(process.execPath,{
2424
input: `require(${JSON.stringify(fakeModulePath)})`,
2525
stdio: ['pipe','pipe',stream]
@@ -33,4 +33,4 @@ stream.on('open', () => {
3333
stream.end();
3434
fs.unlinkSync(stderrOutputPath);
3535
fs.unlinkSync(fakeModulePath);
36-
});
36+
}));

‎test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
constcommon=require('../common');
33
constassert=require('assert');
44

55
if(process.argv[2]==='child')
@@ -23,10 +23,10 @@ function parent() {
2323
err+=c;
2424
});
2525

26-
child.on('close',function(code,signal){
26+
child.on('close',common.mustCall((code,signal)=>{
2727
assert.strictEqual(code,0);
2828
assert.strictEqual(err,'');
2929
assert.strictEqual(out,'foo');
3030
console.log('ok');
31-
});
31+
}));
3232
}

‎test/parallel/test-strace-openat-openssl.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (spawnSync('strace').error !== undefined) {
3232

3333
// stderr is the default for strace
3434
constrl=createInterface({input: strace.stderr});
35-
rl.on('line',(line)=>{
35+
rl.on('line',common.mustCallAtLeast((line)=>{
3636
if(!line.startsWith('open')){
3737
return;
3838
}
@@ -48,7 +48,7 @@ if (spawnSync('strace').error !== undefined) {
4848
}
4949

5050
assert(allowedOpenCalls.delete(file),`${file} is not in the list of allowed openat calls`);
51-
});
51+
}));
5252
constdebugOutput=[];
5353
strace.stderr.setEncoding('utf8');
5454
strace.stderr.on('data',(chunk)=>{

‎test/parallel/test-stream-big-push.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ assert.strictEqual(chunk, str);
6161
chunk=r.read();
6262
assert.strictEqual(chunk,null);
6363

64-
r.once('readable',()=>{
64+
r.once('readable',common.mustCall(()=>{
6565
// This time, we'll get *all* the remaining data, because
6666
// it's been added synchronously, as the read WOULD take
6767
// us below the hwm, and so it triggered a _read() again,
@@ -71,4 +71,4 @@ r.once('readable', () => {
7171

7272
chunk=r.read();
7373
assert.strictEqual(chunk,null);
74-
});
74+
}));

0 commit comments

Comments
 (0)