Server IP : 127.0.0.2 / Your IP : 3.129.73.179 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/npm/node_modules/cmd-shim/test/ |
Upload File : |
var test = require('tap').test var mkdirp = require('mkdirp') var fs = require('fs') var path = require('path') var fixtures = path.resolve(__dirname, 'fixtures') var cmdShim = require('../') test('no shebang', function (t) { var from = path.resolve(fixtures, 'from.exe') var to = path.resolve(fixtures, 'exe.shim') cmdShim(from, to, function(er) { if (er) throw er t.equal(fs.readFileSync(to, 'utf8'), "\"$basedir/from.exe\" \"$@\"\nexit $?\n") t.equal(fs.readFileSync(to + '.cmd', 'utf8'), "\"%~dp0\\from.exe\" %*\r\n") t.end() }) }) test('env shebang', function (t) { var from = path.resolve(fixtures, 'from.env') var to = path.resolve(fixtures, 'env.shim') cmdShim(from, to, function(er) { if (er) throw er console.error('%j', fs.readFileSync(to, 'utf8')) console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) t.equal(fs.readFileSync(to, 'utf8'), "#!/bin/sh"+ "\nbasedir=`dirname \"$0\"`"+ "\n"+ "\ncase `uname` in"+ "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+ "\nesac"+ "\n"+ "\nif [ -x \"$basedir/node\" ]; then"+ "\n \"$basedir/node\" \"$basedir/from.env\" \"$@\""+ "\n ret=$?"+ "\nelse "+ "\n node \"$basedir/from.env\" \"$@\""+ "\n ret=$?"+ "\nfi"+ "\nexit $ret"+ "\n") t.equal(fs.readFileSync(to + '.cmd', 'utf8'), "@IF EXIST \"%~dp0\\node.exe\" (\r"+ "\n \"%~dp0\\node.exe\" \"%~dp0\\from.env\" %*\r"+ "\n) ELSE (\r"+ "\n @SETLOCAL\r"+ "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+ "\n node \"%~dp0\\from.env\" %*\r"+ "\n)") t.end() }) }) test('env shebang with args', function (t) { var from = path.resolve(fixtures, 'from.env.args') var to = path.resolve(fixtures, 'env.args.shim') cmdShim(from, to, function(er) { if (er) throw er console.error('%j', fs.readFileSync(to, 'utf8')) console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) t.equal(fs.readFileSync(to, 'utf8'), "#!/bin/sh"+ "\nbasedir=`dirname \"$0\"`"+ "\n"+ "\ncase `uname` in"+ "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+ "\nesac"+ "\n"+ "\nif [ -x \"$basedir/node\" ]; then"+ "\n \"$basedir/node\" --expose_gc \"$basedir/from.env.args\" \"$@\""+ "\n ret=$?"+ "\nelse "+ "\n node --expose_gc \"$basedir/from.env.args\" \"$@\""+ "\n ret=$?"+ "\nfi"+ "\nexit $ret"+ "\n") t.equal(fs.readFileSync(to + '.cmd', 'utf8'), "@IF EXIST \"%~dp0\\node.exe\" (\r"+ "\n \"%~dp0\\node.exe\" --expose_gc \"%~dp0\\from.env.args\" %*\r"+ "\n) ELSE (\r"+ "\n @SETLOCAL\r"+ "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+ "\n node --expose_gc \"%~dp0\\from.env.args\" %*\r"+ "\n)") t.end() }) }) test('explicit shebang', function (t) { var from = path.resolve(fixtures, 'from.sh') var to = path.resolve(fixtures, 'sh.shim') cmdShim(from, to, function(er) { if (er) throw er console.error('%j', fs.readFileSync(to, 'utf8')) console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) t.equal(fs.readFileSync(to, 'utf8'), "#!/bin/sh" + "\nbasedir=`dirname \"$0\"`" + "\n" + "\ncase `uname` in" + "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" + "\nesac" + "\n" + "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" + "\n \"$basedir//usr/bin/sh\" \"$basedir/from.sh\" \"$@\"" + "\n ret=$?" + "\nelse " + "\n /usr/bin/sh \"$basedir/from.sh\" \"$@\"" + "\n ret=$?" + "\nfi" + "\nexit $ret" + "\n") t.equal(fs.readFileSync(to + '.cmd', 'utf8'), "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + "\n \"%~dp0\\/usr/bin/sh.exe\" \"%~dp0\\from.sh\" %*\r" + "\n) ELSE (\r" + "\n @SETLOCAL\r"+ "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+ "\n /usr/bin/sh \"%~dp0\\from.sh\" %*\r" + "\n)") t.end() }) }) test('explicit shebang with args', function (t) { var from = path.resolve(fixtures, 'from.sh.args') var to = path.resolve(fixtures, 'sh.args.shim') cmdShim(from, to, function(er) { if (er) throw er console.error('%j', fs.readFileSync(to, 'utf8')) console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) t.equal(fs.readFileSync(to, 'utf8'), "#!/bin/sh" + "\nbasedir=`dirname \"$0\"`" + "\n" + "\ncase `uname` in" + "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" + "\nesac" + "\n" + "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" + "\n \"$basedir//usr/bin/sh\" -x \"$basedir/from.sh.args\" \"$@\"" + "\n ret=$?" + "\nelse " + "\n /usr/bin/sh -x \"$basedir/from.sh.args\" \"$@\"" + "\n ret=$?" + "\nfi" + "\nexit $ret" + "\n") t.equal(fs.readFileSync(to + '.cmd', 'utf8'), "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + "\n \"%~dp0\\/usr/bin/sh.exe\" -x \"%~dp0\\from.sh.args\" %*\r" + "\n) ELSE (\r" + "\n @SETLOCAL\r"+ "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+ "\n /usr/bin/sh -x \"%~dp0\\from.sh.args\" %*\r" + "\n)") t.end() }) })