aiiie / cram

Functional tests for command line applications
GNU General Public License v2.0
198 stars 50 forks source link

Differentiate between stdout and stderr #8

Open esc opened 8 years ago

esc commented 8 years ago

Is is possible to differentiate between stdout and stderr? For example to check that an error message was printed to stderr instead of stdout?

cc @snordhausen

aiiie commented 8 years ago

You could redirect the two streams to separate files and cat them/check the output separately. Would that work for what you're trying to do?

E.g:

  $ command 2> stderr.log > stdout.log
  $ cat stderr.log
  Error message!
  $ cat stdout.log
  Regular output!

I'm trying to think of how this could be supported directly in the test syntax, but I'm not sure if it's possible. Right now when Cram invokes the shell, it redirects stderr to stdout. This makes it possible for the two output streams to be properly mixed together and checked in the tests. If Cram didn't do that redirection, I'm not sure it'd be possible to interleave the two output streams properly after the fact.

esc commented 8 years ago

Maybe an alternative syntax could be used, with a special symbol, e.g. |:

  $ command
  Regular output!
  |Error message!

I am guessing here, but the separation and redirection could work, although it is somewhat cumbersome.