Skip to content

Commit c949710

Browse files
committed
fix: test_bashunit_when_a_execution_error
1 parent bcc62d4 commit c949710

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

src/runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function runner::run_test() {
188188
subshell_output=$line
189189
fi
190190

191-
local runtime_output="${test_execution_result%%##ASSERTIONS_=*}"
191+
local runtime_output="${test_execution_result%%##ASSERTIONS_*}"
192192

193193
local runtime_error=""
194194
for error in "command not found" "unbound variable" "permission denied" \

tests/acceptance/bashunit_execution_error_test.sh

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# shellcheck disable=SC2155
23
set -euo pipefail
34

45
function set_up_before_script() {
@@ -7,25 +8,10 @@ function set_up_before_script() {
78

89
function test_bashunit_when_a_execution_error() {
910
local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_execution_error.sh
10-
local fixture_start fixture_end
11-
local color_default color_red color_dim color_bold
12-
13-
color_default="$(sgr 0)"
14-
color_bold="$(sgr 1)"
15-
color_dim="$(sgr 2)"
16-
color_red="$(sgr 31)"
17-
18-
function format_fail_title() {
19-
printf "\n%s%s%s%s" "${color_red}" "$1" "${color_default}" "$2"
20-
}
21-
22-
function format_expect_title() {
23-
printf "\n %s%s%s" "${color_dim}" "$1" "${color_default}"
24-
}
25-
26-
function format_expect_value() {
27-
printf " %s%s%s" "${color_bold}" "$1" "${color_default}"
28-
}
11+
local color_default="$(sgr 0)"
12+
local color_bold="$(sgr 1)"
13+
local color_dim="$(sgr 2)"
14+
local color_red="$(sgr 31)"
2915

3016
function format_summary_title() {
3117
printf "\n%s%s%s" "${color_dim}" "$1" "${color_default}"
@@ -35,26 +21,23 @@ function test_bashunit_when_a_execution_error() {
3521
printf " %s%s%s%s" "${color_red}" "$1" "${color_default}" "$2"
3622
}
3723

38-
fixture_start=$(
39-
printf "${color_bold}%s${color_default}\n" "Running ./tests/acceptance/fixtures/test_bashunit_when_a_execution_error.sh"
40-
format_fail_title "✗ Failed" ": Error"
41-
format_expect_title "Expected"
42-
format_expect_value "'127'"
43-
format_expect_title "to be exactly"
44-
format_expect_value "'1'"
24+
local fixture_start=$(
25+
printf "%sRunning ./tests/acceptance/fixtures/test_bashunit_when_a_execution_error.sh%s\n" \
26+
"${color_bold}" "${color_default}"
27+
printf "%s✗ Error%s: Error\n" "${color_red}" "${color_default}"
28+
printf " %sline 4: invalid_function_name: command not found%s\n" "${color_dim}" "${color_default}"
4529
)
46-
fixture_end=$(
30+
local fixture_end=$(
4731
format_summary_title "Tests: "
4832
format_summary_value "1 failed" ", 1 total"
4933
format_summary_title "Assertions:"
50-
format_summary_value "1 failed" ", 1 total"
34+
format_summary_value "0 failed" ", 0 total"
5135
)
5236

53-
todo "Add snapshots with regex to assert this test (part of the error message is localized)"
54-
todo "Add snapshots with simple/verbose modes as in bashunit_pass_test and bashunit_fail_test"
37+
# todo "Add snapshots with regex to assert this test (part of the error message is localized)"
38+
# todo "Add snapshots with simple/verbose modes as in bashunit_pass_test and bashunit_fail_test"
5539

56-
# shellcheck disable=SC2155
57-
local actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")"
40+
local actual="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")"
5841
assert_contains "$fixture_start" "$actual"
5942
assert_contains "$fixture_end" "$actual"
6043
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")"

tests/acceptance/fixtures/test_bashunit_when_a_execution_error.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
function test_error() {
44
invalid_function_name arg1 arg2
5-
assert_true 0
65
}

0 commit comments

Comments
 (0)