Skip to content
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
143 changes: 87 additions & 56 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,31 @@ To run tests, simply call *bash_unit* with all your tests files as parameter. Fo

```output
Running tests in tests/test_core.sh
Running test_assert_equals_fails_when_not_equal ... SUCCESS
Running test_assert_equals_succeed_when_equal ... SUCCESS
Running test_assert_fails ... SUCCESS
Running test_assert_fails_fails ... SUCCESS
Running test_assert_fails_succeeds ... SUCCESS
Running test_assert_not_equals_fails_when_equal ... SUCCESS
Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS
Running test_assert_shows_stderr_on_failure ... SUCCESS
Running test_assert_shows_stdout_on_failure ... SUCCESS
Running test_assert_status_code_fails ... SUCCESS
Running test_assert_status_code_succeeds ... SUCCESS
Running test_assert_succeeds ... SUCCESS
Running test_fail_fails ... SUCCESS
Running test_fail_prints_failure_message ... SUCCESS
Running test_fail_prints_where_is_error ... SUCCESS
Running test_fake_actually_fakes_the_command ... SUCCESS
Running test_fake_can_fake_inline ... SUCCESS
Running test_fake_echo_stdin_when_no_params ... SUCCESS
Running test_fake_exports_faked_in_subshells ... SUCCESS
Running test_fake_transmits_params_to_fake_code ... SUCCESS
Running test_should_pretty_format_even_when_LANG_is_unset ... SUCCESS
Overall result: SUCCESS
Running test_assert_equals_fails_when_not_equal ... SUCCESS ✓
Running test_assert_equals_succeed_when_equal ... SUCCESS ✓
Running test_assert_fails ... SUCCESS ✓
Running test_assert_fails_fails ... SUCCESS ✓
Running test_assert_fails_succeeds ... SUCCESS ✓
Running test_assert_no_diff_fails_when_diff ... SUCCESS ✓
Running test_assert_no_diff_succeeds_when_no_diff ... SUCCESS ✓
Running test_assert_not_equals_fails_when_equal ... SUCCESS ✓
Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS ✓
Running test_assert_shows_stderr_on_failure ... SUCCESS ✓
Running test_assert_shows_stdout_on_failure ... SUCCESS ✓
Running test_assert_status_code_fails ... SUCCESS ✓
Running test_assert_status_code_succeeds ... SUCCESS ✓
Running test_assert_succeeds ... SUCCESS ✓
Running test_bash_unit_changes_cwd_to_current_test_file_directory ... SUCCESS ✓
Running test_fail_fails ... SUCCESS ✓
Running test_fail_prints_failure_message ... SUCCESS ✓
Running test_fail_prints_where_is_error ... SUCCESS ✓
Running test_fake_actually_fakes_the_command ... SUCCESS ✓
Running test_fake_can_fake_inline ... SUCCESS ✓
Running test_fake_echo_stdin_when_no_params ... SUCCESS ✓
Running test_fake_exports_faked_in_subshells ... SUCCESS ✓
Running test_fake_transmits_params_to_fake_code ... SUCCESS ✓
Running test_should_pretty_format_even_when_LANG_is_unset ... SUCCESS ✓
Overall result: SUCCESS ✓
```

You might also want to run only specific tests, you may do so with the
Expand All @@ -122,20 +125,22 @@ functions against this pattern.

```output
Running tests in tests/test_core.sh
Running test_assert_equals_fails_when_not_equal ... SUCCESS
Running test_assert_equals_succeed_when_equal ... SUCCESS
Running test_assert_fails ... SUCCESS
Running test_assert_fails_fails ... SUCCESS
Running test_assert_fails_succeeds ... SUCCESS
Running test_assert_not_equals_fails_when_equal ... SUCCESS
Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS
Running test_assert_shows_stderr_on_failure ... SUCCESS
Running test_assert_shows_stdout_on_failure ... SUCCESS
Running test_assert_status_code_fails ... SUCCESS
Running test_assert_status_code_succeeds ... SUCCESS
Running test_assert_succeeds ... SUCCESS
Running test_fail_fails ... SUCCESS
Overall result: SUCCESS
Running test_assert_equals_fails_when_not_equal ... SUCCESS ✓
Running test_assert_equals_succeed_when_equal ... SUCCESS ✓
Running test_assert_fails ... SUCCESS ✓
Running test_assert_fails_fails ... SUCCESS ✓
Running test_assert_fails_succeeds ... SUCCESS ✓
Running test_assert_no_diff_fails_when_diff ... SUCCESS ✓
Running test_assert_no_diff_succeeds_when_no_diff ... SUCCESS ✓
Running test_assert_not_equals_fails_when_equal ... SUCCESS ✓
Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS ✓
Running test_assert_shows_stderr_on_failure ... SUCCESS ✓
Running test_assert_shows_stdout_on_failure ... SUCCESS ✓
Running test_assert_status_code_fails ... SUCCESS ✓
Running test_assert_status_code_succeeds ... SUCCESS ✓
Running test_assert_succeeds ... SUCCESS ✓
Running test_fail_fails ... SUCCESS ✓
Overall result: SUCCESS ✓
```

*bash_unit* supports the http://testanything.org/[Test Anything Protocol] so you can ask for a tap formatted
Expand All @@ -147,26 +152,29 @@ output with the _-f_ option.

```output
# Running tests in tests/test_core.sh
ok - test_assert_equals_fails_when_not_equal
ok - test_assert_equals_succeed_when_equal
ok - test_assert_fails
ok - test_assert_fails_fails
ok - test_assert_fails_succeeds
ok - test_assert_not_equals_fails_when_equal
ok - test_assert_not_equals_succeeds_when_not_equal
ok - test_assert_shows_stderr_on_failure
ok - test_assert_shows_stdout_on_failure
ok - test_assert_status_code_fails
ok - test_assert_status_code_succeeds
ok - test_assert_succeeds
ok - test_fail_fails
ok - test_fail_prints_failure_message
ok - test_fail_prints_where_is_error
ok - test_fake_actually_fakes_the_command
ok - test_fake_can_fake_inline
ok - test_fake_echo_stdin_when_no_params
ok - test_fake_exports_faked_in_subshells
ok - test_fake_transmits_params_to_fake_code
ok ✓ test_assert_equals_fails_when_not_equal
ok ✓ test_assert_equals_succeed_when_equal
ok ✓ test_assert_fails
ok ✓ test_assert_fails_fails
ok ✓ test_assert_fails_succeeds
ok ✓ test_assert_no_diff_fails_when_diff
ok ✓ test_assert_no_diff_succeeds_when_no_diff
ok ✓ test_assert_not_equals_fails_when_equal
ok ✓ test_assert_not_equals_succeeds_when_not_equal
ok ✓ test_assert_shows_stderr_on_failure
ok ✓ test_assert_shows_stdout_on_failure
ok ✓ test_assert_status_code_fails
ok ✓ test_assert_status_code_succeeds
ok ✓ test_assert_succeeds
ok ✓ test_bash_unit_changes_cwd_to_current_test_file_directory
ok ✓ test_fail_fails
ok ✓ test_fail_prints_failure_message
ok ✓ test_fail_prints_where_is_error
ok ✓ test_fake_actually_fakes_the_command
ok ✓ test_fake_can_fake_inline
ok ✓ test_fake_echo_stdin_when_no_params
ok ✓ test_fake_exports_faked_in_subshells
ok ✓ test_fake_transmits_params_to_fake_code
ok - test_should_pretty_format_even_when_LANG_is_unset
```

Expand Down Expand Up @@ -405,6 +413,29 @@ doc:2:test_obvious_equality_with_assert_not_equals()
Running test_obvious_inequality_with_assert_not_equals ... SUCCESS
```

=== *assert_no_diff*

assert_no_diff <expected> <actual> [message]

Assert for equality of content between the two files _expected_ and _actual_.

```test
test_obvious_diff_with_assert_no_diff(){
assert_no_diff <(echo foo) <(echo bar) "dynamic files should have no difference"
}
test_obvious_equality_with_assert_no_diff(){
assert_no_diff "$0" "$0"
}
```

```output
Running test_obvious_diff_with_assert_no_diff ... FAILURE ✗
dynamic files should have no difference
expected '/dev/fd/62' to be identical to '/dev/fd/63' but was different
doc:2:test_obvious_diff_with_assert_no_diff()
Running test_obvious_equality_with_assert_no_diff ... SUCCESS ✓
```

== *fake* function

fake <command> [replacement code]
Expand Down
12 changes: 11 additions & 1 deletion bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# https://github.com/pgrange/bash_unit

VERSION=v1.7.2
VERSION=v1.8.0

ESCAPE=$(printf "\033")
NOCOLOR="${ESCAPE}[0m"
Expand Down Expand Up @@ -121,6 +121,16 @@ assert_not_equals() {
fail "$message expected different value than [$unexpected] but was the same"
}

assert_no_diff() {
local expected=$1
local actual=$2
local message=${3:-}
[[ -z $message ]] || message="$message\n"

diff "${expected}" "${actual}" >/dev/null || \
fail "$message expected '${actual}' to be identical to '${expected}' but was different"
}

fake() {
local command=$1
shift
Expand Down
Loading