Commit 7e0dd5a7 authored by Mathieu Giraud's avatar Mathieu Giraud

src/should.py: STATUS_ORDER, combine_status()

Closes #14.
parent 2eff7932
......@@ -109,6 +109,17 @@ STATUS = {
ALLOW_FAILED: 'failed-but-ALLOW',
}
STATUS_ORDER = [
# Failed
False, TODO_PASSED,
# Warnings
TODO, ALLOW_FAILED, SKIP,
# Passed
True,
# 'Forgotten' status when mixed to other tests
None
]
FAIL_STATUS = [False, TODO_PASSED]
WARN_STATUS = FAIL_STATUS + [SKIP, TODO]
......@@ -127,6 +138,22 @@ STATUS_XML[False] = 'failure'
STATUS_XML[SKIP] = 'skipped'
def combine_status(s1, s2):
'''
>>> combine_status(TODO, False)
False
>>> combine_status(True, SKIP) == SKIP
True
>>> combine_status(True, TODO_PASSED) == TODO_PASSED
True
'''
i1 = STATUS_ORDER.index(s1)
i2 = STATUS_ORDER.index(s2)
return STATUS_ORDER[min(i1,i2)]
# Simple colored output
CSIm = '\033[%sm'
......@@ -778,7 +805,7 @@ class TestSuite():
print(color(ANSI.MAGENTA, cmd, colorize))
return cmd
self.status = True
self.status = None
if self.requires_cmd:
requires_cmd = cmd_variables_cd(self.requires_cmd)
......@@ -839,14 +866,7 @@ class TestSuite():
# Test the test
test.test(self.test_lines, variables=self.variables_all, verbose=verbose-1)
self.stats.up(test.status)
# When a test fails, the file fails
if test.status in FAIL_STATUS:
self.status = False
# When the file is not failing, we may report a more sublte status
if test.status in WARN_STATUS and self.status is True:
self.status = test.status
self.status = combine_status(self.status, test.status)
if verbose > 0 or test.status in WARN_STATUS:
print(test.str(colorize))
......@@ -931,7 +951,7 @@ class FileSet():
return len(self.files)
def test(self, variables=None, cd=None, cd_same=False, output=None, verbose=0, only=None):
self.status = True
self.status = None
try:
for f in self.files:
......@@ -944,9 +964,7 @@ class FileSet():
s.test(variables, verbose - 1, only=only)
self.stats.up(s.status, f)
if not s.status:
self.status = False
self.status = combine_status(self.status, s.status)
self.stats_tests += s.stats
filename_without_ext = os.path.splitext(f)[0]
......@@ -1068,6 +1086,6 @@ if __name__ == '__main__':
if len(fs) > 1:
retry = fs.write_retry(sys.argv[1:], args.file, verbose = args.verbose)
sys.exit(0 if status else 1)
sys.exit(1 if status in FAIL_STATUS else 0)
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