From b4004db97776e57c5d81e35e1f6ec90f839564c3 2024-09-09 23:52:23 From: Branko Majic Date: 2024-09-09 23:52:23 Subject: [PATCH] MAR-218: Fix incorrect logic for switching directory: - No piping can be used (since that would be a subshell and would not affect the working directory for the remainder of the script run). --- diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 059a8d418d28dc91aea638e80cf733465a9cdb9d..3937c5ddb65ef18f638b9b0bf1d72e8a74a13dc7 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -282,13 +282,14 @@ for role in "${roles_to_test[@]}"; do info "Running tests for: $role" + # Assume success. This variable gets updated in case of failures. role_test_result=0 # Switch directory, make sure it is successful. - # shellcheck disable=SC2164 # failed directory switch is dealt with additional checks below. - cd "$role_dir" 2>&1 | tee -a "$report_file" - last_pipe_status="${PIPESTATUS[0]}" - [[ $last_pipe_status == 0 ]] || role_test_result="$last_pipe_status" + if ! cd "$role_dir" >> "$report_file" 2>&1; then + role_test_result=1 + error "Failed to switch to directory: $role_dir" + fi # Run the linters. if [[ $role_test_result == 0 ]]; then