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:
authorZoltan Tombol <zoltan.tombol@gmail.com>2016-02-17 00:51:54 +0300
committerZoltan Tombol <zoltan.tombol@gmail.com>2016-02-17 00:51:54 +0300
commit435d510b7791e84a9ba85a084aea0e6daf8cccc0 (patch)
tree248bde0e1983564b0337a7173cba26b02444fa55
parent55b43ca63cddb671e099a4770b0530403c88fe84 (diff)
Remove status and output from the output of assert (Fix #6)
-rw-r--r--README.md15
-rw-r--r--src/assert.bash20
-rwxr-xr-xtest/50-assert-11-assert.bats25
3 files changed, 12 insertions, 48 deletions
diff --git a/README.md b/README.md
index c2ad3b3..3fff359 100644
--- a/README.md
+++ b/README.md
@@ -54,30 +54,24 @@ this test always fails
Fail if the given expression evaluates to false.
***Note:*** *The expression must be a simple command. [Compound
-commands](https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands),
-such as `[[`, can be used only when executed with `bash -c`.
+commands][bash-comp-cmd], such as `[[`, can be used only when executed
+with `bash -c`.
```bash
@test 'assert()' {
- run touch '/var/log/test.log'
+ touch '/var/log/test.log'
assert [ -e '/var/log/test.log' ]
}
```
-On failure, the failed expression, `$status` and `$output` are
-displayed.
+On failure, the failed expression is displayed.
```
-- assertion failed --
expression : [ -e /var/log/test.log ]
-status : 1
-output : touch: cannot touch ‘/var/log/test.log’: Permission denied
--
```
-If `$output` is longer than one line, it is displayed in *multi-line*
-format.
-
### `assert_equal`
@@ -641,3 +635,4 @@ exclusive. An error is displayed when used simultaneously.
[bats-core-output]: https://github.com/ztombol/bats-core#output-formatting
[bats-core]: https://github.com/ztombol/bats-core
[bats-docs]: https://github.com/ztombol/bats-docs
+[bash-comp-cmd]: https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands
diff --git a/src/assert.bash b/src/assert.bash
index b2d1d2c..7f87dc6 100644
--- a/src/assert.bash
+++ b/src/assert.bash
@@ -49,15 +49,13 @@ fail() {
return 1
}
-# Fail and display details if the expression evaluates to false. Details
-# include the expression, `$status' and `$output'.
+# Fail and display the expression if it evaluates to false.
#
# NOTE: The expression must be a simple command. Compound commands, such
# as `[[', can be used only when executed with `bash -c'.
#
# Globals:
-# status
-# output
+# none
# Arguments:
# $1 - expression
# Returns:
@@ -67,18 +65,8 @@ fail() {
# STDERR - details, on failure
assert() {
if ! "$@"; then
- { local -ar single=(
- 'expression' "$*"
- 'status' "$status"
- )
- local -ar may_be_multi=(
- 'output' "$output"
- )
- local -ir width="$( batslib_get_max_single_line_key_width \
- "${single[@]}" "${may_be_multi[@]}" )"
- batslib_print_kv_single "$width" "${single[@]}"
- batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
- } | batslib_decorate 'assertion failed' \
+ batslib_print_kv_single 10 'expression' "$*" \
+ | batslib_decorate 'assertion failed' \
| fail
fi
}
diff --git a/test/50-assert-11-assert.bats b/test/50-assert-11-assert.bats
index 5ada1c6..6b7606b 100755
--- a/test/50-assert-11-assert.bats
+++ b/test/50-assert-11-assert.bats
@@ -8,30 +8,11 @@ load test_helper
[ "${#lines[@]}" -eq 0 ]
}
-@test 'assert() <expression>: returns 1 and displays details if <expression> evaluates to FALSE' {
- run bash -c 'echo "a"
- false'
+@test 'assert() <expression>: returns 1 and displays <expression> if it evaluates to FALSE' {
run assert false
[ "$status" -eq 1 ]
- [ "${#lines[@]}" -eq 5 ]
+ [ "${#lines[@]}" -eq 3 ]
[ "${lines[0]}" == '-- assertion failed --' ]
[ "${lines[1]}" == 'expression : false' ]
- [ "${lines[2]}" == 'status : 1' ]
- [ "${lines[3]}" == 'output : a' ]
- [ "${lines[4]}" == '--' ]
-}
-
-@test "assert() <expression>: displays \`\$output' in multi-line format if it is longer than one line" {
- run bash -c 'printf "a 0\na 1"
- false'
- run assert false
- [ "$status" -eq 1 ]
- [ "${#lines[@]}" -eq 7 ]
- [ "${lines[0]}" == '-- assertion failed --' ]
- [ "${lines[1]}" == 'expression : false' ]
- [ "${lines[2]}" == 'status : 1' ]
- [ "${lines[3]}" == 'output (2 lines):' ]
- [ "${lines[4]}" == ' a 0' ]
- [ "${lines[5]}" == ' a 1' ]
- [ "${lines[6]}" == '--' ]
+ [ "${lines[2]}" == '--' ]
}