Skip to content

Commit 1da651c

Browse files
authored
debug src/Bash/handlePipelineFailure.bats flaky test (#122)
disabled src/Bash/handlePipelineFailure.bats on alpine
1 parent 8661646 commit 1da651c

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

.pre-commit-config-github.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525

2626
- repo: https://github.com/executablebooks/mdformat
2727
# Do this before other tools "fixing" the line endings
28-
rev: 0.7.21
28+
rev: 0.7.22
2929
hooks:
3030
- id: mdformat
3131
name: Format Markdown
@@ -80,13 +80,13 @@ repos:
8080
)
8181
8282
- repo: https://github.com/rhysd/actionlint
83-
rev: v1.7.4
83+
rev: v1.7.7
8484
hooks:
8585
- id: actionlint
8686
stages: [pre-commit, pre-push, manual]
8787

8888
- repo: https://github.com/codespell-project/codespell
89-
rev: v2.3.0
89+
rev: v2.4.1
9090
hooks:
9191
- id: codespell
9292
args:
@@ -150,7 +150,7 @@ repos:
150150
)
151151
152152
- repo: https://github.com/fchastanet/bash-tools-framework
153-
rev: 6.1.1
153+
rev: 6.2.1
154154
hooks:
155155
- id: fixShebangExecutionBit
156156
- id: awkLint
@@ -195,6 +195,6 @@ repos:
195195
stages: [manual] # GITHUB
196196

197197
- repo: https://github.com/fchastanet/bash-compiler
198-
rev: 3.1.3
198+
rev: 3.1.4
199199
hooks:
200200
- id: buildBashBinaries

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020

2121
- repo: https://github.com/executablebooks/mdformat
2222
# Do this before other tools "fixing" the line endings
23-
rev: 0.7.21
23+
rev: 0.7.22
2424
hooks:
2525
- id: mdformat
2626
name: Format Markdown
@@ -75,13 +75,13 @@ repos:
7575
)
7676
7777
- repo: https://github.com/rhysd/actionlint
78-
rev: v1.7.4
78+
rev: v1.7.7
7979
hooks:
8080
- id: actionlint
8181
stages: [pre-commit, pre-push, manual]
8282

8383
- repo: https://github.com/codespell-project/codespell
84-
rev: v2.3.0
84+
rev: v2.4.1
8585
hooks:
8686
- id: codespell
8787
args:
@@ -145,7 +145,7 @@ repos:
145145
)
146146
147147
- repo: https://github.com/fchastanet/bash-tools-framework
148-
rev: 6.1.1
148+
rev: 6.2.1
149149
hooks:
150150
- id: fixShebangExecutionBit
151151
- id: awkLint
@@ -190,6 +190,6 @@ repos:
190190
stages: [] # GITHUB
191191

192192
- repo: https://github.com/fchastanet/bash-compiler
193-
rev: 3.1.3
193+
rev: 3.1.4
194194
hooks:
195195
- id: buildBashBinaries

bin/dockerLint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ Assert::tty() {
334334
# @arg $2 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array
335335
# @env PIPESTATUS assuming that this function is called like in the example provided
336336
# @see https://unix.stackexchange.com/a/709880/582856
337+
# @see https://gitlab.alpinelinux.org/alpine/aports/-/issues/11152
338+
# @warning alpine does not support PIPESTATUS very well as execution order of piped process is
339+
# not guaranteed
337340
Bash::handlePipelineFailure() {
338341
local -a pipeStatusBackup=("${PIPESTATUS[@]}")
339342
local -n handlePipelineFailure_resultingStatusCode=$1

src/Bash/handlePipelineFailure.bats

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ source "$(cd "${BATS_TEST_DIRNAME}/.." && pwd)/batsHeaders.sh"
77
# shellcheck source=src/Bash/handlePipelineFailure.sh
88
source "${srcDir}/Bash/handlePipelineFailure.sh"
99

10+
# bats file_tags=ubuntu_only
11+
1012
function Bash::handlePipelineFailure::withHead { #@test
1113
local resultingStatus=0
1214
local -a originalPipeStatus=()
1315
yes | head -n 1 || Bash::handlePipelineFailure resultingStatus originalPipeStatus
1416
[[ "${resultingStatus}" = "0" ]]
15-
[[ "${originalPipeStatus[*]}" = "141 0" ]]
17+
run echo "${originalPipeStatus[*]}"
18+
assert_output "141 0"
1619
}
1720

1821
function Bash::handlePipelineFailure::withHeadWithoutStatusArg { #@test
@@ -26,7 +29,8 @@ function Bash::handlePipelineFailure::unknownCommand { #@test
2629
local -a originalPipeStatus=()
2730
unknownCommand | head -n 1 || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
2831
[[ "${resultingStatus}" = "127" ]]
29-
[[ "${originalPipeStatus[*]}" = "127 0" ]]
32+
run echo "${originalPipeStatus[*]}"
33+
assert_output "127 0"
3034
}
3135

3236
function Bash::handlePipelineFailure::unknownCommandWithoutStatusArg { #@test
@@ -40,7 +44,8 @@ function Bash::handlePipelineFailure::shouldFail { #@test
4044
local -a originalPipeStatus=()
4145
echo "test" | grep -q "hello" || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
4246
[[ "${resultingStatus}" = "1" ]]
43-
[[ "${originalPipeStatus[*]}" = "0 1" ]]
47+
run echo "${originalPipeStatus[*]}"
48+
assert_output "0 1"
4449
}
4550

4651
function Bash::handlePipelineFailure::shouldFailWithoutStatusArg { #@test
@@ -54,8 +59,8 @@ function Bash::handlePipelineFailure::shouldWork { #@test
5459
local -a originalPipeStatus=()
5560
"${FRAMEWORK_ROOT_DIR}/bin/findShebangFiles" --help | grep -q DESCRIPTION || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
5661
[[ "${resultingStatus}" = "0" ]]
57-
echo "${originalPipeStatus[*]}" >&3
58-
[[ "${originalPipeStatus[*]}" = "141 0" ]]
62+
run echo "${originalPipeStatus[*]}"
63+
assert_output "141 0"
5964
}
6065

6166
function Bash::handlePipelineFailure::shouldWorkWithoutStatusArg { #@test
@@ -69,29 +74,33 @@ function Bash::handlePipelineFailure::shouldWorkWith2Pipes { #@test
6974
local -a originalPipeStatus=()
7075
"${FRAMEWORK_ROOT_DIR}/bin/findShebangFiles" --help | grep -q DESCRIPTION | cat || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
7176
[[ "${resultingStatus}" = "0" ]]
72-
[[ "${originalPipeStatus[*]}" = "141 0 0" ]]
77+
run echo "${originalPipeStatus[*]}"
78+
assert_output "141 0 0"
7379
}
7480

7581
function Bash::handlePipelineFailure::shouldWorkWith2PipesBis { #@test
7682
local resultingStatus=0
7783
local -a originalPipeStatus=()
7884
echo "world" | "${FRAMEWORK_ROOT_DIR}/bin/findShebangFiles" --help | grep -q DESCRIPTION || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
7985
[[ "${resultingStatus}" = "0" ]]
80-
[[ "${originalPipeStatus[*]}" = "0 141 0" ]]
86+
run echo "${originalPipeStatus[*]}"
87+
assert_output "0 141 0"
8188
}
8289

8390
function Bash::handlePipelineFailure::shouldFailWith2Pipes { #@test
8491
local resultingStatus=0
8592
local -a originalPipeStatus=()
8693
echo "test" | grep t | grep -q "hello" || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
8794
[[ "${resultingStatus}" = "1" ]]
88-
[[ "${originalPipeStatus[*]}" = "0 0 1" ]]
95+
run echo "${originalPipeStatus[*]}"
96+
assert_output "0 0 1"
8997
}
9098

9199
function Bash::handlePipelineFailure::shouldFailWith2PipesBis { #@test
92100
local resultingStatus=0
93101
local -a originalPipeStatus=()
94102
echo "test" | grep -q "hello" | grep t || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
95103
[[ "${resultingStatus}" = "1" ]]
96-
[[ "${originalPipeStatus[*]}" = "0 1 1" ]]
104+
run echo "${originalPipeStatus[*]}"
105+
assert_output "0 1 1"
97106
}

src/Bash/handlePipelineFailure.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# @arg $2 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array
1111
# @env PIPESTATUS assuming that this function is called like in the example provided
1212
# @see https://unix.stackexchange.com/a/709880/582856
13+
# @see https://gitlab.alpinelinux.org/alpine/aports/-/issues/11152
14+
# @warning alpine does not support PIPESTATUS very well as execution order of piped process is
15+
# not guaranteed
1316
Bash::handlePipelineFailure() {
1417
local -a pipeStatusBackup=("${PIPESTATUS[@]}")
1518
local -n handlePipelineFailure_resultingStatusCode=$1

0 commit comments

Comments
 (0)