Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding extra info on print_failed_test #263

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,15 @@ function assert_line_count() {
if [ -z "$actual" ]; then
local actual_line_count=0
else
local actual_line_count=$(echo "$actual" | wc -l | tr -d '[:blank:]')
local actual_line_count
actual_line_count=$(echo "$actual" | wc -l | tr -d '[:blank:]')
fi

if [[ "$expected" != "$actual_line_count" ]]; then
state::add_assertions_failed
console_results::print_failed_test "${label}" "${actual}" "to contain number of lines equal to" "${expected}"
console_results::print_failed_test "${label}" "${actual}"\
"to contain number of lines equal to" "${expected}"\
"but found" "${actual_line_count}"
return
fi

Expand Down
8 changes: 8 additions & 0 deletions src/console_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,20 @@ function console_results::print_failed_test() {
local expected=$2
local failure_condition_message=$3
local actual=$4
local extra_key=$5
local extra_value=$6

printf "\
${_COLOR_FAILED}✗ Failed${_COLOR_DEFAULT}: %s
${_COLOR_FAINT}Expected${_COLOR_DEFAULT} ${_COLOR_BOLD}'%s'${_COLOR_DEFAULT}
${_COLOR_FAINT}%s${_COLOR_DEFAULT} ${_COLOR_BOLD}'%s'${_COLOR_DEFAULT}\n"\
"${test_name}" "${expected}" "${failure_condition_message}" "${actual}"

if [ -n "$extra_key" ]; then
printf "\
${_COLOR_FAINT}%s${_COLOR_DEFAULT} ${_COLOR_BOLD}'%s'${_COLOR_DEFAULT}\n"\
"${extra_key}" "${extra_value}"
fi
}

function console_results::print_failed_snapshot_test() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/assert_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,6 @@ function test_successful_assert_line_count() {
function test_unsuccessful_assert_line_count() {
assert_equals\
"$(console_results::print_failed_test\
"Unsuccessful assert line count" "one_line_string" "to contain number of lines equal to" "10")"\
"Unsuccessful assert line count" "one_line_string" "to contain number of lines equal to" "10" "but found" "1")"\
"$(assert_line_count 10 "one_line_string")"
}