Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bats-core/bats-assert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Wheeler <joshwheeler33@gmail.com>2021-10-19 07:02:34 +0300
committerJosh Wheeler <joshwheeler33@gmail.com>2021-10-19 07:20:01 +0300
commit38bfbf61443c046acf91b678a5a8eb5a0ab13000 (patch)
tree58758376397f08af95957aaed597d04364409752
parent672ad1823a4d2f0c475fdbec0c4497498eec5f41 (diff)
Add support for 'assert_not_equal'.
-rw-r--r--README.md23
-rw-r--r--load.bash1
-rw-r--r--src/assert_not_equal.bash42
-rw-r--r--test/assert_not_equal.bats56
4 files changed, 122 insertions, 0 deletions
diff --git a/README.md b/README.md
index 2adbfd9..831374c 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ This project provides the following functions:
- [assert](#assert) / [refute](#refute) Assert a given expression evaluates to `true` or `false`.
- [assert_equal](#assert_equal) Assert two parameters are equal.
+ - [assert_not_equal](#assert_not_equal) Assert two parameters are not equal.
- [assert_success](#assert_success) / [assert_failure](#assert_failure) Assert exit status is `0` or `1`.
- [assert_output](#assert_output) / [refute_output](#refute_output) Assert output does (or does not) contain given content.
- [assert_line](#assert_line) / [refute_line](#refute_line) Assert a specific line of output does (or does not) contain given content.
@@ -127,6 +128,28 @@ actual : have
If either value is longer than one line both are displayed in *multi-line* format.
+### `assert_not_equal`
+
+Fail if the two parameters, actual and unexpected value respectively, are equal.
+
+```bash
+@test 'assert_not_equal()' {
+ assert_not_equal 'foobar' 'foobar'
+}
+```
+
+On failure, the expected and actual values are displayed.
+
+```
+-- values should not be equal --
+unexpected : foobar
+actual : foobar
+--
+```
+
+If either value is longer than one line both are displayed in *multi-line* format.
+
+
### `assert_success`
Fail if `$status` is not 0.
diff --git a/load.bash b/load.bash
index 38bffe0..1201df1 100644
--- a/load.bash
+++ b/load.bash
@@ -22,6 +22,7 @@
source "$(dirname "${BASH_SOURCE[0]}")/src/assert.bash"
source "$(dirname "${BASH_SOURCE[0]}")/src/refute.bash"
source "$(dirname "${BASH_SOURCE[0]}")/src/assert_equal.bash"
+source "$(dirname "${BASH_SOURCE[0]}")/src/assert_not_equal.bash"
source "$(dirname "${BASH_SOURCE[0]}")/src/assert_success.bash"
source "$(dirname "${BASH_SOURCE[0]}")/src/assert_failure.bash"
source "$(dirname "${BASH_SOURCE[0]}")/src/assert_output.bash"
diff --git a/src/assert_not_equal.bash b/src/assert_not_equal.bash
new file mode 100644
index 0000000..933bb71
--- /dev/null
+++ b/src/assert_not_equal.bash
@@ -0,0 +1,42 @@
+# assert_not_equal
+# ============
+#
+# Summary: Fail if the actual and unexpected values are equal.
+#
+# Usage: assert_not_equal <actual> <unexpected>
+#
+# Options:
+# <actual> The value being compared.
+# <unexpected> The value to compare against.
+#
+# ```bash
+# @test 'assert_not_equal()' {
+# assert_not_equal 'foo' 'foo'
+# }
+# ```
+#
+# IO:
+# STDERR - expected and actual values, on failure
+# Globals:
+# none
+# Returns:
+# 0 - if actual does not equal unexpected
+# 1 - otherwise
+#
+# On failure, the unexpected and actual values are displayed.
+#
+# ```
+# -- values should not be equal --
+# unexpected : foo
+# actual : foo
+# --
+# ```
+assert_not_equal() {
+ if [[ "$1" == "$2" ]]; then
+ batslib_print_kv_single_or_multi 10 \
+ 'unexpected' "$2" \
+ 'actual' "$1" \
+ | batslib_decorate 'values should not be equal' \
+ | fail
+ fi
+}
diff --git a/test/assert_not_equal.bats b/test/assert_not_equal.bats
new file mode 100644
index 0000000..28f0142
--- /dev/null
+++ b/test/assert_not_equal.bats
@@ -0,0 +1,56 @@
+#!/usr/bin/env bats
+
+load test_helper
+
+@test 'assert_not_equal() <actual> <unexpected>: returns 0 if <actual> does not equal <unexpected>' {
+ run assert_not_equal foo bar
+ assert_test_pass
+
+ run assert_not_equal "foo" "bar"
+ assert_test_pass
+
+ run assert_not_equal "foo" ""
+ assert_test_pass
+
+ run assert_not_equal "" "foo"
+}
+
+@test 'assert_not_equal() <actual> <unexpected>: returns 1 and displays details if <actual> equals <unexpected>' {
+ run assert_not_equal 'foobar' 'foobar'
+ assert_test_fail <<'ERR_MSG'
+
+-- values should not be equal --
+unexpected : foobar
+actual : foobar
+--
+ERR_MSG
+
+ run assert_not_equal 1 1
+ assert_test_fail <<'ERR_MSG'
+
+-- values should not be equal --
+unexpected : 1
+actual : 1
+--
+ERR_MSG
+}
+
+@test 'assert_not_equal() <actual> <unexpected>: displays details in multi-line format if <actual> and <unexpected> are longer than one line' {
+ run assert_not_equal $'foo\nbar' $'foo\nbar'
+ assert_test_fail <<'ERR_MSG'
+
+-- values should not be equal --
+unexpected (2 lines):
+ foo
+ bar
+actual (2 lines):
+ foo
+ bar
+--
+ERR_MSG
+}
+
+@test 'assert_not_equal() <actual> <unexpected>: performs literal matching' {
+ run assert_not_equal 'a' '*'
+ assert_test_pass
+} \ No newline at end of file