19
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22
assert = require('assert');
23
child = require('child_process');
22
var common = require('../common.js'),
23
assert = require('assert'),
24
child = require('child_process'),
25
nodejs = '"' + process.execPath + '"';
25
nodejs = '"' + process.execPath + '"';
27
// replace \ by / because windows uses backslashes in paths, but they're still
28
// interpreted as the escape character when put between quotes.
29
var filename = __filename.replace(/\\/g, '/');
27
31
if (module.parent) {
28
32
// signal we've been loaded as a module
33
// assert that the result of the final expression is written to stdout
34
child.exec(nodejs + ' --eval "1337; 42"',
35
function(err, stdout, stderr) {
36
assert.equal(parseInt(stdout), 42);
37
// assert that nothing is written to stdout
38
child.exec(nodejs + ' --eval 42',
39
function(err, stdout, stderr) {
40
assert.equal(stdout, '');
43
// assert that "42\n" is written to stderr
44
child.exec(nodejs + ' --eval "console.error(42)"',
45
function(err, stdout, stderr) {
46
assert.equal(stderr, '42\n');
49
// assert that nothing is written to stdout
50
['--print --eval', '-p -e', '-pe'].forEach(function(s) {
51
var cmd = nodejs + ' ' + s + ' ';
53
child.exec(cmd + '42',
54
function(err, stdout, stderr) {
55
assert.equal(stdout, '42\n');
58
child.exec(cmd + "'[]'",
59
function(err, stdout, stderr) {
60
assert.equal(stdout, '[]\n');
39
64
// assert that module loading works
40
child.exec(nodejs + ' --eval "require(\'' + __filename + '\')"',
65
child.exec(nodejs + ' --eval "require(\'' + filename + '\')"',
41
66
function(status, stdout, stderr) {
42
67
assert.equal(status.code, 42);
47
72
function(status, stdout, stderr) {
48
73
assert.equal(status.code, 42);
76
// empty program should do nothing
77
child.exec(nodejs + ' -e ""', function(status, stdout, stderr) {
78
assert.equal(stdout, '');
79
assert.equal(stderr, '');