Skip to content

Commit

Permalink
d/patches: Add fixes for Bash 5.2
Browse files Browse the repository at this point in the history
These patches have been extracted from upstream PR #656 ("Fix endless
loop on CTRL-C with bash 5.2").

bats-core/bats-core#656

Closes: #1020017
  • Loading branch information
gioele committed Sep 25, 2022
1 parent b925d1f commit 4d284fd
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 0 deletions.
29 changes: 29 additions & 0 deletions debian/patches/0001-Fix-kernel-debug-messages-fixes-654.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From: Martin Schulze <martin.schulze@vireso.de>
Date: Sun, 18 Sep 2022 21:38:05 +0200
Subject: Fix kernel debug messages (fixes #654)

due to wait in wait because of read in trap
---
lib/bats-core/tracing.bash | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/bats-core/tracing.bash b/lib/bats-core/tracing.bash
index 49a375d..d1d86e0 100644
--- a/lib/bats-core/tracing.bash
+++ b/lib/bats-core/tracing.bash
@@ -380,8 +380,7 @@ bats_interrupt_trap() {
BATS_INTERRUPTED=true
BATS_ERROR_STATUS=130
# debug trap fires before interrupt trap but gets wrong linenumber (line 1)
- # -> use last stack trace
- exit $BATS_ERROR_STATUS
+ # -> use last stack trace instead of BATS_DEBUG_LAST_STACK_TRACE_IS_VALID=true
}

# this is used inside run()
@@ -390,5 +389,4 @@ bats_interrupt_trap_in_run() {
BATS_INTERRUPTED=true
BATS_ERROR_STATUS=130
BATS_DEBUG_LAST_STACK_TRACE_IS_VALID=true
- exit $BATS_ERROR_STATUS
}
40 changes: 40 additions & 0 deletions debian/patches/0002-Ensure-code-after-SIGINT-does-not-run.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From: Martin Schulze <martin.schulze@vireso.de>
Date: Sun, 18 Sep 2022 21:38:30 +0200
Subject: Ensure code after SIGINT does not run

---
test/bats.bats | 2 ++
test/fixtures/bats/hang_in_test.bats | 7 ++++---
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/test/bats.bats b/test/bats.bats
index dee9ce9..3d3ea6e 100755
--- a/test/bats.bats
+++ b/test/bats.bats
@@ -771,8 +771,10 @@ END_OF_ERR_MSG

[ "${lines[1]}" == "not ok 1 test" ]
# due to scheduling the exact line will vary but we should exit with 130
+ [[ "${lines[2]}" == "# (in test file "*")" ]] || false
[[ "${lines[3]}" == *"failed with status 130" ]] || false
[ "${lines[4]}" == "# Received SIGINT, aborting ..." ]
+ [ ${#lines[@]} -eq 5 ]
}

@test "CTRL-C aborts and fails the current run" {
diff --git a/test/fixtures/bats/hang_in_test.bats b/test/fixtures/bats/hang_in_test.bats
index 52479b1..208f2dc 100644
--- a/test/fixtures/bats/hang_in_test.bats
+++ b/test/fixtures/bats/hang_in_test.bats
@@ -3,6 +3,7 @@ setup() {
}

@test "test" {
- single-use-latch::signal hang_in_test
- sleep 10
-}
\ No newline at end of file
+ single-use-latch::signal hang_in_test
+ sleep 10
+ echo "after sleep" # this should not be printed
+}
37 changes: 37 additions & 0 deletions debian/patches/0003-junit-Fix-xml_escape-for-Bash-5.2-RC.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From: Martin Schulze <martin.schulze@vireso.de>
Date: Fri, 23 Sep 2022 23:40:36 +0200
Subject: junit: Fix xml_escape for Bash 5.2 RC

From [Bash 5.2 release notes](https://mail.gnu.org/archive/html/bug-bash/2022-07/msg00129.html):
x. New shell option: patsub_replacement. When enabled, a `&' in the replacement
string of the pattern substitution expansion is replaced by the portion of
the string that matched the pattern. Backslash will escape the `&' and
insert a literal `&'.
---
libexec/bats-core/bats-format-junit | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libexec/bats-core/bats-format-junit b/libexec/bats-core/bats-format-junit
index a649bdb..993b4f2 100755
--- a/libexec/bats-core/bats-format-junit
+++ b/libexec/bats-core/bats-format-junit
@@ -99,13 +99,13 @@ print_test_case() {
}

xml_escape() {
- output=${1//&/&amp;}
- output=${output//</&lt;}
- output=${output//>/&gt;}
- output=${output//'"'/&quot;}
- output=${output//\'/&#39;}
+ output=${1//&/\&amp;}
+ output=${output//</\&lt;}
+ output=${output//>/\&gt;}
+ output=${output//'"'/\&quot;}
+ output=${output//\'/\&#39;}
local CONTROL_CHAR=$'\033'
- output="${output//$CONTROL_CHAR/&#27;}"
+ output="${output//$CONTROL_CHAR/\&#27;}"
printf "%s" "$output"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
From: Martin Schulze <martin.schulze@vireso.de>
Date: Fri, 23 Sep 2022 23:55:39 +0200
Subject: junit: Fix control char escaping in Bash <4.3

Otherwise would contain the \
---
libexec/bats-core/bats-format-junit | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libexec/bats-core/bats-format-junit b/libexec/bats-core/bats-format-junit
index 993b4f2..1792ec1 100755
--- a/libexec/bats-core/bats-format-junit
+++ b/libexec/bats-core/bats-format-junit
@@ -105,7 +105,7 @@ xml_escape() {
output=${output//'"'/\&quot;}
output=${output//\'/\&#39;}
local CONTROL_CHAR=$'\033'
- output="${output//$CONTROL_CHAR/\&#27;}"
+ output=${output//$CONTROL_CHAR/\&#27;}
printf "%s" "$output"
}

18 changes: 18 additions & 0 deletions debian/patches/0005-Fix-CTRL-C-on-run-test-for-Bash-4.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
From: Martin Schulze <martin.schulze@vireso.de>
Date: Sat, 24 Sep 2022 01:46:34 +0200
Subject: Fix CTRL+C on run test for Bash 4.3

---
lib/bats-core/tracing.bash | 1 +
1 file changed, 1 insertion(+)

diff --git a/lib/bats-core/tracing.bash b/lib/bats-core/tracing.bash
index d1d86e0..9f59622 100644
--- a/lib/bats-core/tracing.bash
+++ b/lib/bats-core/tracing.bash
@@ -389,4 +389,5 @@ bats_interrupt_trap_in_run() {
BATS_INTERRUPTED=true
BATS_ERROR_STATUS=130
BATS_DEBUG_LAST_STACK_TRACE_IS_VALID=true
+ exit 130
}
5 changes: 5 additions & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0001-Fix-kernel-debug-messages-fixes-654.patch
0002-Ensure-code-after-SIGINT-does-not-run.patch
0003-junit-Fix-xml_escape-for-Bash-5.2-RC.patch
0004-junit-Fix-control-char-escaping-in-Bash-4.3.patch
0005-Fix-CTRL-C-on-run-test-for-Bash-4.3.patch

0 comments on commit 4d284fd

Please sign in to comment.