Skip to content

test(executor): pin GNU exit-unwind semantics through AND-OR lists - #122

Merged
caomengxuan666 merged 1 commit into
unixwin:masterfrom
daiaji:test/exit-and-or-unwind-regressions
Sep 24, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:masterfrom
daiaji:test/exit-and-or-unwind-regressions

Conversation

@daiaji

@daiaji daiaji commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

What

Adds 10 executor unit tests pinning GNU exit-unwind semantics through AND-OR lists (builtins/exit.def:157 jump_to_top_level (EXITPROG) → execute_cmd.c:1622). Only true subshell boundaries — parentheses, pipeline stages, command substitutions — may contain an exit; every enclosing AND-OR list, function and brace group must unwind to the shell's top level.

Covered:

Context Assertion
true && exit 5 / exit 0 && … / [ … ] || exit 1 Err(ExitCode(n)), shell terminates
exit inside a function's && list / brace group / loop guard Err(ExitCode(n)) — brace groups and functions are not subshells
(exit 5); echo after Ok — subshell boundary contains it
exit 5 | cat; echo after Ok — pipeline-stage boundary
v=$(true && exit 5; echo hi) Ok, status 5, substitution killed before hi
set -e; false && exit 1; echo ok Ok, 0 — guarded context keeps errexit suppressed

Why

c5c97683 fixed a real regression where ExecuteError::ExitCode was downgraded to a plain status inside AND-OR list execution. On the affected builds the classic [ -f x ] || exit 1 guard silently no-op'd (documented as niubash shell-quirks Q3), and nothing caught it because no test exercised exit inside an AND-OR list — the set -e suites masked it (errexit fires at the next command). This locks the unwind in so it cannot regress unnoticed again.

Notes

  • Based on 2bb0277c (verified compiling). Heads-up: current master tip a81c1d2 does not compile standalone — cargo test --lib fails with 5 × E0599 on comsub_body_alias_splice (from the comsub: heredoc <<-/quoted delimiters commit) — worth a look before the next release.
  • The 3 pre-existing lib-test failures on this host (builtins::test::…modified_since_read…, substitution_metadata::…expanded_word_tracks…, …readback_preserves…) reproduce on clean 2bb0277c without this change; 428→438 passing here with zero new failures.

GNU builtins/exit.def:157 exit_builtin calls jump_to_top_level
(EXITPROG), handled at execute_cmd.c:1622: exit unwinds every enclosing
AND-OR list, function and brace group to the shell's top level; only
true subshell boundaries (parentheses, pipeline stages, command
substitutions) contain it.

c5c9768 fixed a regression where ExitCode was downgraded to a plain
status inside AND-OR list execution, which let the classic
'[ -f x ] || exit 1' guard silently no-op (niubash shell-quirks doc
Q3). These tests pin the fixed semantics so the unwind cannot regress
unnoticed again:

- exit terminates from: mid-list, list head, or-guard, function body,
  brace group, loop guard (the Q3 repro shape)
- exit stays contained in: parentheses, pipeline stages, command
  substitutions (assignment carries the substitution status)
- guarded 'false && exit 1' under set -e still does not fire errexit
@daiaji
daiaji force-pushed the test/exit-and-or-unwind-regressions branch from cdbb02f to 24c45b6 Compare September 24, 2026 04:48
@caomengxuan666
caomengxuan666 merged commit ac217b1 into unixwin:master Sep 24, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank for your test case!

@daiaji
daiaji deleted the test/exit-and-or-unwind-regressions branch September 24, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants