From cbe1ff51003fe5ec7c2f76fbb83aa7acaf1eb250 Mon Sep 17 00:00:00 2001 From: Paul Ferrell Date: Fri, 11 Jul 2025 12:28:28 -0600 Subject: [PATCH 1/3] Making sure we capture exit code when not auto-exiting. --- lib/pavilion/test_run/test_run.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pavilion/test_run/test_run.py b/lib/pavilion/test_run/test_run.py index be335e23b..e227dac8a 100644 --- a/lib/pavilion/test_run/test_run.py +++ b/lib/pavilion/test_run/test_run.py @@ -1225,9 +1225,10 @@ def _write_script(self, stype: str, path: Path, config: dict, module_wrappers: d script.command(f'echo "(pav) Executing {stype} commands."') script.newline() cmds = config.get('cmds', []) + autoexit = utils.str_bool(self.config.get(stype, {}).get('autoexit')) if cmds: script.comment("Perform the sequence of test commands.") - if utils.str_bool(self.config.get(stype, {}).get('autoexit')): + if autoexit: script.command("set -e -o pipefail") for line in config.get('cmds', []): if line is None: @@ -1237,7 +1238,13 @@ def _write_script(self, stype: str, path: Path, config: dict, module_wrappers: d else: script.comment('No commands given for this script.') + # When autoexit isn't set, we need to preserve the return value of the last script command. + if not autoexit: + script.command("PAV_EXIT=$?") script.command(f'echo "(pav) Test {stype} commands completed without error."') + if not autoexit: + script.command("exit $PAV_EXIT") + script.write(path) From 4fc2ab99c229f0f8300716f34fa0317a86048b6f Mon Sep 17 00:00:00 2001 From: Paul Ferrell Date: Fri, 11 Jul 2025 14:06:14 -0600 Subject: [PATCH 2/3] Fixed the 'err' bash function. --- bin/pav-lib.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pav-lib.bash b/bin/pav-lib.bash index b60446b41..3db18d980 100644 --- a/bin/pav-lib.bash +++ b/bin/pav-lib.bash @@ -4,7 +4,7 @@ PAV_PATH=$(dirname "${BASH_SOURCE[0]}")/pav # Echo the first argument, then return false function err() { echo $1 - return 1 + exit 1 } # Find the module command to use. It's printed to stdout, nothing is printed if From b23a4691ecc2a74fabca35910382acdd418bc4c5 Mon Sep 17 00:00:00 2001 From: Paul Ferrell Date: Fri, 11 Jul 2025 14:10:57 -0600 Subject: [PATCH 3/3] Added regression test. --- test/tests/autoexit_tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/tests/autoexit_tests.py b/test/tests/autoexit_tests.py index 693c9a80d..a4df76de2 100644 --- a/test/tests/autoexit_tests.py +++ b/test/tests/autoexit_tests.py @@ -23,3 +23,13 @@ def test_autoexit(self): test = self._quick_test(cfg=cfg_run_no) testreturn = test.run() self.assertEqual(testreturn, 0) + + # Make sure we actually catch the case where the final return is false. + cfg_run_no = self._quick_test_cfg() + cfg_run_no['run'] = {'cmds': ['false', 'echo "did not exit"', 'false'], 'autoexit': 'False'} + test = self._quick_test(cfg=cfg_run_no) + testreturn = test.run() + self.assertEqual(testreturn, 1) + with open(test.path/'run.log') as file: + self.assertIn("did not exit", file.read()) +