Skip to content

Commit 1633f8b

Browse files
vsemozhetbytMylesBorins
authored andcommitted
test: simplify test skipping
* Make common.skip() exit. Also add common.printSkipMessage() for partial skips. * Don't make needless things before skip Backport-PR-URL: #14838 PR-URL: #14021 Fixes: #14016 Reviewed-By: Refael Ackermann <[email protected]>
1 parent 4d3b76d commit 1633f8b

File tree

278 files changed

+775
-1408
lines changed

Some content is hidden

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

278 files changed

+775
-1408
lines changed

test/abort/test-abort-backtrace.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
'use strict';
22
const common = require('../common');
3+
if (common.isWindows)
4+
common.skip('Backtraces unimplemented on Windows.');
5+
36
const assert = require('assert');
47
const cp = require('child_process');
58

6-
if (common.isWindows) {
7-
common.skip('Backtraces unimplemented on Windows.');
8-
return;
9-
}
10-
119
if (process.argv[2] === 'child') {
1210
process.abort();
1311
} else {

test/addons/load-long-path/test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22
const common = require('../../common');
3+
if (common.isWOW64)
4+
common.skip('doesn\'t work on WOW64');
5+
36
const fs = require('fs');
47
const path = require('path');
58
const assert = require('assert');
69

7-
if (common.isWOW64) {
8-
common.skip('doesn\'t work on WOW64');
9-
return;
10-
}
11-
1210
common.refreshTmpDir();
1311

1412
// make a path that is more than 260 chars long.
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
'use strict';
22

33
const common = require('../../common');
4+
const skipMessage = 'intensive toString tests due to memory confinements';
5+
if (!common.enoughTestMem)
6+
common.skip(skipMessage);
7+
48
const binding = require(`./build/${common.buildType}/binding`);
59
const assert = require('assert');
610

711
// v8 fails silently if string length > v8::String::kMaxLength
812
// v8::String::kMaxLength defined in v8.h
913
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
1014

11-
const skipMessage = 'intensive toString tests due to memory confinements';
12-
if (!common.enoughTestMem) {
13-
common.skip(skipMessage);
14-
return;
15-
}
16-
1715
let buf;
1816
try {
1917
buf = Buffer.allocUnsafe(kStringMaxLength);
2018
} catch (e) {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
const maxString = buf.toString('latin1');
3429
assert.strictEqual(maxString.length, kStringMaxLength);

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const binding = require(`./build/${common.buildType}/binding`);
5-
const assert = require('assert');
6-
74
const skipMessage = 'intensive toString tests due to memory confinements';
8-
if (!common.enoughTestMem) {
5+
if (!common.enoughTestMem)
96
common.skip(skipMessage);
10-
return;
11-
}
7+
8+
const binding = require(`./build/${common.buildType}/binding`);
9+
const assert = require('assert');
1210

1311
// v8 fails silently if string length > v8::String::kMaxLength
1412
// v8::String::kMaxLength defined in v8.h
@@ -21,14 +19,11 @@ try {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
assert.throws(function() {
3429
buf.toString('ascii');

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const binding = require(`./build/${common.buildType}/binding`);
5-
const assert = require('assert');
6-
74
const skipMessage = 'intensive toString tests due to memory confinements';
8-
if (!common.enoughTestMem) {
5+
if (!common.enoughTestMem)
96
common.skip(skipMessage);
10-
return;
11-
}
7+
8+
const binding = require(`./build/${common.buildType}/binding`);
9+
const assert = require('assert');
1210

1311
// v8 fails silently if string length > v8::String::kMaxLength
1412
// v8::String::kMaxLength defined in v8.h
@@ -21,14 +19,11 @@ try {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
assert.throws(function() {
3429
buf.toString('base64');

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const binding = require(`./build/${common.buildType}/binding`);
5-
const assert = require('assert');
6-
74
const skipMessage = 'intensive toString tests due to memory confinements';
8-
if (!common.enoughTestMem) {
5+
if (!common.enoughTestMem)
96
common.skip(skipMessage);
10-
return;
11-
}
7+
8+
const binding = require(`./build/${common.buildType}/binding`);
9+
const assert = require('assert');
1210

1311
// v8 fails silently if string length > v8::String::kMaxLength
1412
// v8::String::kMaxLength defined in v8.h
@@ -21,14 +19,11 @@ try {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
assert.throws(function() {
3429
buf.toString('latin1');

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const binding = require(`./build/${common.buildType}/binding`);
5-
const assert = require('assert');
6-
74
const skipMessage = 'intensive toString tests due to memory confinements';
8-
if (!common.enoughTestMem) {
5+
if (!common.enoughTestMem)
96
common.skip(skipMessage);
10-
return;
11-
}
7+
8+
const binding = require(`./build/${common.buildType}/binding`);
9+
const assert = require('assert');
1210

1311
// v8 fails silently if string length > v8::String::kMaxLength
1412
// v8::String::kMaxLength defined in v8.h
@@ -21,14 +19,11 @@ try {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
assert.throws(function() {
3429
buf.toString('hex');

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const binding = require(`./build/${common.buildType}/binding`);
5-
const assert = require('assert');
6-
74
const skipMessage = 'intensive toString tests due to memory confinements';
8-
if (!common.enoughTestMem) {
5+
if (!common.enoughTestMem)
96
common.skip(skipMessage);
10-
return;
11-
}
7+
8+
const binding = require(`./build/${common.buildType}/binding`);
9+
const assert = require('assert');
1210

1311
// v8 fails silently if string length > v8::String::kMaxLength
1412
// v8::String::kMaxLength defined in v8.h
@@ -21,14 +19,11 @@ try {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
assert.throws(function() {
3429
buf.toString();
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const binding = require(`./build/${common.buildType}/binding`);
5-
const assert = require('assert');
6-
74
const skipMessage = 'intensive toString tests due to memory confinements';
8-
if (!common.enoughTestMem) {
5+
if (!common.enoughTestMem)
96
common.skip(skipMessage);
10-
return;
11-
}
7+
8+
const binding = require(`./build/${common.buildType}/binding`);
9+
const assert = require('assert');
1210

1311
// v8 fails silently if string length > v8::String::kMaxLength
1412
// v8::String::kMaxLength defined in v8.h
@@ -21,14 +19,11 @@ try {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
const maxString = buf.toString('utf16le');
3429
assert.strictEqual(maxString.length, (kStringMaxLength + 2) / 2);

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const binding = require(`./build/${common.buildType}/binding`);
5-
const assert = require('assert');
6-
74
const skipMessage = 'intensive toString tests due to memory confinements';
8-
if (!common.enoughTestMem) {
5+
if (!common.enoughTestMem)
96
common.skip(skipMessage);
10-
return;
11-
}
7+
8+
const binding = require(`./build/${common.buildType}/binding`);
9+
const assert = require('assert');
1210

1311
// v8 fails silently if string length > v8::String::kMaxLength
1412
// v8::String::kMaxLength defined in v8.h
@@ -21,14 +19,11 @@ try {
2119
// If the exception is not due to memory confinement then rethrow it.
2220
if (e.message !== 'Array buffer allocation failed') throw (e);
2321
common.skip(skipMessage);
24-
return;
2522
}
2623

2724
// Ensure we have enough memory available for future allocations to succeed.
28-
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
25+
if (!binding.ensureAllocation(2 * kStringMaxLength))
2926
common.skip(skipMessage);
30-
return;
31-
}
3227

3328
assert.throws(function() {
3429
buf.toString('utf16le');

test/addons/symlinked-module/test.js

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ try {
2222
} catch (err) {
2323
if (err.code !== 'EPERM') throw err;
2424
common.skip('module identity test (no privs for symlinks)');
25-
return;
2625
}
2726

2827
const sub = require('./submodule');

test/common/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ Path to the test sock.
251251

252252
Port tests are running on.
253253

254+
### printSkipMessage(msg)
255+
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
256+
257+
Logs '1..0 # Skipped: ' + `msg`
258+
254259
### refreshTmpDir
255260
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
256261

@@ -264,7 +269,7 @@ Path to the 'root' directory. either `/` or `c:\\` (windows)
264269
### skip(msg)
265270
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
266271

267-
Logs '1..0 # Skipped: ' + `msg`
272+
Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`.
268273

269274
### spawnPwd(options)
270275
* `options` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

test/common/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,15 @@ exports.mustNotCall = function(msg) {
493493
};
494494
};
495495

496-
exports.skip = function(msg) {
496+
exports.printSkipMessage = function(msg) {
497497
console.log(`1..0 # Skipped: ${msg}`);
498498
};
499499

500+
exports.skip = function(msg) {
501+
exports.printSkipMessage(msg);
502+
process.exit(0);
503+
};
504+
500505
// A stream to push an array into a REPL
501506
function ArrayStream() {
502507
this.run = function(data) {

test/doctool/test-doctool-html.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
'use strict';
22

33
const common = require('../common');
4-
const assert = require('assert');
5-
const fs = require('fs');
6-
const path = require('path');
7-
84
// The doctool currently uses js-yaml from the tool/eslint/ tree.
95
try {
106
require('../../tools/eslint/node_modules/js-yaml');
117
} catch (e) {
12-
return common.skip('missing js-yaml (eslint not present)');
8+
common.skip('missing js-yaml (eslint not present)');
139
}
1410

11+
const assert = require('assert');
12+
const fs = require('fs');
13+
const path = require('path');
1514
const processIncludes = require('../../tools/doc/preprocess.js');
1615
const html = require('../../tools/doc/html.js');
1716

0 commit comments

Comments
 (0)