bare_shebang.js 1.0 KB

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