Skip to content

Commit

Permalink
Exit with a non-zero exit status if test(s) fail.
Browse files Browse the repository at this point in the history
Oops.  Didn't realise this wasn't already happening...
  • Loading branch information
James Spencer committed Apr 17, 2013
1 parent dd80397 commit e5bc028
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions bin/testcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ def end_status(tests, skipped=0, verbose=True):
else:
print(' [%s/%s]%s'% (npassed, nran, skipped_msg))

return 0 if nran == npassed else 1

#--- main runner ---

def main(args):
Expand All @@ -536,14 +538,15 @@ def main(args):
options.benchmark, options.user_option,
options.job_option)

ret_val = 0
if not (len(actions) == 1 and 'tidy' in actions):
start_status(tests, 'run' in actions, verbose)
if 'run' in actions:
run_tests(tests, verbose, options.queue_system, options.tot_nprocs)
end_status(tests, 0, verbose)
ret_val = end_status(tests, 0, verbose)
if 'compare' in actions:
nskipped = compare_tests(tests, verbose)
end_status(tests, nskipped, verbose)
ret_val = end_status(tests, nskipped, verbose)
if 'diff' in actions:
diff_tests(tests, user_options['diff'], verbose)
if 'tidy' in actions:
Expand All @@ -555,6 +558,8 @@ def main(args):
if 'make-benchmarks' in actions:
make_benchmarks(test_programs, tests, userconfig, start_time)

return ret_val

if __name__ == '__main__':

main(sys.argv[1:])
sys.exit(main(sys.argv[1:]))
7 changes: 6 additions & 1 deletion docs/testcode.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,18 @@ Options
Override/add setting to :ref:`userconfig`. Takes three arguments. Format:
section_name option_name value. Default: none.

Exit status
-----------

1 if one or more tests fail (run and compare actions only) and 0 otherwise.

License
-------

Modified BSD License. See LICENSE in the source code for more details.

Bugs
----

Contact James Spencer (j.spencer@imperial.ac.uk) regarding bug reports,
suggestions for improvements or code contributions.

0 comments on commit e5bc028

Please sign in to comment.