Skip to content

Commit

Permalink
test: use common.isWindows consistently
Browse files Browse the repository at this point in the history
In the tests, we use "process.platform === 'win32'" in some places.
This patch replaces them with the "common.isWindows" for consistency.

PR-URL: #2269
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
thefourtheye committed Jul 30, 2015
1 parent fa98b97 commit d5ab92b
Show file tree
Hide file tree
Showing 66 changed files with 114 additions and 132 deletions.
16 changes: 8 additions & 8 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Object.defineProperty(exports, 'opensslCli', {get: function() {
opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
}

if (process.platform === 'win32') opensslCli += '.exe';
if (exports.isWindows) opensslCli += '.exe';

var openssl_cmd = child_process.spawnSync(opensslCli, ['version']);
if (openssl_cmd.status !== 0 || openssl_cmd.error !== undefined) {
Expand All @@ -133,7 +133,7 @@ Object.defineProperty(exports, 'hasCrypto', {get: function() {
return process.versions.openssl ? true : false;
}});

if (process.platform === 'win32') {
if (exports.isWindows) {
exports.PIPE = '\\\\.\\pipe\\libuv-test';
} else {
exports.PIPE = exports.tmpDir + '/test.sock';
Expand All @@ -150,7 +150,7 @@ if (process.env.NODE_COMMON_PIPE) {
}
}

if (process.platform === 'win32') {
if (exports.isWindows) {
exports.faketimeCli = false;
} else {
exports.faketimeCli = path.join(__dirname, '..', 'tools', 'faketime', 'src',
Expand Down Expand Up @@ -183,7 +183,7 @@ exports.indirectInstanceOf = function(obj, cls) {


exports.ddCommand = function(filename, kilobytes) {
if (process.platform === 'win32') {
if (exports.isWindows) {
var p = path.resolve(exports.fixturesDir, 'create-file.js');
return '"' + process.argv[0] + '" "' + p + '" "' +
filename + '" ' + (kilobytes * 1024);
Expand All @@ -196,7 +196,7 @@ exports.ddCommand = function(filename, kilobytes) {
exports.spawnCat = function(options) {
var spawn = require('child_process').spawn;

if (process.platform === 'win32') {
if (exports.isWindows) {
return spawn('more', [], options);
} else {
return spawn('cat', [], options);
Expand All @@ -207,7 +207,7 @@ exports.spawnCat = function(options) {
exports.spawnSyncCat = function(options) {
var spawnSync = require('child_process').spawnSync;

if (process.platform === 'win32') {
if (exports.isWindows) {
return spawnSync('more', [], options);
} else {
return spawnSync('cat', [], options);
Expand All @@ -218,7 +218,7 @@ exports.spawnSyncCat = function(options) {
exports.spawnPwd = function(options) {
var spawn = require('child_process').spawn;

if (process.platform === 'win32') {
if (exports.isWindows) {
return spawn('cmd.exe', ['/c', 'cd'], options);
} else {
return spawn('pwd', [], options);
Expand Down Expand Up @@ -374,7 +374,7 @@ exports.checkSpawnSyncRet = function(ret) {
};

var etcServicesFileName = path.join('/etc', 'services');
if (process.platform === 'win32') {
if (exports.isWindows) {
etcServicesFileName = path.join(process.env.SystemRoot, 'System32', 'drivers',
'etc', 'services');
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-c-ares.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ assert.throws(function() {
// Windows doesn't usually have an entry for localhost 127.0.0.1 in
// C:\Windows\System32\drivers\etc\hosts
// so we disable this test on Windows.
if (process.platform != 'win32') {
if (!common.isWindows) {
dns.resolve('127.0.0.1', 'PTR', function(error, domains) {
if (error) throw error;
assert.ok(Array.isArray(domains));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function testCwd(options, forCode, forData) {
}

// Assume these exist, and 'pwd' gives us the right directory back
if (process.platform == 'win32') {
if (common.isWindows) {
testCwd({cwd: process.env.windir}, 0, process.env.windir);
testCwd({cwd: 'c:\\'}, 0, 'c:\\');
} else {
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-child-process-default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ var assert = require('assert');

var spawn = require('child_process').spawn;

var isWindows = process.platform === 'win32';

process.env.HELLO = 'WORLD';

if (isWindows) {
if (common.isWindows) {
var child = spawn('cmd.exe', ['/c', 'set'], {});
} else {
var child = spawn('/usr/bin/env', [], {});
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-child-process-double-pipe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';
var is_windows = process.platform === 'win32';

var common = require('../common');
var assert = require('assert'),
os = require('os'),
Expand All @@ -12,7 +10,7 @@ var assert = require('assert'),

var grep, sed, echo;

if (is_windows) {
if (common.isWindows) {
grep = spawn('grep', ['--binary', 'o']),
sed = spawn('sed', ['--binary', 's/o/O/']),
echo = spawn('cmd.exe',
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-child-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ var assert = require('assert');

var spawn = require('child_process').spawn;

var isWindows = process.platform === 'win32';

var env = {
'HELLO': 'WORLD'
};
env.__proto__ = {
'FOO': 'BAR'
};

if (isWindows) {
if (common.isWindows) {
var child = spawn('cmd.exe', ['/c', 'set'], {env: env});
} else {
var child = spawn('/usr/bin/env', [], {env: env});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-exec-cwd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
var assert = require('assert');
var exec = require('child_process').exec;

Expand All @@ -8,7 +8,7 @@ var error_count = 0;

var pwdcommand, dir;

if (process.platform == 'win32') {
if (common.isWindows) {
pwdcommand = 'echo %cd%';
dir = 'c:\\windows';
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-exec-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function after(err, stdout, stderr) {
}
}

if (process.platform !== 'win32') {
if (!common.isWindows) {
child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after);
} else {
child = exec('set', { env: { 'HELLO': 'WORLD' } }, after);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-exec-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function test(fun, code) {
});
}

if (process.platform === 'win32') {
if (common.isWindows) {
test(child_process.exec, 1); // exit code of cmd.exe
} else {
test(child_process.exec, 127); // exit code of /bin/sh
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-fork-dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var fork = require('child_process').fork;
var assert = require('assert');
var common = require('../common');

if (process.platform === 'win32') {
if (common.isWindows) {
console.error('Sending dgram sockets to child processes not supported');
process.exit(0);
}
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-child-process-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ var assert = require('assert');

var spawn = require('child_process').spawn;

var is_windows = process.platform === 'win32';

var exitCode;
var termSignal;
var gotStdoutEOF = false;
var gotStderrEOF = false;

var cat = spawn(is_windows ? 'cmd' : 'cat');
var cat = spawn(common.isWindows ? 'cmd' : 'cat');


cat.stdout.on('end', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawn-typeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var assert = require('assert');
var child_process = require('child_process');
var spawn = child_process.spawn;
var cmd = (process.platform === 'win32') ? 'rundll32' : 'ls';
var cmd = require('../common').isWindows ? 'rundll32' : 'ls';
var invalidArgsMsg = /Incorrect value of args option/;
var invalidOptionsMsg = /options argument must be an object/;

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawnsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ assert.deepEqual(ret_err.spawnargs, ['bar']);
var response;
var cwd;

if (process.platform === 'win32') {
if (common.isWindows) {
cwd = 'c:\\';
response = spawnSync('cmd.exe', ['/c', 'cd'], {cwd: cwd});
} else {
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-child-process-stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ var common = require('../common');
var assert = require('assert');

var spawn = require('child_process').spawn;
var is_windows = process.platform === 'win32';

var cat = spawn(is_windows ? 'more' : 'cat');
var cat = spawn(common.isWindows ? 'more' : 'cat');
cat.stdin.write('hello');
cat.stdin.write(' ');
cat.stdin.write('world');
Expand Down Expand Up @@ -51,7 +50,7 @@ cat.on('exit', function(status) {

cat.on('close', function() {
closed = true;
if (is_windows) {
if (common.isWindows) {
assert.equal('hello world\r\n', response);
} else {
assert.equal('hello world', response);
Expand All @@ -61,7 +60,7 @@ cat.on('close', function() {
process.on('exit', function() {
assert.equal(0, exitStatus);
assert(closed);
if (is_windows) {
if (common.isWindows) {
assert.equal('hello world\r\n', response);
} else {
assert.equal('hello world', response);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-bind-privileged-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert');
var cluster = require('cluster');
var net = require('net');

if (process.platform === 'win32') {
if (common.isWindows) {
console.log('1..0 # Skipped: not reliable on Windows.');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-dgram-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var common = require('../common');
var dgram = require('dgram');


if (process.platform === 'win32') {
if (common.isWindows) {
console.warn('dgram clustering is currently not supported on windows.');
process.exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-dgram-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var common = require('../common');
var dgram = require('dgram');


if (process.platform === 'win32') {
if (common.isWindows) {
console.warn('dgram clustering is currently not supported on windows.');
process.exit(0);
}
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-cluster-disconnect-unshared-udp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';
if (process.platform === 'win32') {

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

if (common.isWindows) {
console.log('1..0 # Skipped: on windows, because clustered dgram is ENOTSUP');
return;
}
Expand Down
13 changes: 7 additions & 6 deletions test/parallel/test-cluster-http-pipe.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const http = require('http');

// It is not possible to send pipe handles over the IPC pipe on Windows.
if (process.platform === 'win32') {
if (common.isWindows) {
process.exit(0);
}

var common = require('../common');
var assert = require('assert');
var cluster = require('cluster');
var http = require('http');

if (cluster.isMaster) {
common.refreshTmpDir();
var ok = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert');
var cluster = require('cluster');
var net = require('net');

if (process.platform === 'win32') {
if (common.isWindows) {
console.log('1..0 # Skipped: not reliable on Windows');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cwd-enoent-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fs = require('fs');
var spawn = require('child_process').spawn;

// Fails with EINVAL on SmartOS, EBUSY on Windows.
if (process.platform === 'sunos' || process.platform === 'win32') {
if (process.platform === 'sunos' || common.isWindows) {
console.log('1..0 # Skipped: cannot rmdir current working directory');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cwd-enoent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fs = require('fs');
var spawn = require('child_process').spawn;

// Fails with EINVAL on SmartOS, EBUSY on Windows.
if (process.platform === 'sunos' || process.platform === 'win32') {
if (process.platform === 'sunos' || common.isWindows) {
console.log('1..0 # Skipped: cannot rmdir current working directory');
return;
}
Expand Down
8 changes: 3 additions & 5 deletions test/parallel/test-dgram-exclusive-implicit-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ var dgram = require('dgram');
// supported while using cluster, though servers still cause the master to error
// with ENOTSUP.

var windows = process.platform === 'win32';

if (cluster.isMaster) {
var pass;
var messages = 0;
Expand All @@ -56,12 +54,12 @@ if (cluster.isMaster) {
messages++;
ports[rinfo.port] = true;

if (windows && messages === 2) {
if (common.isWindows && messages === 2) {
assert.equal(Object.keys(ports).length, 2);
done();
}

if (!windows && messages === 4) {
if (!common.isWindows && messages === 4) {
assert.equal(Object.keys(ports).length, 3);
done();
}
Expand All @@ -76,7 +74,7 @@ if (cluster.isMaster) {
target.on('listening', function() {
cluster.fork();
cluster.fork();
if (!windows) {
if (!common.isWindows) {
cluster.fork({BOUND: 'y'});
cluster.fork({BOUND: 'y'});
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ createFileWithPerms(readWriteFile, 0o666);
* continuous integration platform to take care of that.
*/
var hasWriteAccessForReadonlyFile = false;
if (process.platform !== 'win32' && process.getuid() === 0) {
if (!common.isWindows && process.getuid() === 0) {
hasWriteAccessForReadonlyFile = true;
try {
process.setuid('nobody');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-append-file-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var m = 0o600;
fs.appendFileSync(filename4, num, { mode: m });

// windows permissions aren't unix
if (process.platform !== 'win32') {
if (!common.isWindows) {
var st = fs.statSync(filename4);
assert.equal(st.mode & 0o700, m);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-append-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fs.appendFile(filename4, n, { mode: m }, function(e) {
common.error('appended to file4');

// windows permissions aren't unix
if (process.platform !== 'win32') {
if (!common.isWindows) {
var st = fs.statSync(filename4);
assert.equal(st.mode & 0o700, m);
}
Expand Down
Loading

0 comments on commit d5ab92b

Please sign in to comment.