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

Fix display multiline errors within the same test #389

Merged
merged 7 commits into from
Dec 5, 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Unreleased

- Fixed name rendered when having `test_test_*`
- Fixed display test with multiple outputs in multiline
- Improved output: adding a space between each test file
- Removed `BASHUNIT_DEV_MODE` in favor of `BASHUNIT_DEV_LOG`
- Fixed name rendered when having `test_test_*`
- Added source file and line on global dev function `log`

## [0.18.0](https://github.com/TypedDevs/bashunit/compare/0.17.0...0.18.0) - 2024-10-16

Expand Down
4 changes: 3 additions & 1 deletion src/globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ function log() {
*) set -- "$level $@"; level="INFO" ;;
esac

echo "$(current_timestamp) [$level]: $@" >> "$BASHUNIT_DEV_LOG"
local GRAY='\033[1;30m'
local RESET='\033[0m'
echo -e "$(current_timestamp) [$level]: $@ ${GRAY}#${BASH_SOURCE[1]}:${BASH_LINENO[0]}${RESET}" >> "$BASHUNIT_DEV_LOG"
}
6 changes: 6 additions & 0 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ function runner::run_test() {
local type="${subshell_output%%]*}" # Remove everything after "]"
type="${type#[}" # Remove the leading "["
local line="${subshell_output#*]}" # Remove everything before and including "]"

# Replace [type] with a newline to split the messages
line=$(echo "$line" | sed -e 's/\[failed\]/\n/g' \
-e 's/\[skipped\]/\n/g' \
-e 's/\[incomplete\]/\n/g')

state::print_line "$type" "$line"

subshell_output=$line
Expand Down
9 changes: 9 additions & 0 deletions tests/acceptance/bashunit_fail_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ function test_bashunit_when_a_test_fail_simple_output_option() {
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)"
}

function test_bashunit_with_multiple_failing_tests() {
local test_file=./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh

# shellcheck disable=SC2317
assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")"
# shellcheck disable=SC2317
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)"
}

function test_different_simple_snapshots_matches() {
todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

function test_assert_same() {
assert_same 1 1
}

function test_assert_failing() {
assert_same 1 2
assert_same 3 4
}

function test_assert_todo_and_skip() {
todo "foo"
skip "bar"
}

function test_assert_skip_and_todo() {
skip "baz"
todo "yei"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Running ./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh
βœ“ Passed: Assert same
βœ— Failed: Assert failing
Expected '1'
but got  '2'
βœ— Failed: Assert failing
Expected '3'
but got  '4'
βœ’ Incomplete: Assert todo and skip foo
↷ Skipped: Assert todo and skip bar
↷ Skipped: Assert skip and todo baz
βœ’ Incomplete: Assert skip and todo yei

There was 1 failure:

|1) ./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh
|βœ— Failed: Assert failing
| Expected '1'
| but got  '2'
|βœ— Failed: Assert failing
| Expected '3'
| but got  '4'

Tests:  1 passed, 0 skipped, 2 incomplete, 1 failed, 4 total
Assertions: 1 passed, 2 skipped, 2 incomplete, 2 failed, 7 total

 Some tests failed 
Loading