Skip to content

Commit

Permalink
Fishrock's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
thefourtheye committed Jul 30, 2015
1 parent 4c6280d commit 9d2cfcf
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 49 deletions.
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 = common.isWindows;

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-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 = common.isWindows;

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: 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 = common.isWindows;

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
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 = common.isWindows;

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
11 changes: 5 additions & 6 deletions test/parallel/test-fs-chmod.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var got_error = false;
var success_count = 0;
var mode_async;
var mode_sync;
var is_windows = common.isWindows;

// Need to hijack fs.open/close to make sure that things
// get closed once they're opened.
Expand Down Expand Up @@ -44,7 +43,7 @@ function closeSync() {


// On Windows chmod is only able to manipulate read-only bit
if (is_windows) {
if (common.isWindows) {
mode_async = 0o400; // read-only
mode_sync = 0o600; // read-write
} else {
Expand All @@ -61,14 +60,14 @@ fs.chmod(file1, mode_async.toString(8), function(err) {
} else {
console.log(fs.statSync(file1).mode);

if (is_windows) {
if (common.isWindows) {
assert.ok((fs.statSync(file1).mode & 0o777) & mode_async);
} else {
assert.equal(mode_async, fs.statSync(file1).mode & 0o777);
}

fs.chmodSync(file1, mode_sync);
if (is_windows) {
if (common.isWindows) {
assert.ok((fs.statSync(file1).mode & 0o777) & mode_sync);
} else {
assert.equal(mode_sync, fs.statSync(file1).mode & 0o777);
Expand All @@ -89,14 +88,14 @@ fs.open(file2, 'a', function(err, fd) {
} else {
console.log(fs.fstatSync(fd).mode);

if (is_windows) {
if (common.isWindows) {
assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_async);
} else {
assert.equal(mode_async, fs.fstatSync(fd).mode & 0o777);
}

fs.fchmodSync(fd, mode_sync);
if (is_windows) {
if (common.isWindows) {
assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_sync);
} else {
assert.equal(mode_sync, fs.fstatSync(fd).mode & 0o777);
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-fs-realpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
var async_completed = 0, async_expected = 0, unlink = [];
var isWindows = common.isWindows;
var skipSymlinks = false;

common.refreshTmpDir();

var root = '/';
if (isWindows) {
if (common.isWindows) {
// something like "C:\\"
root = process.cwd().substr(0, 3);

Expand Down Expand Up @@ -292,7 +291,7 @@ function test_relative_input_cwd(callback) {

function test_deep_symlink_mix(callback) {
console.log('test_deep_symlink_mix');
if (isWindows) {
if (common.isWindows) {
// This one is a mix of files and directories, and it's quite tricky
// to get the file/dir links sorted out correctly.
console.log('1..0 # Skipped: symlink test (no privs)');
Expand Down Expand Up @@ -503,7 +502,7 @@ function test_lying_cache_liar(cb) {
'/a/b' : '/a/b',
'/a/b/c' : '/a/b',
'/a/b/d' : '/a/b/d' };
if (isWindows) {
if (common.isWindows) {
var wc = {};
Object.keys(cache).forEach(function(k) {
wc[ path.resolve(k) ] = path.resolve(cache[k]);
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-fs-symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ var expected_async = 4;
var linkTime;
var fileTime;

var is_windows = common.isWindows;

common.refreshTmpDir();

var runtest = function(skip_symlinks) {
Expand Down Expand Up @@ -57,7 +55,7 @@ var runtest = function(skip_symlinks) {
});
};

if (is_windows) {
if (common.isWindows) {
// On Windows, creating symlinks requires admin privileges.
// We'll only try to run symlink test if we have enough privileges.
exec('whoami /priv', function(err, o) {
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-fs-utimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var assert = require('assert');
var util = require('util');
var fs = require('fs');

var is_windows = common.isWindows;

var tests_ok = 0;
var tests_run = 0;

Expand Down Expand Up @@ -99,7 +97,7 @@ function runTest(atime, mtime, callback) {
expect_errno('utimes', 'foobarbaz', err, 'ENOENT');

// don't close this fd
if (is_windows) {
if (common.isWindows) {
fd = fs.openSync(__filename, 'r+');
} else {
fd = fs.openSync(__filename, 'r');
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-write-file-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var isWindows = common.isWindows;
var openCount = 0;
var mode;
var content;
Expand All @@ -20,7 +19,7 @@ var mask = process.umask(0o000);

// On Windows chmod is only able to manipulate read-only bit. Test if creating
// the file in read-only mode works.
if (isWindows) {
if (common.isWindows) {
mode = 0o444;
} else {
mode = 0o755;
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-module-globalpaths-nodepath.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ var assert = require('assert');

var module = require('module');

var isWindows = common.isWindows;

var partA, partB;
var partC = '';

if (isWindows) {
if (common.isWindows) {
partA = 'C:\\Users\\Rocko Artischocko\\AppData\\Roaming\\npm';
partB = 'C:\\Program Files (x86)\\nodejs\\';
process.env['NODE_PATH'] = partA + ';' + partB + ';' + partC;
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-module-nodemodulepaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ var assert = require('assert');

var module = require('module');

var isWindows = common.isWindows;

var file, delimiter, paths;

if (isWindows) {
if (common.isWindows) {
file = 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo';
delimiter = '\\';
} else {
Expand Down
16 changes: 7 additions & 9 deletions test/parallel/test-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var assert = require('assert');

var path = require('path');

var isWindows = common.isWindows;

var f = __filename;

assert.equal(path.basename(f), 'test-path.js');
Expand Down Expand Up @@ -33,7 +31,7 @@ assert.equal(path.posix.basename('basename.ext\\\\'), 'basename.ext\\\\');

// POSIX filenames may include control characters
// c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html
if (!isWindows) {
if (!common.isWindows) {
var controlCharFilename = 'Icon' + String.fromCharCode(13);
assert.equal(path.basename('/a/b/' + controlCharFilename),
controlCharFilename);
Expand All @@ -42,7 +40,7 @@ if (!isWindows) {
assert.equal(path.extname(f), '.js');

assert.equal(path.dirname(f).substr(-13),
isWindows ? 'test\\parallel' : 'test/parallel');
common.isWindows ? 'test\\parallel' : 'test/parallel');
assert.equal(path.dirname('/a/b/'), '/a');
assert.equal(path.dirname('/a/b'), '/a');
assert.equal(path.dirname('/a'), '/');
Expand Down Expand Up @@ -194,7 +192,7 @@ var joinTests =
];

// Windows-specific join tests
if (isWindows) {
if (common.isWindows) {
joinTests = joinTests.concat(
[// UNC path expected
[['//foo/bar'], '//foo/bar/'],
Expand Down Expand Up @@ -246,7 +244,7 @@ if (isWindows) {
// Run the join tests.
joinTests.forEach(function(test) {
var actual = path.join.apply(path, test[0]);
var expected = isWindows ? test[1].replace(/\//g, '\\') : test[1];
var expected = common.isWindows ? test[1].replace(/\//g, '\\') : test[1];
var message = 'path.join(' + test[0].map(JSON.stringify).join(',') + ')' +
'\n expect=' + JSON.stringify(expected) +
'\n actual=' + JSON.stringify(actual);
Expand Down Expand Up @@ -306,7 +304,7 @@ assert.equal(path.posix.normalize('a//b//./c'), 'a/b/c');
assert.equal(path.posix.normalize('a//b//.'), 'a/b');

// path.resolve tests
if (isWindows) {
if (common.isWindows) {
// windows
var resolveTests =
// arguments result
Expand Down Expand Up @@ -360,7 +358,7 @@ assert.equal(path.posix.isAbsolute('bar/'), false);
assert.equal(path.posix.isAbsolute('./baz'), false);

// path.relative tests
if (isWindows) {
if (common.isWindows) {
// windows
var relativeTests =
// arguments result
Expand Down Expand Up @@ -409,7 +407,7 @@ assert.equal(path.win32.delimiter, ';');
assert.equal(path.posix.delimiter, ':');


if (isWindows)
if (common.isWindows)
assert.deepEqual(path, path.win32, 'should be win32 path module');
else
assert.deepEqual(path, path.posix, 'should be posix path module');
4 changes: 1 addition & 3 deletions test/pummel/test-child-process-spawn-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var assert = require('assert');

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

var is_windows = common.isWindows;

var SIZE = 1000 * 1024;
var N = 40;
var finished = false;
Expand All @@ -25,7 +23,7 @@ function doSpawn(i) {

child.on('close', function() {
// + 1 for \n or + 2 for \r\n on Windows
assert.equal(SIZE + (is_windows ? 2 : 1), count);
assert.equal(SIZE + (common.isWindows ? 2 : 1), count);
if (i < N) {
doSpawn(i + 1);
} else {
Expand Down

0 comments on commit 9d2cfcf

Please sign in to comment.