Commit 760fc37c authored by Mathieu Giraud's avatar Mathieu Giraud

Merge branch 'feature/48-non-zero-exit-code' into 'dev'

Allow to test that EXIT_CODE is not 0

Closes #31

See merge request !25
parents ce98a6dd 60ddda47
Pipeline #2705 passed with stages
in 17 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
......
......@@ -101,6 +101,7 @@ CONTINUATION_CHAR = '\\'
MAX_HALF_DUMP_LINES = 45
MAX_DUMP_LINES = 2*MAX_HALF_DUMP_LINES + 10
NOT_ZERO = '+'
# Simple colored output
......@@ -685,7 +686,7 @@ class TestCase(TestCaseAbstract):
if not m:
raise ShouldException('Error in parsing modifiers: ' + modifiers)
self.modifiers = m.group(1) + m.group(3)
self.expected_count = int(m.group(2)) if m.group(2) else None
self.expected_count = int(m.group(2)) if m.group(2) else NOT_ZERO
# Parse modifiers
self.mods = parser_mod.parse_modifiers(self.modifiers)
......@@ -764,7 +765,7 @@ class TestCase(TestCaseAbstract):
self.count += l.count(expression_var) if self.mods.count_all else 1
# Compute status
if self.expected_count is None:
if self.expected_count == NOT_ZERO:
sta = (self.count > 0)
elif self.mods.less_than:
sta = (self.count < self.expected_count)
......@@ -788,12 +789,12 @@ class TestCase(TestCaseAbstract):
if self.status.is_warned() or verbose:
s += ' (%s/%s%s)' % (self.count,
MOD_LESS_THAN if self.mods.less_than else MOD_MORE_THAN if self.mods.more_than else '',
self.expected_count if self.expected_count is not None else '+')
self.expected_count)
return s
def __repr__(self):
return '%s%s:%s' % (self.modifiers, self.expected_count if self.expected_count is not None else '', self.expression)
return '%s%s:%s' % (self.modifiers, self.expected_count if self.expected_count != NOT_ZERO else '', self.expression)
class TestSuite():
......@@ -920,7 +921,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
......@@ -1007,11 +1009,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