Permalink
Browse files

cleanup child-process boilerplate in in require-tests

  • Loading branch information...
1 parent daa4700 commit 8dd023772ae1f98ab2e1c7053851c4db72a2f684 @timbertson timbertson committed Jun 8, 2012
Showing with 23 additions and 22 deletions.
  1. +23 −22 test/suites/require-tests.sjs
@@ -20,39 +20,40 @@ if (!testUtil.isBrowser) {
var child_process = require('apollo:nodejs/child-process');
var path = require('nodejs:path');
var apollo_path = path.join(http.parseURL(module.id).path, '../../../apollo');
-
- test('apollo -e', {stdout: 'hi\n', stderr: ''}, function() {
- return child_process.run(apollo_path, ['-e', 'require("util").puts("hi");'], {
- env: process.env
- });
- }).serverOnly();
-
- test('hub resolution via $APOLLO_INIT', {stdout: 'HELLO!\n', stderr: ''}, function() {
- var hub_path = path.join(http.parseURL(module.id).path, '../../data/literal-hub.sjs');
- var script = 'require("util").puts(require("literal:exports.hello=\'HELLO!\'").hello);';
+
+ var run_with_env = function(cmd, args, env)
+ {
try {
- var result = child_process.run(apollo_path, ['-e', script], {
- env: common.mergeSettings(process.env, {APOLLO_INIT: hub_path})
+ var result = child_process.run(cmd, args, {
+ env: common.mergeSettings(process.env, env || process.env)
});
return result;
} catch(e) {
console.log(e.stderr);
return e;
}
+ }
+
+ test('apollo -e', {stdout: 'hi\n', stderr: ''}, function() {
+ return run_with_env(apollo_path, ['-e', 'require("util").puts("hi");'], null);
+ }).serverOnly();
+
+ test('hub resolution via $APOLLO_INIT', {stdout: 'HELLO!\n', stderr: ''}, function() {
+ var hub_path = path.join(http.parseURL(module.id).path, '../../data/literal-hub.sjs');
+ var script = 'require("util").puts(require("literal:exports.hello=\'HELLO!\'").hello);';
+ return run_with_env(apollo_path, ['-e', script], {APOLLO_INIT: hub_path});
}).serverOnly();
- test('loading .sjs using NODE_PATH', {stdout: '42\n', stderr: ''}, function() {
+ test('loading .sjs from NODE_PATH', {stdout: '42\n', stderr: ''}, function() {
var script = 'try{}or{}; require("util").puts(require("nodejs:child1.sjs").child1_function1());';
var data_dir = path.join(http.parseURL(module.id).path, '../../data');
- try {
- var result = child_process.run(apollo_path, ['-e', script], {
- env: common.mergeSettings(process.env, {NODE_PATH: data_dir})
- });
- return result;
- } catch(e) {
- console.log(e.stderr);
- return e;
- }
+ return run_with_env(apollo_path, ['-e', script], {NODE_PATH: data_dir});
+ }).serverOnly();
+
+ test('loading .sjs (without an extension) from NODE_PATH', {stdout: '42\n', stderr: ''}, function() {
+ var script = 'waitfor{}or{}; require("util").puts(require("nodejs:child1").child1_function1());';
+ var data_dir = path.join(http.parseURL(module.id).path, '../../data');
+ return run_with_env(apollo_path, ['-e', script], {NODE_PATH: data_dir});
}).serverOnly();
}

0 comments on commit 8dd0237

Please sign in to comment.