From e70dd3a682e6bc75a2b4be8e595be1c647cbf00f Mon Sep 17 00:00:00 2001 From: Olof Kraigher Date: Thu, 11 Jun 2015 14:40:22 +0200 Subject: [PATCH] Adds --exit-0 flag to exit with code 0 even with failed tests but not when a fatal error occured --- user_guide.md | 3 +++ vunit/test/acceptance/test_artificial.py | 8 ++++++++ vunit/ui.py | 9 ++++++--- vunit/vunit_cli.py | 6 ++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/user_guide.md b/user_guide.md index 964c5d89d..414729b78 100644 --- a/user_guide.md +++ b/user_guide.md @@ -57,6 +57,9 @@ optional arguments: Output path for compilation and simulation artifacts -x XUNIT_XML, --xunit-xml XUNIT_XML Xunit test report .xml file + --exit-0 Exit with code 0 even if a test failed. Still exits + with code 1 on fatal errors such as compilation + failure -v, --verbose Print test output immediately and not only when failure --no-color Do not color output diff --git a/vunit/test/acceptance/test_artificial.py b/vunit/test/acceptance/test_artificial.py index 1ab2fddac..4fbe9310a 100644 --- a/vunit/test/acceptance/test_artificial.py +++ b/vunit/test/acceptance/test_artificial.py @@ -140,6 +140,14 @@ def check(self, run_file, args=None, persistent_sim=True, clean=True, exit_code= env=new_env) self.assertEqual(retcode, exit_code) + def test_exit_0_flag(self): + self.check(self.artificial_run, + exit_code=1, + args=["lib.tb_fail"]) + self.check(self.artificial_run, + exit_code=0, + args=["--exit-0", "lib.tb_fail"]) + EXPECTED_REPORT = ( ("passed", "lib.tb_pass"), diff --git a/vunit/ui.py b/vunit/ui.py index da21f9b84..48412ce12 100644 --- a/vunit/ui.py +++ b/vunit/ui.py @@ -80,7 +80,8 @@ def test_filter(name): elaborate_only=args.elaborate, compile_builtins=compile_builtins, simulator_factory=SimulatorFactory(args), - num_threads=args.num_threads) + num_threads=args.num_threads, + exit_0=args.exit_0) def __init__(self, # pylint: disable=too-many-locals, too-many-arguments output_path, @@ -97,7 +98,8 @@ def __init__(self, # pylint: disable=too-many-locals, too-many-arguments elaborate_only=False, vhdl_standard='2008', compile_builtins=True, - num_threads=1): + num_threads=1, + exit_0=False): self._configure_logging(log_level) @@ -129,6 +131,7 @@ def __init__(self, # pylint: disable=too-many-locals, too-many-arguments self._project = None self._create_project() self._num_threads = num_threads + self._exit_0 = exit_0 if compile_builtins: self.add_builtins(library_name="vunit_lib") @@ -307,7 +310,7 @@ def main(self): traceback.print_exc() exit(1) - if not all_ok: + if (not all_ok) and (not self._exit_0): exit(1) exit(0) diff --git a/vunit/vunit_cli.py b/vunit/vunit_cli.py index 64731e053..dbbef7a64 100644 --- a/vunit/vunit_cli.py +++ b/vunit/vunit_cli.py @@ -65,6 +65,12 @@ def create_argument_parser(description=None): default=None, help='Xunit test report .xml file') + parser.add_argument('--exit-0', + default=False, + action="store_true", + help=('Exit with code 0 even if a test failed. ' + 'Still exits with code 1 on fatal errors such as compilation failure')) + parser.add_argument('-v', '--verbose', action="store_true", default=False, help='Print test output immediately and not only when failure')