Skip to content

Commit

Permalink
make stderr test work on Windows; update Unix tests for consistency w…
Browse files Browse the repository at this point in the history
…ith Windows tests
  • Loading branch information
mykmelez committed Sep 25, 2012
1 parent 1a1cf8e commit 558d10d
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions tests/test-subprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const subprocess = require("subprocess");
const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);

// For now, only test on windows
if (env.get('OS') && env.get('OS').match(/Windows/))
if (env.get('OS') && env.get('OS').match(/Windows/)) {

exports.testWindows = function (test) {
test.waitUntilDone();
let envTestValue = "OK";
let gotStdout = false;
let gotStderr = false;

var p = subprocess.call({
// Retrieve windows cmd.exe path from env
Expand All @@ -29,13 +29,40 @@ exports.testWindows = function (test) {
test.assertEqual(data,envTestValue+"\r\n","stdout contains the environment variable");
gotStdout = true;
},
stderr: function(data) {
test.fail("shouldn't get stderr");
},
done: function() {
test.assert(gotStdout, "got stdout before finished");
test.done();
},
mergeStderr: false
});

}

exports.testWindowsStderr = function (test) {
test.waitUntilDone();
let gotStderr = false;

var p = subprocess.call({
command: env.get('ComSpec'),
arguments: ['/C', 'nonexistent'],

stdout: function(data) {
test.fail("shouldn't get stdout");
},
stderr: function(data) {
test.assert(!gotStderr,"don't get stderr twice");
test.assertEqual(data,"","stderr is empty");
test.assertEqual(
data,
"'nonexistent' is not recognized as an internal or external command,\r\n" +
"operable program or batch file.\r\n",
"stderr contains the error message"
);
gotStderr = true;
},
done: function() {
test.assert(gotStdout, "got stdout before finished");
test.assert(gotStderr, "got stderr before finished");
test.done();
},
Expand All @@ -44,13 +71,14 @@ exports.testWindows = function (test) {

}

}

if (env.get('USER') && env.get('SHELL')) {

exports.testUnix = function (test) {
test.waitUntilDone();
let envTestValue = "OK";
let gotStdout = false;
let gotStderr = false;

var p = subprocess.call({
command: '/bin/sh',
Expand All @@ -67,9 +95,11 @@ exports.testUnix = function (test) {
test.assertEqual(data,envTestValue+"\n","stdout contains the environment variable");
gotStdout = true;
},
stderr: function(data) {
test.fail("shouldn't get stderr");
},
done: function() {
test.assert(gotStdout, "got stdout before finished");
test.assert(!gotStderr, "didn't get stderr");
test.done();
},
mergeStderr: false
Expand All @@ -85,6 +115,9 @@ exports.testUnixStderr = function (test) {
command: '/bin/sh',
arguments: ['nonexistent'],

stdout: function(data) {
test.fail("shouldn't get stdout");
},
stderr: function(data) {
test.assert(!gotStderr,"don't get stderr twice");
test.assertEqual(data,"/bin/sh: nonexistent: No such file or directory\n",
Expand Down

0 comments on commit 558d10d

Please sign in to comment.