diff --git a/CHANGELOG.md b/CHANGELOG.md index 922d5ade..f4e266d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/globals.sh b/src/globals.sh index 7314b978..4e8a7f75 100644 --- a/src/globals.sh +++ b/src/globals.sh @@ -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" } diff --git a/src/runner.sh b/src/runner.sh index 764b82b8..67706e04 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -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 diff --git a/tests/acceptance/bashunit_fail_test.sh b/tests/acceptance/bashunit_fail_test.sh index 7e7a1ea2..821747a9 100644 --- a/tests/acceptance/bashunit_fail_test.sh +++ b/tests/acceptance/bashunit_fail_test.sh @@ -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?" } diff --git a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh new file mode 100644 index 00000000..a4ea5377 --- /dev/null +++ b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh @@ -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" +} diff --git a/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot new file mode 100644 index 00000000..16777156 --- /dev/null +++ b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot @@ -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