Skip to content

Commit

Permalink
test for ./bin usage
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Feb 1, 2011
1 parent bf20782 commit 35473a4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/_.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var spawn = require('child_process').spawn;
var assert = require('assert');

exports.dotSlashEmpty = function () {
var to = setTimeout(function () {
assert.fail('Never got stdout data.')
}, 1000);

var oldDir = process.cwd();
process.chdir(__dirname + '/_');
var bin = spawn('./bin.js');
process.chdir(oldDir);

bin.stderr.on('data', assert.fail);
bin.stdout.on('data', function (buf) {
clearTimeout(to);
var _ = JSON.parse(buf.toString());
assert.eql(_, []);
});
};

exports.dotSlashArgs = function () {
var to = setTimeout(function () {
assert.fail('Never got stdout data.')
}, 1000);

var oldDir = process.cwd();
process.chdir(__dirname + '/_');
var bin = spawn('./bin.js', ['a','b','c']);
process.chdir(oldDir);

bin.stderr.on('data', assert.fail);
bin.stdout.on('data', function (buf) {
clearTimeout(to);
var _ = JSON.parse(buf.toString());
assert.eql(_, ['a','b','c']);
});
};
3 changes: 3 additions & 0 deletions test/_/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
var argv = require('optimist').argv
console.log(JSON.stringify(argv._));

0 comments on commit 35473a4

Please sign in to comment.