Skip to content

Commit d5ab92b

Browse files
committed
test: use common.isWindows consistently
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 <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent fa98b97 commit d5ab92b

File tree

66 files changed

+114
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+114
-132
lines changed

test/common.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Object.defineProperty(exports, 'opensslCli', {get: function() {
119119
opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
120120
}
121121

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

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

136-
if (process.platform === 'win32') {
136+
if (exports.isWindows) {
137137
exports.PIPE = '\\\\.\\pipe\\libuv-test';
138138
} else {
139139
exports.PIPE = exports.tmpDir + '/test.sock';
@@ -150,7 +150,7 @@ if (process.env.NODE_COMMON_PIPE) {
150150
}
151151
}
152152

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

184184

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

199-
if (process.platform === 'win32') {
199+
if (exports.isWindows) {
200200
return spawn('more', [], options);
201201
} else {
202202
return spawn('cat', [], options);
@@ -207,7 +207,7 @@ exports.spawnCat = function(options) {
207207
exports.spawnSyncCat = function(options) {
208208
var spawnSync = require('child_process').spawnSync;
209209

210-
if (process.platform === 'win32') {
210+
if (exports.isWindows) {
211211
return spawnSync('more', [], options);
212212
} else {
213213
return spawnSync('cat', [], options);
@@ -218,7 +218,7 @@ exports.spawnSyncCat = function(options) {
218218
exports.spawnPwd = function(options) {
219219
var spawn = require('child_process').spawn;
220220

221-
if (process.platform === 'win32') {
221+
if (exports.isWindows) {
222222
return spawn('cmd.exe', ['/c', 'cd'], options);
223223
} else {
224224
return spawn('pwd', [], options);
@@ -374,7 +374,7 @@ exports.checkSpawnSyncRet = function(ret) {
374374
};
375375

376376
var etcServicesFileName = path.join('/etc', 'services');
377-
if (process.platform === 'win32') {
377+
if (exports.isWindows) {
378378
etcServicesFileName = path.join(process.env.SystemRoot, 'System32', 'drivers',
379379
'etc', 'services');
380380
}

test/parallel/test-c-ares.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ assert.throws(function() {
3030
// Windows doesn't usually have an entry for localhost 127.0.0.1 in
3131
// C:\Windows\System32\drivers\etc\hosts
3232
// so we disable this test on Windows.
33-
if (process.platform != 'win32') {
33+
if (!common.isWindows) {
3434
dns.resolve('127.0.0.1', 'PTR', function(error, domains) {
3535
if (error) throw error;
3636
assert.ok(Array.isArray(domains));

test/parallel/test-child-process-cwd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function testCwd(options, forCode, forData) {
3838
}
3939

4040
// Assume these exist, and 'pwd' gives us the right directory back
41-
if (process.platform == 'win32') {
41+
if (common.isWindows) {
4242
testCwd({cwd: process.env.windir}, 0, process.env.windir);
4343
testCwd({cwd: 'c:\\'}, 0, 'c:\\');
4444
} else {

test/parallel/test-child-process-default-options.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ var assert = require('assert');
44

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

7-
var isWindows = process.platform === 'win32';
8-
97
process.env.HELLO = 'WORLD';
108

11-
if (isWindows) {
9+
if (common.isWindows) {
1210
var child = spawn('cmd.exe', ['/c', 'set'], {});
1311
} else {
1412
var child = spawn('/usr/bin/env', [], {});

test/parallel/test-child-process-double-pipe.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
'use strict';
2-
var is_windows = process.platform === 'win32';
3-
42
var common = require('../common');
53
var assert = require('assert'),
64
os = require('os'),
@@ -12,7 +10,7 @@ var assert = require('assert'),
1210

1311
var grep, sed, echo;
1412

15-
if (is_windows) {
13+
if (common.isWindows) {
1614
grep = spawn('grep', ['--binary', 'o']),
1715
sed = spawn('sed', ['--binary', 's/o/O/']),
1816
echo = spawn('cmd.exe',

test/parallel/test-child-process-env.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ var assert = require('assert');
44

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

7-
var isWindows = process.platform === 'win32';
8-
97
var env = {
108
'HELLO': 'WORLD'
119
};
1210
env.__proto__ = {
1311
'FOO': 'BAR'
1412
};
1513

16-
if (isWindows) {
14+
if (common.isWindows) {
1715
var child = spawn('cmd.exe', ['/c', 'set'], {env: env});
1816
} else {
1917
var child = spawn('/usr/bin/env', [], {env: env});

test/parallel/test-child-process-exec-cwd.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
var assert = require('assert');
44
var exec = require('child_process').exec;
55

@@ -8,7 +8,7 @@ var error_count = 0;
88

99
var pwdcommand, dir;
1010

11-
if (process.platform == 'win32') {
11+
if (common.isWindows) {
1212
pwdcommand = 'echo %cd%';
1313
dir = 'c:\\windows';
1414
} else {

test/parallel/test-child-process-exec-env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function after(err, stdout, stderr) {
2020
}
2121
}
2222

23-
if (process.platform !== 'win32') {
23+
if (!common.isWindows) {
2424
child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after);
2525
} else {
2626
child = exec('set', { env: { 'HELLO': 'WORLD' } }, after);

test/parallel/test-child-process-exec-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function test(fun, code) {
1717
});
1818
}
1919

20-
if (process.platform === 'win32') {
20+
if (common.isWindows) {
2121
test(child_process.exec, 1); // exit code of cmd.exe
2222
} else {
2323
test(child_process.exec, 127); // exit code of /bin/sh

test/parallel/test-child-process-fork-dgram.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var fork = require('child_process').fork;
1818
var assert = require('assert');
1919
var common = require('../common');
2020

21-
if (process.platform === 'win32') {
21+
if (common.isWindows) {
2222
console.error('Sending dgram sockets to child processes not supported');
2323
process.exit(0);
2424
}

test/parallel/test-child-process-kill.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ var assert = require('assert');
44

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

7-
var is_windows = process.platform === 'win32';
8-
97
var exitCode;
108
var termSignal;
119
var gotStdoutEOF = false;
1210
var gotStderrEOF = false;
1311

14-
var cat = spawn(is_windows ? 'cmd' : 'cat');
12+
var cat = spawn(common.isWindows ? 'cmd' : 'cat');
1513

1614

1715
cat.stdout.on('end', function() {

test/parallel/test-child-process-spawn-typeerror.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var assert = require('assert');
33
var child_process = require('child_process');
44
var spawn = child_process.spawn;
5-
var cmd = (process.platform === 'win32') ? 'rundll32' : 'ls';
5+
var cmd = require('../common').isWindows ? 'rundll32' : 'ls';
66
var invalidArgsMsg = /Incorrect value of args option/;
77
var invalidOptionsMsg = /options argument must be an object/;
88

test/parallel/test-child-process-spawnsync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ assert.deepEqual(ret_err.spawnargs, ['bar']);
3838
var response;
3939
var cwd;
4040

41-
if (process.platform === 'win32') {
41+
if (common.isWindows) {
4242
cwd = 'c:\\';
4343
response = spawnSync('cmd.exe', ['/c', 'cd'], {cwd: cwd});
4444
} else {

test/parallel/test-child-process-stdin.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ var common = require('../common');
33
var assert = require('assert');
44

55
var spawn = require('child_process').spawn;
6-
var is_windows = process.platform === 'win32';
76

8-
var cat = spawn(is_windows ? 'more' : 'cat');
7+
var cat = spawn(common.isWindows ? 'more' : 'cat');
98
cat.stdin.write('hello');
109
cat.stdin.write(' ');
1110
cat.stdin.write('world');
@@ -51,7 +50,7 @@ cat.on('exit', function(status) {
5150

5251
cat.on('close', function() {
5352
closed = true;
54-
if (is_windows) {
53+
if (common.isWindows) {
5554
assert.equal('hello world\r\n', response);
5655
} else {
5756
assert.equal('hello world', response);
@@ -61,7 +60,7 @@ cat.on('close', function() {
6160
process.on('exit', function() {
6261
assert.equal(0, exitStatus);
6362
assert(closed);
64-
if (is_windows) {
63+
if (common.isWindows) {
6564
assert.equal('hello world\r\n', response);
6665
} else {
6766
assert.equal('hello world', response);

test/parallel/test-cluster-bind-privileged-port.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var assert = require('assert');
44
var cluster = require('cluster');
55
var net = require('net');
66

7-
if (process.platform === 'win32') {
7+
if (common.isWindows) {
88
console.log('1..0 # Skipped: not reliable on Windows.');
99
return;
1010
}

test/parallel/test-cluster-dgram-1.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var common = require('../common');
88
var dgram = require('dgram');
99

1010

11-
if (process.platform === 'win32') {
11+
if (common.isWindows) {
1212
console.warn('dgram clustering is currently not supported on windows.');
1313
process.exit(0);
1414
}

test/parallel/test-cluster-dgram-2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var common = require('../common');
88
var dgram = require('dgram');
99

1010

11-
if (process.platform === 'win32') {
11+
if (common.isWindows) {
1212
console.warn('dgram clustering is currently not supported on windows.');
1313
process.exit(0);
1414
}

test/parallel/test-cluster-disconnect-unshared-udp.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use strict';
2-
if (process.platform === 'win32') {
2+
3+
const common = require('../common');
4+
5+
if (common.isWindows) {
36
console.log('1..0 # Skipped: on windows, because clustered dgram is ENOTSUP');
47
return;
58
}

test/parallel/test-cluster-http-pipe.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const cluster = require('cluster');
6+
const http = require('http');
7+
28
// It is not possible to send pipe handles over the IPC pipe on Windows.
3-
if (process.platform === 'win32') {
9+
if (common.isWindows) {
410
process.exit(0);
511
}
612

7-
var common = require('../common');
8-
var assert = require('assert');
9-
var cluster = require('cluster');
10-
var http = require('http');
11-
1213
if (cluster.isMaster) {
1314
common.refreshTmpDir();
1415
var ok = false;

test/parallel/test-cluster-shared-handle-bind-privileged-port.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var assert = require('assert');
44
var cluster = require('cluster');
55
var net = require('net');
66

7-
if (process.platform === 'win32') {
7+
if (common.isWindows) {
88
console.log('1..0 # Skipped: not reliable on Windows');
99
return;
1010
}

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.
8-
if (process.platform === 'sunos' || process.platform === 'win32') {
8+
if (process.platform === 'sunos' || common.isWindows) {
99
console.log('1..0 # Skipped: 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.
8-
if (process.platform === 'sunos' || process.platform === 'win32') {
8+
if (process.platform === 'sunos' || common.isWindows) {
99
console.log('1..0 # Skipped: cannot rmdir current working directory');
1010
return;
1111
}

test/parallel/test-dgram-exclusive-implicit-bind.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ var dgram = require('dgram');
3939
// supported while using cluster, though servers still cause the master to error
4040
// with ENOTSUP.
4141

42-
var windows = process.platform === 'win32';
43-
4442
if (cluster.isMaster) {
4543
var pass;
4644
var messages = 0;
@@ -56,12 +54,12 @@ if (cluster.isMaster) {
5654
messages++;
5755
ports[rinfo.port] = true;
5856

59-
if (windows && messages === 2) {
57+
if (common.isWindows && messages === 2) {
6058
assert.equal(Object.keys(ports).length, 2);
6159
done();
6260
}
6361

64-
if (!windows && messages === 4) {
62+
if (!common.isWindows && messages === 4) {
6563
assert.equal(Object.keys(ports).length, 3);
6664
done();
6765
}
@@ -76,7 +74,7 @@ if (cluster.isMaster) {
7674
target.on('listening', function() {
7775
cluster.fork();
7876
cluster.fork();
79-
if (!windows) {
77+
if (!common.isWindows) {
8078
cluster.fork({BOUND: 'y'});
8179
cluster.fork({BOUND: 'y'});
8280
}

test/parallel/test-fs-access.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ createFileWithPerms(readWriteFile, 0o666);
4949
* continuous integration platform to take care of that.
5050
*/
5151
var hasWriteAccessForReadonlyFile = false;
52-
if (process.platform !== 'win32' && process.getuid() === 0) {
52+
if (!common.isWindows && process.getuid() === 0) {
5353
hasWriteAccessForReadonlyFile = true;
5454
try {
5555
process.setuid('nobody');

test/parallel/test-fs-append-file-sync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var m = 0o600;
6262
fs.appendFileSync(filename4, num, { mode: m });
6363

6464
// windows permissions aren't unix
65-
if (process.platform !== 'win32') {
65+
if (!common.isWindows) {
6666
var st = fs.statSync(filename4);
6767
assert.equal(st.mode & 0o700, m);
6868
}

test/parallel/test-fs-append-file.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fs.appendFile(filename4, n, { mode: m }, function(e) {
9191
common.error('appended to file4');
9292

9393
// windows permissions aren't unix
94-
if (process.platform !== 'win32') {
94+
if (!common.isWindows) {
9595
var st = fs.statSync(filename4);
9696
assert.equal(st.mode & 0o700, m);
9797
}

0 commit comments

Comments
 (0)