-
Notifications
You must be signed in to change notification settings - Fork 723
/
shjs.js
31 lines (24 loc) · 1.09 KB
/
shjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var shell = require('..');
var common = require('../src/common');
var path = require('path');
var assert = require('assert');
function runScript(name) {
// prefix with 'node ' for Windows, don't prefix for OSX/Linux
var cmd = (process.platform === 'win32' ? JSON.stringify(common.nodeBinPath) + ' ' : '') + path.resolve(__dirname, '../bin/shjs');
var script = path.resolve(__dirname, 'resources', 'shjs', name);
return shell.exec(cmd + ' ' + script, { silent: true });
}
// Exit Codes
assert.equal(runScript('exit-codes.js').code, 42, 'exit code works');
assert.equal(runScript('exit-0.js').code, 0, 'exiting 0 works');
// Stdout/Stderr
var stdioRet = runScript('stdout-stderr.js');
assert.equal(stdioRet.stdout, 'stdout: OK!\n', 'stdout works');
assert.equal(stdioRet.stderr, 'stderr: OK!\n', 'stderr works');
// CoffeeScript
assert.equal(runScript('coffeescript.coffee').stdout, 'CoffeeScript: OK!\n');
// Extension detection
var extDetectRet = runScript('a-file');
assert.equal(extDetectRet.code, 0, 'error code works');
assert.equal(extDetectRet.stdout, 'OK!\n', 'stdout works');
shell.exit(123);