Skip to content

Commit b365916

Browse files
authored
Merge pull request #389 from TypedDevs/fix/381-multiple-errors-display-lines
Fix display multiline errors within the same test
2 parents 7a7cc5a + c017f03 commit b365916

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## Unreleased
44

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

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

src/globals.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,7 @@ function log() {
7171
*) set -- "$level $@"; level="INFO" ;;
7272
esac
7373

74-
echo "$(current_timestamp) [$level]: $@" >> "$BASHUNIT_DEV_LOG"
74+
local GRAY='\033[1;30m'
75+
local RESET='\033[0m'
76+
echo -e "$(current_timestamp) [$level]: $@ ${GRAY}#${BASH_SOURCE[1]}:${BASH_LINENO[0]}${RESET}" >> "$BASHUNIT_DEV_LOG"
7577
}

src/runner.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ function runner::run_test() {
187187
local type="${subshell_output%%]*}" # Remove everything after "]"
188188
type="${type#[}" # Remove the leading "["
189189
local line="${subshell_output#*]}" # Remove everything before and including "]"
190+
191+
# Replace [type] with a newline to split the messages
192+
line=$(echo "$line" | sed -e 's/\[failed\]/\n/g' \
193+
-e 's/\[skipped\]/\n/g' \
194+
-e 's/\[incomplete\]/\n/g')
195+
190196
state::print_line "$type" "$line"
191197

192198
subshell_output=$line

tests/acceptance/bashunit_fail_test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ function test_bashunit_when_a_test_fail_simple_output_option() {
4444
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)"
4545
}
4646

47+
function test_bashunit_with_multiple_failing_tests() {
48+
local test_file=./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh
49+
50+
# shellcheck disable=SC2317
51+
assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")"
52+
# shellcheck disable=SC2317
53+
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)"
54+
}
55+
4756
function test_different_simple_snapshots_matches() {
4857
todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?"
4958
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
function test_assert_same() {
4+
assert_same 1 1
5+
}
6+
7+
function test_assert_failing() {
8+
assert_same 1 2
9+
assert_same 3 4
10+
}
11+
12+
function test_assert_todo_and_skip() {
13+
todo "foo"
14+
skip "bar"
15+
}
16+
17+
function test_assert_skip_and_todo() {
18+
skip "baz"
19+
todo "yei"
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Running ./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh
2+
✓ Passed: Assert same
3+
✗ Failed: Assert failing
4+
Expected '1'
5+
but got  '2'
6+
✗ Failed: Assert failing
7+
Expected '3'
8+
but got  '4'
9+
✒ Incomplete: Assert todo and skip foo
10+
↷ Skipped: Assert todo and skip bar
11+
↷ Skipped: Assert skip and todo baz
12+
✒ Incomplete: Assert skip and todo yei
13+
14+
There was 1 failure:
15+
16+
|1) ./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh
17+
|✗ Failed: Assert failing
18+
| Expected '1'
19+
| but got  '2'
20+
|✗ Failed: Assert failing
21+
| Expected '3'
22+
| but got  '4'
23+
24+
Tests:  1 passed, 0 skipped, 2 incomplete, 1 failed, 4 total
25+
Assertions: 1 passed, 2 skipped, 2 incomplete, 2 failed, 7 total
26+
27+
 Some tests failed 

0 commit comments

Comments
 (0)