From 2a4ac8f6831d14e0e5e5b1075d9a18a2ebbf0973 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 3 Feb 2024 15:29:20 +0900 Subject: [PATCH 1/3] Fix false-negative test case for __bp_install This is an oversight of changing `trap DEBUG` to `trap - DEBUG` in https://github.com/rcaloras/bash-preexec/pull/106 The oversight did not cause a test error because the test always succeeds. The problem is that even if __bp_install is broken and fails to remove `trap - DEBUG`, the current test case failed to detect the failure and produce a false negative. This patch fixes it. --- test/bash-preexec.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bash-preexec.bats b/test/bash-preexec.bats index 3d3f6b7..0d970f6 100644 --- a/test/bash-preexec.bats +++ b/test/bash-preexec.bats @@ -79,7 +79,7 @@ set_exit_code_and_run_precmd() { eval_PROMPT_COMMAND - [[ "$PROMPT_COMMAND" != *"trap DEBUG"* ]] || return 1 + [[ "$PROMPT_COMMAND" != *"trap - DEBUG"* ]] || return 1 [[ "$PROMPT_COMMAND" != *"__bp_install"* ]] || return 1 } From 8913ea5fafdde261bb5ea64eef3ad477be9f589e Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 4 Feb 2024 11:19:24 +0900 Subject: [PATCH 2/3] Use $__bp_install_string for a robust test case --- test/bash-preexec.bats | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/bash-preexec.bats b/test/bash-preexec.bats index 0d970f6..8c8eb10 100644 --- a/test/bash-preexec.bats +++ b/test/bash-preexec.bats @@ -74,13 +74,11 @@ set_exit_code_and_run_precmd() { @test "__bp_install should remove trap logic and itself from PROMPT_COMMAND" { __bp_install_after_session_init - [[ "$PROMPT_COMMAND" == *"trap - DEBUG"* ]] || return 1 - [[ "$PROMPT_COMMAND" == *"__bp_install"* ]] || return 1 + [[ "$PROMPT_COMMAND" == *"$__bp_install_string"* ]] || return 1 eval_PROMPT_COMMAND - [[ "$PROMPT_COMMAND" != *"trap - DEBUG"* ]] || return 1 - [[ "$PROMPT_COMMAND" != *"__bp_install"* ]] || return 1 + [[ "$PROMPT_COMMAND" != *"$__bp_install_string"* ]] || return 1 } @test "__bp_install should preserve an existing DEBUG trap" { From 99d05b9ca9be2bd1f7eef379aef5418cf9a5053c Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 4 Feb 2024 11:57:46 +0900 Subject: [PATCH 3/3] Clarify the intent of the test case Co-authored-by: Michael Diamond --- test/bash-preexec.bats | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/bash-preexec.bats b/test/bash-preexec.bats index 8c8eb10..152d5a6 100644 --- a/test/bash-preexec.bats +++ b/test/bash-preexec.bats @@ -74,6 +74,8 @@ set_exit_code_and_run_precmd() { @test "__bp_install should remove trap logic and itself from PROMPT_COMMAND" { __bp_install_after_session_init + # Assert that before running, the command contains the install string, and + # afterwards it does not [[ "$PROMPT_COMMAND" == *"$__bp_install_string"* ]] || return 1 eval_PROMPT_COMMAND