Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/pav-lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/pavilion/test_run/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions test/tests/autoexit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Loading