diff --git a/test/common.js b/test/common.js index aacea9ae768fc7..4aa48de48f4b6f 100644 --- a/test/common.js +++ b/test/common.js @@ -26,6 +26,8 @@ exports.isLinuxPPCBE = (process.platform === 'linux') && (os.endianness() === 'BE'); exports.isSunOS = process.platform === 'sunos'; exports.isFreeBSD = process.platform === 'freebsd'; +exports.isLinux = process.platform === 'linux'; +exports.isOSX = process.platform === 'darwin'; exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */ exports.rootDir = exports.isWindows ? 'c:\\' : '/'; @@ -61,7 +63,7 @@ function rmdirSync(p, originalEr) { if (e.code === 'ENOTDIR') throw originalEr; if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { - const enc = process.platform === 'linux' ? 'buffer' : 'utf8'; + const enc = exports.isLinux ? 'buffer' : 'utf8'; fs.readdirSync(p, enc).forEach((f) => { if (f instanceof Buffer) { const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); @@ -91,7 +93,7 @@ var inFreeBSDJail = null; var localhostIPv4 = null; exports.localIPv6Hosts = ['localhost']; -if (process.platform === 'linux') { +if (exports.isLinux) { exports.localIPv6Hosts = [ // Debian/Ubuntu 'ip6-localhost', @@ -110,7 +112,7 @@ Object.defineProperty(exports, 'inFreeBSDJail', { get: function() { if (inFreeBSDJail !== null) return inFreeBSDJail; - if (process.platform === 'freebsd' && + if (exports.isFreeBSD && child_process.execSync('sysctl -n security.jail.jailed').toString() === '1\n') { inFreeBSDJail = true; @@ -469,7 +471,7 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) { // On Windows, v8's base::OS::Abort triggers an access violation, // which corresponds to exit code 3221225477 (0xC0000005) - if (process.platform === 'win32') + if (exports.isWindows) expectedExitCodes = [3221225477]; // When using --abort-on-uncaught-exception, V8 will use diff --git a/test/internet/test-dns-ipv6.js b/test/internet/test-dns-ipv6.js index a9e46c8478d52b..f14b45df07ebf2 100644 --- a/test/internet/test-dns-ipv6.js +++ b/test/internet/test-dns-ipv6.js @@ -123,7 +123,7 @@ TEST(function test_lookup_ipv6_hint(done) { }, function(err, ip, family) { if (err) { // FreeBSD does not support V4MAPPED - if (process.platform === 'freebsd') { + if (common.isFreeBSD) { assert(err instanceof Error); assert.strictEqual(err.code, 'EAI_BADFLAGS'); assert.strictEqual(err.hostname, 'www.google.com'); diff --git a/test/parallel/test-cwd-enoent-preload.js b/test/parallel/test-cwd-enoent-preload.js index b2f7ae0a4aed08..8418e1177e6c89 100644 --- a/test/parallel/test-cwd-enoent-preload.js +++ b/test/parallel/test-cwd-enoent-preload.js @@ -5,7 +5,7 @@ const fs = require('fs'); const spawn = require('child_process').spawn; // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. -if (process.platform === 'sunos' || common.isWindows || common.isAix) { +if (common.isSunOS || common.isWindows || common.isAix) { common.skip('cannot rmdir current working directory'); return; } diff --git a/test/parallel/test-cwd-enoent-repl.js b/test/parallel/test-cwd-enoent-repl.js index 3c8b543cf139d6..2782ec4394ea06 100644 --- a/test/parallel/test-cwd-enoent-repl.js +++ b/test/parallel/test-cwd-enoent-repl.js @@ -5,7 +5,7 @@ var fs = require('fs'); var spawn = require('child_process').spawn; // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. -if (process.platform === 'sunos' || common.isWindows || common.isAix) { +if (common.isSunOS || common.isWindows || common.isAix) { common.skip('cannot rmdir current working directory'); return; } diff --git a/test/parallel/test-cwd-enoent.js b/test/parallel/test-cwd-enoent.js index 9ff9f86405a333..f5c04fe068e945 100644 --- a/test/parallel/test-cwd-enoent.js +++ b/test/parallel/test-cwd-enoent.js @@ -5,7 +5,7 @@ var fs = require('fs'); var spawn = require('child_process').spawn; // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. -if (process.platform === 'sunos' || common.isWindows || common.isAix) { +if (common.isSunOS || common.isWindows || common.isAix) { common.skip('cannot rmdir current working directory'); return; } diff --git a/test/parallel/test-dgram-empty-packet.js b/test/parallel/test-dgram-empty-packet.js index cdda183e2afcaa..1c7e7205d1edf2 100644 --- a/test/parallel/test-dgram-empty-packet.js +++ b/test/parallel/test-dgram-empty-packet.js @@ -6,7 +6,7 @@ var callbacks = 0; var client; var timer; -if (process.platform === 'darwin') { +if (common.isOSX) { common.skip('because of 17894467 Apple bug'); return; } diff --git a/test/parallel/test-dgram-send-empty-array.js b/test/parallel/test-dgram-send-empty-array.js index 959fbed158a70d..c5050a7d548265 100644 --- a/test/parallel/test-dgram-send-empty-array.js +++ b/test/parallel/test-dgram-send-empty-array.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); const dgram = require('dgram'); -if (process.platform === 'darwin') { +if (common.isOSX) { common.skip('because of 17894467 Apple bug'); return; } diff --git a/test/parallel/test-dgram-send-empty-buffer.js b/test/parallel/test-dgram-send-empty-buffer.js index d6d31f41665f0b..ac541a9c243947 100644 --- a/test/parallel/test-dgram-send-empty-buffer.js +++ b/test/parallel/test-dgram-send-empty-buffer.js @@ -2,7 +2,7 @@ const common = require('../common'); const dgram = require('dgram'); -if (process.platform === 'darwin') { +if (common.isOSX) { common.skip('because of 17894467 Apple bug'); return; } diff --git a/test/parallel/test-domain-abort-on-uncaught.js b/test/parallel/test-domain-abort-on-uncaught.js index 4f290d22e75355..2a5eb804bc34ec 100644 --- a/test/parallel/test-domain-abort-on-uncaught.js +++ b/test/parallel/test-domain-abort-on-uncaught.js @@ -233,7 +233,7 @@ if (process.argv[2] === 'child') { tests.forEach(function(test, testIndex) { var testCmd = ''; - if (process.platform !== 'win32') { + if (!common.isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines testCmd += 'ulimit -c 0 && '; diff --git a/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js b/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js index 329772e7444238..76ca3faad702b6 100644 --- a/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js +++ b/test/parallel/test-domain-no-error-handler-abort-on-uncaught.js @@ -144,7 +144,7 @@ if (process.argv[2] === 'child') { tests.forEach(function(test, testIndex) { var testCmd = ''; - if (process.platform !== 'win32') { + if (!common.isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines testCmd += 'ulimit -c 0 && '; diff --git a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js index ae86ef2cdf20d3..b490a30b52d39f 100644 --- a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js +++ b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js @@ -82,7 +82,7 @@ function runTestWithAbortOnUncaughtException() { function createTestCmdLine(options) { var testCmd = ''; - if (process.platform !== 'win32') { + if (!common.isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines testCmd += 'ulimit -c 0 && '; diff --git a/test/parallel/test-domain-with-abort-on-uncaught-exception.js b/test/parallel/test-domain-with-abort-on-uncaught-exception.js index 423c77136fa5f6..455acc7804b230 100644 --- a/test/parallel/test-domain-with-abort-on-uncaught-exception.js +++ b/test/parallel/test-domain-with-abort-on-uncaught-exception.js @@ -93,7 +93,7 @@ if (process.argv[2] === 'child') { throwInDomainErrHandlerOpt = 'throwInDomainErrHandler'; var cmdToExec = ''; - if (process.platform !== 'win32') { + if (!common.isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines cmdToExec += 'ulimit -c 0 && '; diff --git a/test/parallel/test-fs-read-file-sync-hostname.js b/test/parallel/test-fs-read-file-sync-hostname.js index de105737969865..ca300819e704c6 100644 --- a/test/parallel/test-fs-read-file-sync-hostname.js +++ b/test/parallel/test-fs-read-file-sync-hostname.js @@ -1,10 +1,14 @@ 'use strict'; -require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); -// test reading from hostname -if (process.platform === 'linux2') { - var hostname = fs.readFileSync('/proc/sys/kernel/hostname'); - assert.ok(hostname.length > 0); +if (!common.isLinux) { + common.skip('Test is linux specific.'); + return; } + +// Test to make sure reading a file under the /proc directory works. See: +// https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0 +const hostname = fs.readFileSync('/proc/sys/kernel/hostname'); +assert.ok(hostname.length > 0); diff --git a/test/parallel/test-fs-readdir-ucs2.js b/test/parallel/test-fs-readdir-ucs2.js index 46c99954351429..916758fe943f86 100644 --- a/test/parallel/test-fs-readdir-ucs2.js +++ b/test/parallel/test-fs-readdir-ucs2.js @@ -5,7 +5,7 @@ const path = require('path'); const fs = require('fs'); const assert = require('assert'); -if (process.platform !== 'linux') { +if (!common.isLinux) { common.skip('Test is linux specific.'); return; } diff --git a/test/parallel/test-fs-watch-recursive.js b/test/parallel/test-fs-watch-recursive.js index 7853baaa02b797..23a92129a75f01 100644 --- a/test/parallel/test-fs-watch-recursive.js +++ b/test/parallel/test-fs-watch-recursive.js @@ -2,7 +2,7 @@ const common = require('../common'); -if (!(process.platform === 'darwin' || common.isWindows)) { +if (!(common.isOSX || common.isWindows)) { common.skip('recursive option is darwin/windows specific'); return; } diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index 2b01b78d2bff38..8f4db817071b53 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -71,7 +71,7 @@ var arch = os.arch(); console.log('arch = ', arch); assert.ok(arch.length > 0); -if (process.platform != 'sunos') { +if (!common.isSunOS) { // not implemeneted yet assert.ok(os.loadavg().length > 0); assert.ok(os.freemem() > 0); diff --git a/test/parallel/test-process-constants-noatime.js b/test/parallel/test-process-constants-noatime.js index bf4ed4d395bbcf..d0c027f0b9353d 100644 --- a/test/parallel/test-process-constants-noatime.js +++ b/test/parallel/test-process-constants-noatime.js @@ -1,10 +1,10 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const constants = process.binding('constants'); -if (process.platform === 'linux') { +if (common.isLinux) { assert('O_NOATIME' in constants.fs); assert.strictEqual(constants.fs.O_NOATIME, 0x40000); } else { diff --git a/test/parallel/test-process-getgroups.js b/test/parallel/test-process-getgroups.js index 6d07692a764e52..7910eb3e292fc3 100644 --- a/test/parallel/test-process-getgroups.js +++ b/test/parallel/test-process-getgroups.js @@ -3,7 +3,7 @@ const common = require('../common'); var assert = require('assert'); var exec = require('child_process').exec; -if (process.platform === 'darwin') { +if (common.isOSX) { common.skip('Output of `id -G` is unreliable on Darwin.'); return; } diff --git a/test/parallel/test-repl-sigint-nested-eval.js b/test/parallel/test-repl-sigint-nested-eval.js index 288c4bceebcd61..1bb09ba3963f3e 100644 --- a/test/parallel/test-repl-sigint-nested-eval.js +++ b/test/parallel/test-repl-sigint-nested-eval.js @@ -4,7 +4,7 @@ const assert = require('assert'); const spawn = require('child_process').spawn; -if (process.platform === 'win32') { +if (common.isWindows) { // No way to send CTRL_C_EVENT to processes from JS right now. common.skip('platform not supported'); return; diff --git a/test/parallel/test-repl-sigint.js b/test/parallel/test-repl-sigint.js index 6b342ce8612d28..5ee974aaea340e 100644 --- a/test/parallel/test-repl-sigint.js +++ b/test/parallel/test-repl-sigint.js @@ -4,7 +4,7 @@ const assert = require('assert'); const spawn = require('child_process').spawn; -if (process.platform === 'win32') { +if (common.isWindows) { // No way to send CTRL_C_EVENT to processes from JS right now. common.skip('platform not supported'); return; diff --git a/test/parallel/test-setproctitle.js b/test/parallel/test-setproctitle.js index 943cd60769c29a..4d096b1941865f 100644 --- a/test/parallel/test-setproctitle.js +++ b/test/parallel/test-setproctitle.js @@ -1,9 +1,10 @@ 'use strict'; // Original test written by Jakub Lekstan +const common = require('../common'); require('../common'); // FIXME add sunos support -if ('linux freebsd darwin'.indexOf(process.platform) === -1) { +if (!(common.isFreeBSD || common.isOSX || common.isLinux)) { console.log(`1..0 # Skipped: Unsupported platform [${process.platform}]`); return; } @@ -26,7 +27,7 @@ exec('ps -p ' + process.pid + ' -o args=', function(error, stdout, stderr) { assert.equal(stderr, ''); // freebsd always add ' (procname)' to the process title - if (process.platform === 'freebsd') + if (common.isFreeBSD) title += ` (${path.basename(process.execPath)})`; // omitting trailing whitespace and \n diff --git a/test/parallel/test-util-sigint-watchdog.js b/test/parallel/test-util-sigint-watchdog.js index 2f95286a5e72e0..f9bb3ecd93d39b 100644 --- a/test/parallel/test-util-sigint-watchdog.js +++ b/test/parallel/test-util-sigint-watchdog.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const binding = process.binding('util'); -if (process.platform === 'win32') { +if (common.isWindows) { // No way to send CTRL_C_EVENT to processes from JS right now. common.skip('platform not supported'); return; diff --git a/test/parallel/test-vm-sigint-existing-handler.js b/test/parallel/test-vm-sigint-existing-handler.js index e86bbeec0b5e9b..0f86b53dd282be 100644 --- a/test/parallel/test-vm-sigint-existing-handler.js +++ b/test/parallel/test-vm-sigint-existing-handler.js @@ -5,7 +5,7 @@ const vm = require('vm'); const spawn = require('child_process').spawn; -if (process.platform === 'win32') { +if (common.isWindows) { // No way to send CTRL_C_EVENT to processes from JS right now. common.skip('platform not supported'); return; diff --git a/test/parallel/test-vm-sigint.js b/test/parallel/test-vm-sigint.js index 11497733ce7eb1..2488b0d1c028f6 100644 --- a/test/parallel/test-vm-sigint.js +++ b/test/parallel/test-vm-sigint.js @@ -5,7 +5,7 @@ const vm = require('vm'); const spawn = require('child_process').spawn; -if (process.platform === 'win32') { +if (common.isWindows) { // No way to send CTRL_C_EVENT to processes from JS right now. common.skip('platform not supported'); return; diff --git a/test/pummel/test-net-pingpong.js b/test/pummel/test-net-pingpong.js index a7ede0b0565ac9..85dce02b6cf635 100644 --- a/test/pummel/test-net-pingpong.js +++ b/test/pummel/test-net-pingpong.js @@ -94,9 +94,8 @@ pingPongTest(common.PORT, 'localhost'); pingPongTest(common.PORT + 1, null); // This IPv6 isn't working on Solaris -var solaris = /sunos/i.test(process.platform); -if (!solaris) pingPongTest(common.PORT + 2, '::1'); +if (!common.isSunOS) pingPongTest(common.PORT + 2, '::1'); process.on('exit', function() { - assert.equal(solaris ? 2 : 3, tests_run); + assert.equal(common.isSunOS ? 2 : 3, tests_run); }); diff --git a/test/sequential/test-fs-watch.js b/test/sequential/test-fs-watch.js index 249164c7e4e991..f254ebc17cf5ae 100644 --- a/test/sequential/test-fs-watch.js +++ b/test/sequential/test-fs-watch.js @@ -5,8 +5,8 @@ var path = require('path'); var fs = require('fs'); var expectFilePath = common.isWindows || - process.platform === 'linux' || - process.platform === 'darwin'; + common.isLinux || + common.isOSX; var watchSeenOne = 0; var watchSeenTwo = 0;