mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.8 KiB
95 lines
2.8 KiB
14 years ago
|
// Copyright Joyent, Inc. and other Node contributors.
|
||
|
//
|
||
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
// copy of this software and associated documentation files (the
|
||
|
// "Software"), to deal in the Software without restriction, including
|
||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||
|
// persons to whom the Software is furnished to do so, subject to the
|
||
|
// following conditions:
|
||
|
//
|
||
|
// The above copyright notice and this permission notice shall be included
|
||
|
// in all copies or substantial portions of the Software.
|
||
|
//
|
||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
|
||
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var spawn = require('child_process').spawn;
|
||
|
var path = require('path');
|
||
15 years ago
|
|
||
|
var returns = 0;
|
||
|
|
||
|
/*
|
||
14 years ago
|
Spawns 'pwd' with given options, then test
|
||
15 years ago
|
- whether the exit code equals forCode,
|
||
14 years ago
|
- optionally whether the stdout result matches forData
|
||
|
(after removing traling whitespace)
|
||
15 years ago
|
*/
|
||
|
function testCwd(options, forCode, forData) {
|
||
14 years ago
|
var data = '';
|
||
|
|
||
|
var child = common.spawnPwd(options);
|
||
14 years ago
|
|
||
15 years ago
|
child.stdout.setEncoding('utf8');
|
||
|
|
||
13 years ago
|
child.stdout.on('data', function(chunk) {
|
||
15 years ago
|
data += chunk;
|
||
|
});
|
||
14 years ago
|
|
||
13 years ago
|
child.on('exit', function(code, signal) {
|
||
15 years ago
|
assert.strictEqual(forCode, code);
|
||
13 years ago
|
});
|
||
|
|
||
|
child.on('close', function () {
|
||
|
forData && assert.strictEqual(forData, data.replace(/[\s\r\n]+$/, ''));
|
||
15 years ago
|
returns--;
|
||
|
});
|
||
14 years ago
|
|
||
15 years ago
|
returns++;
|
||
13 years ago
|
|
||
|
return child;
|
||
15 years ago
|
}
|
||
|
|
||
|
// Assume these exist, and 'pwd' gives us the right directory back
|
||
13 years ago
|
if (process.platform == 'win32') {
|
||
14 years ago
|
testCwd({cwd: process.env.windir}, 0, process.env.windir);
|
||
|
testCwd({cwd: 'c:\\'}, 0, 'c:\\');
|
||
|
} else {
|
||
|
testCwd({cwd: '/dev'}, 0, '/dev');
|
||
|
testCwd({cwd: '/'}, 0, '/');
|
||
|
}
|
||
15 years ago
|
|
||
13 years ago
|
// Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT
|
||
|
(function() {
|
||
|
var errors = 0;
|
||
|
|
||
|
testCwd({cwd: 'does-not-exist'}, -1).on('error', function(e) {
|
||
|
assert.equal(e.code, 'ENOENT');
|
||
|
errors++;
|
||
|
});
|
||
|
|
||
|
process.on('exit', function() {
|
||
|
assert.equal(errors, 1);
|
||
|
});
|
||
|
})();
|
||
15 years ago
|
|
||
|
// Spawn() shouldn't try to chdir() so this should just work
|
||
14 years ago
|
testCwd(undefined, 0);
|
||
|
testCwd({}, 0);
|
||
|
testCwd({cwd: ''}, 0);
|
||
|
testCwd({cwd: undefined}, 0);
|
||
|
testCwd({cwd: null}, 0);
|
||
15 years ago
|
|
||
|
// Check whether all tests actually returned
|
||
|
assert.notEqual(0, returns);
|
||
13 years ago
|
process.on('exit', function() {
|
||
15 years ago
|
assert.equal(0, returns);
|
||
14 years ago
|
});
|