Skip to content

Commit

Permalink
fix: test_bashunit_when_a_execution_error
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Oct 14, 2024
1 parent bcc62d4 commit 238d570
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function runner::run_test() {
subshell_output=$line
fi

local runtime_output="${test_execution_result%%##ASSERTIONS_=*}"
local runtime_output="${test_execution_result%%##ASSERTIONS_*}"

local runtime_error=""
for error in "command not found" "unbound variable" "permission denied" \
Expand Down
43 changes: 13 additions & 30 deletions tests/acceptance/bashunit_execution_error_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC2155
set -euo pipefail

function set_up_before_script() {
Expand All @@ -7,25 +8,10 @@ function set_up_before_script() {

function test_bashunit_when_a_execution_error() {
local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_execution_error.sh
local fixture_start fixture_end
local color_default color_red color_dim color_bold

color_default="$(sgr 0)"
color_bold="$(sgr 1)"
color_dim="$(sgr 2)"
color_red="$(sgr 31)"

function format_fail_title() {
printf "\n%s%s%s%s" "${color_red}" "$1" "${color_default}" "$2"
}

function format_expect_title() {
printf "\n %s%s%s" "${color_dim}" "$1" "${color_default}"
}

function format_expect_value() {
printf " %s%s%s" "${color_bold}" "$1" "${color_default}"
}
local color_default="$(sgr 0)"
local color_bold="$(sgr 1)"
local color_dim="$(sgr 2)"
local color_red="$(sgr 31)"

function format_summary_title() {
printf "\n%s%s%s" "${color_dim}" "$1" "${color_default}"
Expand All @@ -35,26 +21,23 @@ function test_bashunit_when_a_execution_error() {
printf " %s%s%s%s" "${color_red}" "$1" "${color_default}" "$2"
}

fixture_start=$(
printf "${color_bold}%s${color_default}\n" "Running ./tests/acceptance/fixtures/test_bashunit_when_a_execution_error.sh"
format_fail_title "✗ Failed" ": Error"
format_expect_title "Expected"
format_expect_value "'127'"
format_expect_title "to be exactly"
format_expect_value "'1'"
local fixture_start=$(
printf "%sRunning ./tests/acceptance/fixtures/test_bashunit_when_a_execution_error.sh%s\n" \
"${color_bold}" "${color_default}"
printf "%s✗ Error%s: Error\n" "${color_red}" "${color_default}"
printf " %sline 4: invalid_function_name: command not found%s\n" "${color_dim}" "${color_default}"
)
fixture_end=$(
local fixture_end=$(
format_summary_title "Tests: "
format_summary_value "1 failed" ", 1 total"
format_summary_title "Assertions:"
format_summary_value "1 failed" ", 1 total"
format_summary_value "0 failed" ", 0 total"
)

todo "Add snapshots with regex to assert this test (part of the error message is localized)"
todo "Add snapshots with simple/verbose modes as in bashunit_pass_test and bashunit_fail_test"

# shellcheck disable=SC2155
local actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")"
local actual="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")"
assert_contains "$fixture_start" "$actual"
assert_contains "$fixture_end" "$actual"
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

function test_error() {
invalid_function_name arg1 arg2
assert_true 0
}

0 comments on commit 238d570

Please sign in to comment.