Commit 11395827 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos

regtest: Return an exist status code depending on whether the command succeeded

parent 44cf2de0
......@@ -194,6 +194,8 @@ class TestRun:
self._queue.join()
return int(self._n_passed != self._n_run)
def summary(self):
self.printer.printout_ln()
......
......@@ -44,7 +44,7 @@ class Command:
def execute(self, args):
ns = self._parser.parse_args(args)
self.run(vars(ns))
return self.run(vars(ns))
def run(self, options):
raise NotImplementedError
......@@ -68,7 +68,7 @@ def _get_command(command_name):
def run(args):
command_class = _get_command(args[0])
command = command_class()
command.execute(args[1:])
return command.execute(args[1:])
def print_help():
import os
......
......@@ -63,4 +63,6 @@ class CreateRefs(Command):
refs.create_refs_for_file(os.path.basename(doc))
get_printer().printout_ln("Refs created in %s" % (t.elapsed_str()))
return 0
register_command('create-refs', CreateRefs)
......@@ -55,4 +55,6 @@ class CreateReport(Command):
report = HTMLReport(docs_dir, options['refs_dir'], options['out_dir'])
report.create()
return 0
register_command('create-report', CreateReport)
......@@ -68,11 +68,13 @@ class FindRegression(Command):
doc = options['test']
if not os.path.isfile(doc):
get_printer().printerr("Invalid test %s: not a regulat file" % (doc))
return
return 1
t = Timer()
bisect = Bisect(options['test'], options['refs_dir'], options['out_dir'])
bisect.run()
get_printer().printout_ln("Tests run in %s" % (t.elapsed_str()))
return 0
register_command('find-regression', FindRegression)
......@@ -65,10 +65,12 @@ class RunTests(Command):
tests = TestRun(docs_dir, options['refs_dir'], options['out_dir'])
if doc == docs_dir:
tests.run_tests()
status = tests.run_tests()
else:
tests.run_test(os.path.basename(doc))
status = tests.run_test(os.path.basename(doc))
tests.summary()
get_printer().printout_ln("Tests run in %s" % (t.elapsed_str()))
return status
register_command('run-tests', RunTests)
......@@ -80,16 +80,16 @@ def main(args):
c.threads = n_cpus - c.threads
try:
commands.run(args)
return commands.run(args)
except commands.UnknownCommandError:
sys.stderr.write("Unknown command: %s\n" % (args[0]))
commands.print_help()
sys.exit(1)
return 1
except backends.UnknownBackendError as e:
sys.stderr.write(str(e) + "\n")
sys.stdout.write("Backends are: %s\n" % (", ".join([backend.get_name() for backend in backends.get_all_backends()])))
sys.exit(1)
return 1
if __name__ == '__main__':
import sys
main(sys.argv[1:])
sys.exit(main(sys.argv[1:]))
......@@ -3,4 +3,4 @@
import sys
import main
main.main(sys.argv[1:])
sys.exit(main.main(sys.argv[1:]))
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