vesln / nixt

Simple and elegant end-to-end testing for command-line apps
MIT License
310 stars 19 forks source link

Linking commands (&&) doesn't return correct exit code. #13

Closed reggi closed 8 years ago

reggi commented 9 years ago

This assertion does not work as expected, it throws an error.

it('should return exit code 1', function (done) {
  return nixt()
  .run('node -e \'process.exit(0)\' && node -e \'process.exit(1)\'')
  .code(1)
  .end(done)
})
AssertionError: `node -e 'process.exit(0)' && node -e 'process.exit(1)'`: Expected exit code: "1", actual: "0"
reggi commented 9 years ago

npm's default test expression breaks too.

it('should return exit code 1', function (done) {
  return nixt()
  .run('echo \"Error: no test specified\" && exit 1')
  .code(0)
  .end(done)
})
reggi commented 9 years ago

Also can't run exit.

it('should return exit 1', function (done) {
  return nixt()
  .run('exit 1')
  .code(0)
  .end(done)
})

Uncaught Error: spawn exit ENOENT

vesln commented 9 years ago

lmk if you wanna try to investigate & provide a patch, happy to give contributor/npm access

eush77 commented 8 years ago

@reggi && and exit aren't actually supposed to work.

nixt uses child_process.spawn to spawn a process, not child_process.exec. The difference between the two is that spawn simply starts a new process with the given arguments, and exec spawns a shell process (/bin/sh or cmd.exe) and passes the command to that shell. The latter is substantially different, because the shell language usually includes many things such as sequencing operators (e.g. && and ||), stdio redirection, loops and conditionals, built-in commands (e.g. exit) and so on.

Do you still need to be able to use shell operators or builtins with nixt? If so, what is your use case?

eush77 commented 8 years ago

Closing due to lack of response.