1 | var test = require('tap').test;
|
2 | var spawn = require('child_process').spawn;
|
3 | var path = require('path');
|
4 | var concat = require('concat-stream');
|
5 | var vm = require('vm');
|
6 |
|
7 | test('bare shebang', function (t) {
|
8 | t.plan(4);
|
9 |
|
10 | var ps = spawn(process.execPath, [
|
11 | path.resolve(__dirname, '../bin/cmd.js'),
|
12 | '-', '--bare'
|
13 | ]);
|
14 | ps.stderr.pipe(process.stderr);
|
15 | ps.stdout.pipe(concat(function (body) {
|
16 | vm.runInNewContext(body, {
|
17 | Buffer: function (s) { return s.toLowerCase() },
|
18 | console: {
|
19 | log: function (msg) { t.equal(msg, 'woo') }
|
20 | }
|
21 | });
|
22 | vm.runInNewContext(body, {
|
23 | Buffer: Buffer,
|
24 | console: {
|
25 | log: function (msg) {
|
26 | t.ok(Buffer.isBuffer(msg));
|
27 | t.equal(msg.toString('utf8'), 'WOO')
|
28 | }
|
29 | }
|
30 | });
|
31 | }));
|
32 | ps.stdin.end('#!/usr/bin/env node\nconsole.log(Buffer("WOO"))');
|
33 |
|
34 | ps.on('exit', function (code) {
|
35 | t.equal(code, 0);
|
36 | });
|
37 | });
|