Skip to content

Commit

Permalink
Merge pull request #389 from TypedDevs/fix/381-multiple-errors-displa…
Browse files Browse the repository at this point in the history
…y-lines

Fix display multiline errors within the same test
  • Loading branch information
Chemaclass authored Dec 5, 2024
2 parents 7a7cc5a + c017f03 commit b365916
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
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 

0 comments on commit b365916

Please sign in to comment.