Skip to content

Commit

Permalink
test: simplify test skipping
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
vsemozhetbyt authored and MylesBorins committed Sep 5, 2017
1 parent 4d3b76d commit 1633f8b
Show file tree
Hide file tree
Showing 278 changed files with 775 additions and 1,408 deletions.
8 changes: 3 additions & 5 deletions test/abort/test-abort-backtrace.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';
const common = require('../common');
if (common.isWindows)
common.skip('Backtraces unimplemented on Windows.');

const assert = require('assert');
const cp = require('child_process');

if (common.isWindows) {
common.skip('Backtraces unimplemented on Windows.');
return;
}

if (process.argv[2] === 'child') {
process.abort();
} else {
Expand Down
8 changes: 3 additions & 5 deletions test/addons/load-long-path/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';
const common = require('../../common');
if (common.isWOW64)
common.skip('doesn\'t work on WOW64');

const fs = require('fs');
const path = require('path');
const assert = require('assert');

if (common.isWOW64) {
common.skip('doesn\'t work on WOW64');
return;
}

common.refreshTmpDir();

// make a path that is more than 260 chars long.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
'use strict';

const common = require('../../common');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
common.skip(skipMessage);
return;
}

let buf;
try {
buf = Buffer.allocUnsafe(kStringMaxLength);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
return;
}

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

const maxString = buf.toString('latin1');
assert.strictEqual(maxString.length, kStringMaxLength);
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
if (!common.enoughTestMem)
common.skip(skipMessage);
return;
}

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

assert.throws(function() {
buf.toString('ascii');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
if (!common.enoughTestMem)
common.skip(skipMessage);
return;
}

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

assert.throws(function() {
buf.toString('base64');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
if (!common.enoughTestMem)
common.skip(skipMessage);
return;
}

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

assert.throws(function() {
buf.toString('latin1');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
if (!common.enoughTestMem)
common.skip(skipMessage);
return;
}

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

assert.throws(function() {
buf.toString('hex');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
if (!common.enoughTestMem)
common.skip(skipMessage);
return;
}

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

assert.throws(function() {
buf.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
if (!common.enoughTestMem)
common.skip(skipMessage);
return;
}

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

const maxString = buf.toString('utf16le');
assert.strictEqual(maxString.length, (kStringMaxLength + 2) / 2);
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
if (!common.enoughTestMem)
common.skip(skipMessage);
return;
}

const binding = require(`./build/${common.buildType}/binding`);
const assert = require('assert');

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

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
return;
}

assert.throws(function() {
buf.toString('utf16le');
Expand Down
1 change: 0 additions & 1 deletion test/addons/symlinked-module/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ try {
} catch (err) {
if (err.code !== 'EPERM') throw err;
common.skip('module identity test (no privs for symlinks)');
return;
}

const sub = require('./submodule');
Expand Down
7 changes: 6 additions & 1 deletion test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ Path to the test sock.

Port tests are running on.

### printSkipMessage(msg)
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)

Logs '1..0 # Skipped: ' + `msg`

### refreshTmpDir
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)

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

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

### spawnPwd(options)
* `options` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
Expand Down
7 changes: 6 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,15 @@ exports.mustNotCall = function(msg) {
};
};

exports.skip = function(msg) {
exports.printSkipMessage = function(msg) {
console.log(`1..0 # Skipped: ${msg}`);
};

exports.skip = function(msg) {
exports.printSkipMessage(msg);
process.exit(0);
};

// A stream to push an array into a REPL
function ArrayStream() {
this.run = function(data) {
Expand Down
9 changes: 4 additions & 5 deletions test/doctool/test-doctool-html.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');

// The doctool currently uses js-yaml from the tool/eslint/ tree.
try {
require('../../tools/eslint/node_modules/js-yaml');
} catch (e) {
return common.skip('missing js-yaml (eslint not present)');
common.skip('missing js-yaml (eslint not present)');
}

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const processIncludes = require('../../tools/doc/preprocess.js');
const html = require('../../tools/doc/html.js');

Expand Down
Loading

0 comments on commit 1633f8b

Please sign in to comment.