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 <refack@gmail.com>
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

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

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

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

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

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

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

Lines changed: 5 additions & 10 deletions
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();
Lines changed: 5 additions & 10 deletions
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

Lines changed: 5 additions & 10 deletions
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');

0 commit comments

Comments
 (0)