Commit 60ddda47 authored by Mathieu Giraud's avatar Mathieu Giraud

demo/exit-code.should, src/should.py: test non-zero exit codes

closes #31
parent 061eb38d
Pipeline #2676 passed with stages
in 15 seconds
......@@ -2,9 +2,14 @@
# Other exit codes can be given
# The files differ
$ Exit code is exactly '1'
!EXIT_CODE: 1
diff demo/hello.should demo/cal.should
$ Exit code is not zero
!EXIT_CODE: +
diff demo/hello.should demo/cal.should
$ 'world' is in the diff
: world
......
......@@ -817,7 +817,8 @@ class TestSuite():
# Directive -- Exit code
if l.startswith(DIRECTIVE_EXIT_CODE):
self.expected_exit_code = int(l[len(DIRECTIVE_EXIT_CODE):].strip())
e = l[len(DIRECTIVE_EXIT_CODE):].strip()
self.expected_exit_code = NOT_ZERO if e == NOT_ZERO else int(e)
continue
# Name
......@@ -904,11 +905,15 @@ class TestSuite():
stdout=f_stdout, stderr=f_stderr,
close_fds=True)
exit_code_message = 'Exit code is %d -- %s' % (self.expected_exit_code, cmd)
exit_code_message = 'Exit code is %s -- %s' % (self.expected_exit_code, cmd)
try:
self.exit_code = p.wait(self.timeout)
exit_test = ExternalTestCase(exit_code_message, self.exit_code == self.expected_exit_code, str(self.exit_code))
if self.expected_exit_code == NOT_ZERO:
success = (self.exit_code > 0)
else:
success = (self.exit_code == self.expected_exit_code)
exit_test = ExternalTestCase(exit_code_message, success, str(self.exit_code))
except subprocess.TimeoutExpired:
self.exit_code = None
exit_test = ExternalTestCase(exit_code_message, S_SKIP, 'timeout after %s seconds' % self.timeout)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment