1 var test = require('tap').test
2 var mkdirp = require('mkdirp')
4 var path = require('path')
5 var fixtures = path.resolve(__dirname, 'fixtures')
7 var cmdShim = require('../')
9 test('no shebang', function (t) {
10 var from = path.resolve(fixtures, 'from.exe')
11 var to = path.resolve(fixtures, 'exe.shim')
12 cmdShim(from, to, function(er) {
15 t.equal(fs.readFileSync(to, 'utf8'),
16 "\"$basedir/from.exe\" \"$@\"\nexit $?\n")
17 t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
18 "@\"%~dp0\\from.exe\" %*\r\n")
23 test('env shebang', function (t) {
24 var from = path.resolve(fixtures, 'from.env')
25 var to = path.resolve(fixtures, 'env.shim')
26 cmdShim(from, to, function(er) {
29 console.error('%j', fs.readFileSync(to, 'utf8'))
30 console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
32 t.equal(fs.readFileSync(to, 'utf8'),
34 "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
37 "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
40 "\nif [ -x \"$basedir/node\" ]; then"+
41 "\n \"$basedir/node\" \"$basedir/from.env\" \"$@\""+
44 "\n node \"$basedir/from.env\" \"$@\""+
49 t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
50 "@IF EXIST \"%~dp0\\node.exe\" (\r"+
51 "\n \"%~dp0\\node.exe\" \"%~dp0\\from.env\" %*\r"+
54 "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
55 "\n node \"%~dp0\\from.env\" %*\r"+
61 test('env shebang with args', function (t) {
62 var from = path.resolve(fixtures, 'from.env.args')
63 var to = path.resolve(fixtures, 'env.args.shim')
64 cmdShim(from, to, function(er) {
67 console.error('%j', fs.readFileSync(to, 'utf8'))
68 console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
70 t.equal(fs.readFileSync(to, 'utf8'),
72 "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
75 "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
78 "\nif [ -x \"$basedir/node\" ]; then"+
79 "\n \"$basedir/node\" --expose_gc \"$basedir/from.env.args\" \"$@\""+
82 "\n node --expose_gc \"$basedir/from.env.args\" \"$@\""+
87 t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
88 "@IF EXIST \"%~dp0\\node.exe\" (\r"+
89 "\n \"%~dp0\\node.exe\" --expose_gc \"%~dp0\\from.env.args\" %*\r"+
92 "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
93 "\n node --expose_gc \"%~dp0\\from.env.args\" %*\r"+
99 test('explicit shebang', function (t) {
100 var from = path.resolve(fixtures, 'from.sh')
101 var to = path.resolve(fixtures, 'sh.shim')
102 cmdShim(from, to, function(er) {
105 console.error('%j', fs.readFileSync(to, 'utf8'))
106 console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
108 t.equal(fs.readFileSync(to, 'utf8'),
110 "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
112 "\ncase `uname` in" +
113 "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" +
116 "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" +
117 "\n \"$basedir//usr/bin/sh\" \"$basedir/from.sh\" \"$@\"" +
120 "\n /usr/bin/sh \"$basedir/from.sh\" \"$@\"" +
126 t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
127 "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
128 "\n \"%~dp0\\/usr/bin/sh.exe\" \"%~dp0\\from.sh\" %*\r" +
131 "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
132 "\n /usr/bin/sh \"%~dp0\\from.sh\" %*\r" +
138 test('explicit shebang with args', function (t) {
139 var from = path.resolve(fixtures, 'from.sh.args')
140 var to = path.resolve(fixtures, 'sh.args.shim')
141 cmdShim(from, to, function(er) {
144 console.error('%j', fs.readFileSync(to, 'utf8'))
145 console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
147 t.equal(fs.readFileSync(to, 'utf8'),
149 "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
151 "\ncase `uname` in" +
152 "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" +
155 "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" +
156 "\n \"$basedir//usr/bin/sh\" -x \"$basedir/from.sh.args\" \"$@\"" +
159 "\n /usr/bin/sh -x \"$basedir/from.sh.args\" \"$@\"" +
165 t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
166 "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
167 "\n \"%~dp0\\/usr/bin/sh.exe\" -x \"%~dp0\\from.sh.args\" %*\r" +
170 "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
171 "\n /usr/bin/sh -x \"%~dp0\\from.sh.args\" %*\r" +