coffee_bin.js 1020 B

123456789101112131415161718192021222324252627282930313233343536
  1. var test = require('tap').test;
  2. var spawn = require('child_process').spawn;
  3. var path = require('path');
  4. var vm = require('vm');
  5. test('compiling coffee with -c', function (t) {
  6. t.plan(4);
  7. var cwd = process.cwd();
  8. process.chdir(__dirname);
  9. var ps = spawn(process.execPath, [
  10. path.resolve(__dirname, '../bin/cmd.js'),
  11. '-c', '"' + process.execPath + '" "' + __dirname + '/../node_modules/coffee-script/bin/coffee" -sc',
  12. 'coffee_bin/main.coffee'
  13. ]);
  14. var src = '';
  15. var err = '';
  16. ps.stdout.on('data', function (buf) { src += buf });
  17. ps.stderr.on('data', function (buf) { err += buf });
  18. ps.on('exit', function (code) {
  19. t.equal(code, 0);
  20. t.equal(err, '');
  21. var msgs = [ 'hello world!', 'from x!' ];
  22. var c = {
  23. console: {
  24. log: function (msg) {
  25. t.equal(msg, msgs.shift());
  26. }
  27. }
  28. };
  29. vm.runInNewContext(src, c);
  30. });
  31. });