test/system: Unbreak the 'toolbox run /etc' tests with Bash >= 5.3

Bash 5.3.0 changed the error messages shown by its exec built-in [1].

With Bash 5.2.37:
  $ exec /etc
  bash: /etc: Is a directory
  bash: exec: /etc: cannot execute: Is a directory

With Bash 5.3.0:
  $ exec /etc
  bash: /etc: Is a directory

The 'assert' function cannot directly handle compound commands.  So,
those need to be wrapped in 'bash -c "..."' [2].

[1] Bash commit b8c60bc9ca365f82
    See how exec_builtin() handles EX_NOEXEC and EISDIR from
    shell_execve() to avoid printing a duplicate error message.
    https://cgit.git.savannah.gnu.org/cgit/bash.git/commit/?id=b8c60bc9ca365f82

[2] https://github.com/bats-core/bats-assert

https://github.com/containers/toolbox/pull/1688
https://github.com/containers/toolbox/pull/1699
This commit is contained in:
Dalibor Kricka 2025-08-07 10:59:59 +02:00 committed by Debarshi Ray
parent d32dd5d322
commit 6c98db6ba2
2 changed files with 18 additions and 6 deletions

View File

@ -811,9 +811,15 @@ teardown() {
assert [ ${#lines[@]} -eq 0 ]
lines=("${stderr_lines[@]}")
assert_line --index 0 "bash: line 1: /etc: Is a directory"
assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory"
assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)"
assert [ ${#stderr_lines[@]} -eq 3 ]
if [ ${#stderr_lines[@]} -eq 2 ]; then
assert_line --index 1 "Error: failed to invoke command /etc in container $(get_latest_container_name)"
elif [ ${#stderr_lines[@]} -eq 3 ]; then
assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory"
assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)"
else
assert bash -c "[ ${#stderr_lines[@]} -eq 2 ] || [ ${#stderr_lines[@]} -eq 3 ]"
fi
}
@test "run: Try a non-existent command" {

View File

@ -92,9 +92,15 @@ teardown() {
assert [ ${#lines[@]} -eq 0 ]
lines=("${stderr_lines[@]}")
assert_line --index 0 "bash: line 1: /etc: Is a directory"
assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory"
assert_line --index 2 "Error: failed to invoke command /etc in container $default_container"
assert [ ${#stderr_lines[@]} -eq 3 ]
if [ ${#stderr_lines[@]} -eq 2 ]; then
assert_line --index 1 "Error: failed to invoke command /etc in container $(get_latest_container_name)"
elif [ ${#stderr_lines[@]} -eq 3 ]; then
assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory"
assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)"
else
assert bash -c "[ ${#stderr_lines[@]} -eq 2 ] || [ ${#stderr_lines[@]} -eq 3 ]"
fi
}
@test "run: Try a non-existent command (forwarded to host)" {