Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: using common.isWindows consistently #2269

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-exclusive-implicit-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var dgram = require('dgram');
// supported while using cluster, though servers still cause the master to error
// with ENOTSUP.

var windows = process.platform === 'win32';
var windows = common.isWindows;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well also do it here then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then I thought I covered everything :D


if (cluster.isMaster) {
var pass;
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