diff options
| author | 2018-03-20 22:56:16 -0400 | |
|---|---|---|
| committer | 2018-03-20 22:56:16 -0400 | |
| commit | d929c8cbc09732337fb4805accbf3564e9cca0bb (patch) | |
| tree | 27f71b63f26cdf0ef957ce2d7390f5991561b839 /test/common | |
Import Upstream version 18upstream/18
Diffstat (limited to 'test/common')
| -rw-r--r-- | test/common | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/common b/test/common new file mode 100644 index 0000000..8773077 --- /dev/null +++ b/test/common @@ -0,0 +1,45 @@ +#!/bin/bash + +fail=0 +testcount=0 + +EXPECT_success() { + (( ++testcount )) + if ! "$@"; then + (( ++fail )) + printf 'expectation failed: did not succeed: %s\n' "$*" >&2 + fi +} + +EXPECT_failure() { + (( ++testcount )) + if "$@"; then + (( ++fail )) + printf 'expectation failed: did not fail: %s\n' "$*" >&2 + fi +} + +TEST_exit() { + local result + + trap -- EXIT + + (( fail == 0 )) && result=PASS || result=FAIL + + printf '%s: %s\n' "$result" "$1" + + exit $(( fail != 0 )) +} + +ASSERT_streq() { + if [[ $1 != "$2" ]]; then + printf 'assertion failed [line %d]: [[ %s = "%s" ]]\n' "$BASH_LINENO" "$1" "$2" >&2 + fi +} + +TEST_start() { + trap "TEST_exit '$1'" EXIT +} + +TEST_start "${0##*/test_}" + |
