Skip to content

Commit dee0e3a

Browse files
committed
test: use common platform helpers everywhere
Use the common.isWindows, common.isFreeBSD and common.isSunOS where possible. Add common.isOSX and common.isLinux. Fix `test-fs-read-file-sync-hostname` as in its current form was not being run anywhere. PR-URL: #7845 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e22ffef commit dee0e3a

26 files changed

+46
-40
lines changed

test/common.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ exports.isLinuxPPCBE = (process.platform === 'linux') &&
2626
(os.endianness() === 'BE');
2727
exports.isSunOS = process.platform === 'sunos';
2828
exports.isFreeBSD = process.platform === 'freebsd';
29+
exports.isLinux = process.platform === 'linux';
30+
exports.isOSX = process.platform === 'darwin';
2931

3032
exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */
3133
exports.rootDir = exports.isWindows ? 'c:\\' : '/';
@@ -61,7 +63,7 @@ function rmdirSync(p, originalEr) {
6163
if (e.code === 'ENOTDIR')
6264
throw originalEr;
6365
if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') {
64-
const enc = process.platform === 'linux' ? 'buffer' : 'utf8';
66+
const enc = exports.isLinux ? 'buffer' : 'utf8';
6567
fs.readdirSync(p, enc).forEach((f) => {
6668
if (f instanceof Buffer) {
6769
const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]);
@@ -91,7 +93,7 @@ var inFreeBSDJail = null;
9193
var localhostIPv4 = null;
9294

9395
exports.localIPv6Hosts = ['localhost'];
94-
if (process.platform === 'linux') {
96+
if (exports.isLinux) {
9597
exports.localIPv6Hosts = [
9698
// Debian/Ubuntu
9799
'ip6-localhost',
@@ -110,7 +112,7 @@ Object.defineProperty(exports, 'inFreeBSDJail', {
110112
get: function() {
111113
if (inFreeBSDJail !== null) return inFreeBSDJail;
112114

113-
if (process.platform === 'freebsd' &&
115+
if (exports.isFreeBSD &&
114116
child_process.execSync('sysctl -n security.jail.jailed').toString() ===
115117
'1\n') {
116118
inFreeBSDJail = true;
@@ -469,7 +471,7 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
469471

470472
// On Windows, v8's base::OS::Abort triggers an access violation,
471473
// which corresponds to exit code 3221225477 (0xC0000005)
472-
if (process.platform === 'win32')
474+
if (exports.isWindows)
473475
expectedExitCodes = [3221225477];
474476

475477
// When using --abort-on-uncaught-exception, V8 will use

test/internet/test-dns-ipv6.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ TEST(function test_lookup_ipv6_hint(done) {
123123
}, function(err, ip, family) {
124124
if (err) {
125125
// FreeBSD does not support V4MAPPED
126-
if (process.platform === 'freebsd') {
126+
if (common.isFreeBSD) {
127127
assert(err instanceof Error);
128128
assert.strictEqual(err.code, 'EAI_BADFLAGS');
129129
assert.strictEqual(err.hostname, 'www.google.com');

test/parallel/test-cwd-enoent-preload.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fs = require('fs');
55
const spawn = require('child_process').spawn;
66

77
// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
8-
if (process.platform === 'sunos' || common.isWindows || common.isAix) {
8+
if (common.isSunOS || common.isWindows || common.isAix) {
99
common.skip('cannot rmdir current working directory');
1010
return;
1111
}

test/parallel/test-cwd-enoent-repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var fs = require('fs');
55
var spawn = require('child_process').spawn;
66

77
// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
8-
if (process.platform === 'sunos' || common.isWindows || common.isAix) {
8+
if (common.isSunOS || common.isWindows || common.isAix) {
99
common.skip('cannot rmdir current working directory');
1010
return;
1111
}

test/parallel/test-cwd-enoent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var fs = require('fs');
55
var spawn = require('child_process').spawn;
66

77
// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
8-
if (process.platform === 'sunos' || common.isWindows || common.isAix) {
8+
if (common.isSunOS || common.isWindows || common.isAix) {
99
common.skip('cannot rmdir current working directory');
1010
return;
1111
}

test/parallel/test-dgram-empty-packet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var callbacks = 0;
66
var client;
77
var timer;
88

9-
if (process.platform === 'darwin') {
9+
if (common.isOSX) {
1010
common.skip('because of 17894467 Apple bug');
1111
return;
1212
}

test/parallel/test-dgram-send-empty-array.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const common = require('../common');
44
const assert = require('assert');
55
const dgram = require('dgram');
66

7-
if (process.platform === 'darwin') {
7+
if (common.isOSX) {
88
common.skip('because of 17894467 Apple bug');
99
return;
1010
}

test/parallel/test-dgram-send-empty-buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const common = require('../common');
33
const dgram = require('dgram');
44

5-
if (process.platform === 'darwin') {
5+
if (common.isOSX) {
66
common.skip('because of 17894467 Apple bug');
77
return;
88
}

test/parallel/test-domain-abort-on-uncaught.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ if (process.argv[2] === 'child') {
233233

234234
tests.forEach(function(test, testIndex) {
235235
var testCmd = '';
236-
if (process.platform !== 'win32') {
236+
if (!common.isWindows) {
237237
// Do not create core files, as it can take a lot of disk space on
238238
// continuous testing and developers' machines
239239
testCmd += 'ulimit -c 0 && ';

test/parallel/test-domain-no-error-handler-abort-on-uncaught.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if (process.argv[2] === 'child') {
144144

145145
tests.forEach(function(test, testIndex) {
146146
var testCmd = '';
147-
if (process.platform !== 'win32') {
147+
if (!common.isWindows) {
148148
// Do not create core files, as it can take a lot of disk space on
149149
// continuous testing and developers' machines
150150
testCmd += 'ulimit -c 0 && ';

test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function runTestWithAbortOnUncaughtException() {
8282
function createTestCmdLine(options) {
8383
var testCmd = '';
8484

85-
if (process.platform !== 'win32') {
85+
if (!common.isWindows) {
8686
// Do not create core files, as it can take a lot of disk space on
8787
// continuous testing and developers' machines
8888
testCmd += 'ulimit -c 0 && ';

test/parallel/test-domain-with-abort-on-uncaught-exception.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ if (process.argv[2] === 'child') {
9393
throwInDomainErrHandlerOpt = 'throwInDomainErrHandler';
9494

9595
var cmdToExec = '';
96-
if (process.platform !== 'win32') {
96+
if (!common.isWindows) {
9797
// Do not create core files, as it can take a lot of disk space on
9898
// continuous testing and developers' machines
9999
cmdToExec += 'ulimit -c 0 && ';
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
'use strict';
2-
require('../common');
3-
var assert = require('assert');
4-
var fs = require('fs');
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const fs = require('fs');
55

6-
// test reading from hostname
7-
if (process.platform === 'linux2') {
8-
var hostname = fs.readFileSync('/proc/sys/kernel/hostname');
9-
assert.ok(hostname.length > 0);
6+
if (!common.isLinux) {
7+
common.skip('Test is linux specific.');
8+
return;
109
}
10+
11+
// Test to make sure reading a file under the /proc directory works. See:
12+
// https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0
13+
const hostname = fs.readFileSync('/proc/sys/kernel/hostname');
14+
assert.ok(hostname.length > 0);

test/parallel/test-fs-readdir-ucs2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55
const fs = require('fs');
66
const assert = require('assert');
77

8-
if (process.platform !== 'linux') {
8+
if (!common.isLinux) {
99
common.skip('Test is linux specific.');
1010
return;
1111
}

test/parallel/test-fs-watch-recursive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const common = require('../common');
44

5-
if (!(process.platform === 'darwin' || common.isWindows)) {
5+
if (!(common.isOSX || common.isWindows)) {
66
common.skip('recursive option is darwin/windows specific');
77
return;
88
}

test/parallel/test-os.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var arch = os.arch();
7171
console.log('arch = ', arch);
7272
assert.ok(arch.length > 0);
7373

74-
if (process.platform != 'sunos') {
74+
if (!common.isSunOS) {
7575
// not implemeneted yet
7676
assert.ok(os.loadavg().length > 0);
7777
assert.ok(os.freemem() > 0);

test/parallel/test-process-constants-noatime.js

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

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const constants = process.binding('constants');
66

7-
if (process.platform === 'linux') {
7+
if (common.isLinux) {
88
assert('O_NOATIME' in constants.fs);
99
assert.strictEqual(constants.fs.O_NOATIME, 0x40000);
1010
} else {

test/parallel/test-process-getgroups.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../common');
33
var assert = require('assert');
44
var exec = require('child_process').exec;
55

6-
if (process.platform === 'darwin') {
6+
if (common.isOSX) {
77
common.skip('Output of `id -G` is unreliable on Darwin.');
88
return;
99
}

test/parallel/test-repl-sigint-nested-eval.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44

55
const spawn = require('child_process').spawn;
66

7-
if (process.platform === 'win32') {
7+
if (common.isWindows) {
88
// No way to send CTRL_C_EVENT to processes from JS right now.
99
common.skip('platform not supported');
1010
return;

test/parallel/test-repl-sigint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44

55
const spawn = require('child_process').spawn;
66

7-
if (process.platform === 'win32') {
7+
if (common.isWindows) {
88
// No way to send CTRL_C_EVENT to processes from JS right now.
99
common.skip('platform not supported');
1010
return;

test/parallel/test-setproctitle.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22
// Original test written by Jakub Lekstan <[email protected]>
3+
const common = require('../common');
34

45
require('../common');
56
// FIXME add sunos support
6-
if ('linux freebsd darwin'.indexOf(process.platform) === -1) {
7+
if (!(common.isFreeBSD || common.isOSX || common.isLinux)) {
78
console.log(`1..0 # Skipped: Unsupported platform [${process.platform}]`);
89
return;
910
}
@@ -26,7 +27,7 @@ exec('ps -p ' + process.pid + ' -o args=', function(error, stdout, stderr) {
2627
assert.equal(stderr, '');
2728

2829
// freebsd always add ' (procname)' to the process title
29-
if (process.platform === 'freebsd')
30+
if (common.isFreeBSD)
3031
title += ` (${path.basename(process.execPath)})`;
3132

3233
// omitting trailing whitespace and \n

test/parallel/test-util-sigint-watchdog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../common');
33
const assert = require('assert');
44
const binding = process.binding('util');
55

6-
if (process.platform === 'win32') {
6+
if (common.isWindows) {
77
// No way to send CTRL_C_EVENT to processes from JS right now.
88
common.skip('platform not supported');
99
return;

test/parallel/test-vm-sigint-existing-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const vm = require('vm');
55

66
const spawn = require('child_process').spawn;
77

8-
if (process.platform === 'win32') {
8+
if (common.isWindows) {
99
// No way to send CTRL_C_EVENT to processes from JS right now.
1010
common.skip('platform not supported');
1111
return;

test/parallel/test-vm-sigint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const vm = require('vm');
55

66
const spawn = require('child_process').spawn;
77

8-
if (process.platform === 'win32') {
8+
if (common.isWindows) {
99
// No way to send CTRL_C_EVENT to processes from JS right now.
1010
common.skip('platform not supported');
1111
return;

test/pummel/test-net-pingpong.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ pingPongTest(common.PORT, 'localhost');
9494
pingPongTest(common.PORT + 1, null);
9595

9696
// This IPv6 isn't working on Solaris
97-
var solaris = /sunos/i.test(process.platform);
98-
if (!solaris) pingPongTest(common.PORT + 2, '::1');
97+
if (!common.isSunOS) pingPongTest(common.PORT + 2, '::1');
9998

10099
process.on('exit', function() {
101-
assert.equal(solaris ? 2 : 3, tests_run);
100+
assert.equal(common.isSunOS ? 2 : 3, tests_run);
102101
});

test/sequential/test-fs-watch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var path = require('path');
55
var fs = require('fs');
66

77
var expectFilePath = common.isWindows ||
8-
process.platform === 'linux' ||
9-
process.platform === 'darwin';
8+
common.isLinux ||
9+
common.isOSX;
1010

1111
var watchSeenOne = 0;
1212
var watchSeenTwo = 0;

0 commit comments

Comments
 (0)