2
0
mirror of https://github.com/deajan/osync synced 2024-11-07 15:20:26 +00:00
osync/dev/tests/shunit2/shunit2_failures_test.sh

83 lines
2.6 KiB
Bash
Raw Normal View History

2016-08-22 08:26:38 +00:00
#! /bin/sh
# vim:et:ft=sh:sts=2:sw=2
#
2018-07-02 21:25:49 +00:00
# shUnit2 unit test for failure functions
#
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
2016-08-22 08:26:38 +00:00
# Released under the LGPL (GNU Lesser General Public License)
#
# Author: kate.ward@forestent.com (Kate Ward)
2018-07-02 21:25:49 +00:00
# https://github.com/kward/shunit2
2016-08-22 08:26:38 +00:00
#
2018-07-02 21:25:49 +00:00
# Disable source following.
# shellcheck disable=SC1090,SC1091
2016-08-22 08:26:38 +00:00
2018-07-02 21:25:49 +00:00
# These variables will be overridden by the test helpers.
stdoutF="${TMPDIR:-/tmp}/STDOUT"
stderrF="${TMPDIR:-/tmp}/STDERR"
2016-08-22 08:26:38 +00:00
2018-07-02 21:25:49 +00:00
# Load test helpers.
. ./shunit2_test_helpers
2016-08-22 08:26:38 +00:00
2018-07-02 21:25:49 +00:00
testFail() {
2016-08-22 08:26:38 +00:00
( fail >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'fail' $? "${stdoutF}" "${stderrF}"
( fail "${MSG}" >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'fail with msg' $? "${stdoutF}" "${stderrF}"
( fail arg1 >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'too many arguments' $? "${stdoutF}" "${stderrF}"
}
2018-07-02 21:25:49 +00:00
testFailNotEquals() {
2016-08-22 08:26:38 +00:00
( failNotEquals 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
( failNotEquals "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}"
( failNotEquals 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}"
( failNotEquals '' '' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
( failNotEquals >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
( failNotEquals arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
}
2018-07-02 21:25:49 +00:00
testFailSame() {
2016-08-22 08:26:38 +00:00
( failSame 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
( failSame "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}"
( failSame 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}"
( failSame '' '' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
( failSame >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
( failSame arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
}
2018-07-02 21:25:49 +00:00
oneTimeSetUp() {
2016-08-22 08:26:38 +00:00
th_oneTimeSetUp
MSG='This is a test message'
}
2018-07-02 21:25:49 +00:00
# Load and run shUnit2.
# shellcheck disable=SC2034
2016-08-22 08:26:38 +00:00
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
2018-07-02 21:25:49 +00:00
. "${TH_SHUNIT}"