-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f73d89
commit b9ce374
Showing
54 changed files
with
1,143 additions
and
1,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* eslint-disable no-octal */ | ||
|
||
var | ||
assert = require('assert'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
existsSync = fs.existsSync || path.existsSync; | ||
|
||
|
||
module.exports.assertName = function assertName(name, expected) { | ||
assert.ok(typeof name == 'string'); | ||
assert.ok(name.length > 0, 'an empty string is not a valid name'); | ||
if (expected) { | ||
assert.equal(path.basename(name), expected, 'should be the expected name'); | ||
} | ||
}; | ||
|
||
|
||
module.exports.assertStat = function assertStat(name, mode) { | ||
var stat = fs.statSync(name); | ||
|
||
/* | ||
// geteuid() and getegid() do not exist on Windows. | ||
// must use the effective gid and effective uid for testing | ||
if (process.geteuid) { | ||
assert.equal(stat.uid, process.geteuid(), 'should have the same UID'); | ||
} | ||
if (process.getegid) { | ||
// FIXME does not always work as expected (setgid bit on parent directory) | ||
console.log('stat.gid ' + stat.gid); | ||
console.log('egid ' + process.getegid()); | ||
assert.equal(stat.gid, process.getegid(), 'should have the same GUID'); | ||
} | ||
*/ | ||
|
||
// mode values do not work properly on Windows. Ignore “group” and | ||
// “other” bits then. Ignore execute bit on that platform because it | ||
// doesn’t exist—even for directories. | ||
if (process.platform == 'win32') { | ||
assert.equal(stat.mode & 000600, mode & 000600); | ||
} else { | ||
assert.equal(stat.mode & 000777, mode); | ||
} | ||
}; | ||
|
||
|
||
module.exports.assertPrefix = function assertPrefix(name, prefix) { | ||
assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'should have the provided prefix'); | ||
}; | ||
|
||
|
||
module.exports.assertPostfix = function assertPostfix(name, postfix) { | ||
assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'should have the provided postfix'); | ||
}; | ||
|
||
|
||
module.exports.assertProperResult = function assertProperResult(result, withfd) { | ||
assert.ok(result); | ||
assert.ok(result.name, 'should have a name'); | ||
if (withfd) assert.ok(result.fd, 'should have an fd'); | ||
else assert.strictEqual(result.fd, undefined, 'should not have an fd'); | ||
assert.ok(typeof result.removeCallback == 'function', 'should have a removeCallback'); | ||
}; | ||
|
||
|
||
module.exports.assertExists = function assertExists(name, isfile) { | ||
assert.ok(existsSync(name), name + ' should exist'); | ||
var stat = fs.statSync(name); | ||
if (isfile) assert.ok(stat.isFile(), name + ' should be a file'); | ||
else assert.ok(stat.isDirectory(), name + ' should be a directory'); | ||
}; | ||
|
||
|
||
module.exports.assertDoesNotExist = function assertDoesNotExist(name) { | ||
assert.ok(!existsSync(name), name + ' should not exist'); | ||
}; | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// vim: expandtab:ts=2:sw=2 | ||
|
||
var | ||
fs = require('fs'), | ||
path = require('path'), | ||
existsSync = fs.existsSync || path.existsSync, | ||
spawn = require('child_process').spawn; | ||
|
||
|
||
module.exports = function spawnChildProcess(configFile, cb) { | ||
var | ||
node_path = process.argv[0], | ||
command_args = [ path.join(__dirname, 'spawn.js') ].concat(configFile), | ||
stdoutBufs = [], | ||
stderrBufs = [], | ||
child, | ||
done = false, | ||
stderrDone = false, | ||
stdoutDone = false; | ||
|
||
// make sure that the config file exists | ||
if (!existsSync(path.join(__dirname, configFile))) | ||
return cb(new Error('ENOENT: configFile ' + path.join(__dirname, configFile) + ' does not exist')); | ||
|
||
// spawn doesn’t have the quoting problems that exec does, | ||
// especially when going for Windows portability. | ||
child = spawn(node_path, command_args); | ||
child.stdin.end(); | ||
// Cannot use 'close' event because not on node-0.6. | ||
function _close() { | ||
var | ||
stderr = _bufferConcat(stderrBufs).toString(), | ||
stdout = _bufferConcat(stdoutBufs).toString(); | ||
if (stderrDone && stdoutDone && !done) { | ||
done = true; | ||
cb(null, stderr, stdout); | ||
} | ||
} | ||
child.on('error', function _spawnError(err) { | ||
if (!done) { | ||
done = true; | ||
cb(err); | ||
} | ||
}); | ||
child.stdout.on('data', function _stdoutData(data) { | ||
stdoutBufs.push(data); | ||
}).on('close', function _stdoutEnd() { | ||
stdoutDone = true; | ||
_close(); | ||
}); | ||
child.stderr.on('data', function _stderrData(data) { | ||
stderrBufs.push(data); | ||
}).on('close', function _stderrEnd() { | ||
stderrDone = true; | ||
_close(); | ||
}); | ||
} | ||
|
||
|
||
function _bufferConcat(buffers) { | ||
if (Buffer.concat) { | ||
return Buffer.concat.apply(this, arguments); | ||
} else { | ||
return new Buffer(buffers.reduce(function (acc, buf) { | ||
for (var i = 0; i < buf.length; i++) { | ||
acc.push(buf[i]); | ||
} | ||
return acc; | ||
}, [])); | ||
} | ||
} | ||
|
Oops, something went wrong.