On Jun 10, 2025 / 08:49, Bart Van Assche wrote: > On 6/9/25 7:05 PM, Shinichiro Kawasaki wrote: > > On Jun 09, 2025 / 10:40, Bart Van Assche wrote: > > > Has the following alternative been considered? Let test script authors add > > > "set -e" and "set +e" where appropriate but only in a subshell. If a failure > > > occurs, only the subshell will be exited and cleanup code will still be > > > executed if it occurs past the subshell. A disadvantage of this > > > approach is that global variables can't be set from inside the subshell > > > and that another mechanism is needed than local variables to pass output > > > from the subshell to the context outside it, e.g. a pipe. > > > > This idea sounds something to consider, but I'm not sure if I fully understand > > it. The word "subshell" is not clear for me. Do you mean subshells those test > > case authors create in each test script? If so I'm not sure how to ensure that > > "set -e" and "set +e" only happen in the subshells. Or do you mean to modify the > > check script to create subshells dedicated for each test case run? If so, I will > > need some work to understand its impact. > > From https://www.gnu.org/software/bash/manual/bash.html: > <quote> > ( list ) > > Placing a list of commands between parentheses forces the shell to create a > subshell (see Command Execution Environment), and each of the commands in > list is executed in that subshell environment. Since the list is executed in > a subshell, variable assignments do not remain in effect after the subshell > completes. > </quote> > > Here is an example that shows how a subshell can be used to halt a test > with "set -e" if a failure occurs in such a way that error handling is > still executed: > > $ bash -c '(set -e; false; echo "Skipped because the previous command > failed"); echo "Error handling commands outside the subshell are still > executed"' > > Error handling commands outside the subshell are still executed Yes, I understand it. I assume that your idea is to ask test case authors to add the subshells in test cases when they want to do "set -e", right? My question is how to ensure that the "set -e" is done only in the subshells. I think we need to rely one code reviews. If "set -e" out of subshells are overlooked in the reviews, the impact for the following test cases are left. Maybe this is not a big risk and we can take it, but I wanted to know what you think about it. > > > > > @@ -372,6 +380,7 @@ _call_test() { > > > > fi > > > > TIMEFORMAT="%Rs" > > > > + ((ERR_EXIT)) && set -e > > > > pushd . >/dev/null || return > > > > { time "$test_func" >"${seqres}.out" 2>&1; } 2>"${seqres}.runtime" > > > > TEST_RUN["exit_status"]=$? > > > > > > This change makes it harder to write test code because it forces authors > > > to surround cleanup code with something like if cleanup_code; then :; fi. > > > > I see, this point makes sense. I'm okay to not call "set -e" in the > > _call_test(). If we take this approach, test cases can do "set -e" and "set +e" > > wherever in the test scripts, but they must declare ERR_EXIT=1. > > Do you agree that with the style of the above example ERR_EXIT is not > needed at all? Generally, yes. I have the one question left as I noted above.