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:
		
							parent
							
								
									d32dd5d322
								
							
						
					
					
						commit
						6c98db6ba2
					
				|  | @ -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" { | ||||
|  |  | |||
|  | @ -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)" { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue