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

PR-URL: #14021
Fixes: #14016
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
vsemozhetbyt authored and addaleax committed Jul 18, 2017

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
1 parent 0cc12fc commit 32a8f36
Showing 333 changed files with 896 additions and 1,633 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 {
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.
5 changes: 2 additions & 3 deletions test/addons/openssl-binding/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const common = require('../../common');
if (!common.hasCrypto) {
if (!common.hasCrypto)
common.skip('missing crypto');
process.exit(0);
}

const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
const bytes = new Uint8Array(1024);
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
@@ -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');
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
@@ -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');
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
@@ -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');
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
@@ -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');
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
@@ -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();
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
@@ -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
@@ -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');
1 change: 0 additions & 1 deletion test/addons/symlinked-module/test.js
Original file line number Diff line number Diff line change
@@ -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');
10 changes: 4 additions & 6 deletions test/async-hooks/test-connection.ssl.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const initHooks = require('./init-hooks');
const tick = require('./tick');
const common = require('../common');
const assert = require('assert');
const { checkInvocations } = require('./hook-checks');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

const tls = require('tls');
const Connection = process.binding('crypto').Connection;
const hooks = initHooks();
5 changes: 2 additions & 3 deletions test/async-hooks/test-crypto-pbkdf2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto) {
if (!common.hasCrypto)
common.skip('missing crypto');
return;
}

const assert = require('assert');
const tick = require('./tick');
const initHooks = require('./init-hooks');
5 changes: 2 additions & 3 deletions test/async-hooks/test-crypto-randomBytes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto) {
if (!common.hasCrypto)
common.skip('missing crypto');
return;
}

const assert = require('assert');
const tick = require('./tick');
const initHooks = require('./init-hooks');
Loading

0 comments on commit 32a8f36

Please sign in to comment.