1
0
mirror of https://github.com/deajan/obackup.git synced 2024-11-15 12:13:41 +01:00
obackup/dev/tests/shunit2/shunit2_failures_test.sh

83 lines
2.6 KiB
Bash
Raw Normal View History

2016-08-18 14:19:52 +02:00
#! /bin/sh
# vim:et:ft=sh:sts=2:sw=2
#
2018-09-30 16:31:34 +02:00
# shUnit2 unit test for failure functions
#
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
2016-08-18 14:19:52 +02:00
# Released under the LGPL (GNU Lesser General Public License)
#
# Author: kate.ward@forestent.com (Kate Ward)
2018-09-30 16:31:34 +02:00
# https://github.com/kward/shunit2
2016-08-18 14:19:52 +02:00
#
2018-09-30 16:31:34 +02:00
# Disable source following.
# shellcheck disable=SC1090,SC1091
2016-08-18 14:19:52 +02:00
2018-09-30 16:31:34 +02:00
# These variables will be overridden by the test helpers.
stdoutF="${TMPDIR:-/tmp}/STDOUT"
stderrF="${TMPDIR:-/tmp}/STDERR"
2016-08-18 14:19:52 +02:00
2018-09-30 16:31:34 +02:00
# Load test helpers.
. ./shunit2_test_helpers
2016-08-18 14:19:52 +02:00
2018-09-30 16:31:34 +02:00
testFail() {
2016-08-18 14:19:52 +02: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-09-30 16:31:34 +02:00
testFailNotEquals() {
2016-08-18 14:19:52 +02: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-09-30 16:31:34 +02:00
testFailSame() {
2016-08-18 14:19:52 +02: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-09-30 16:31:34 +02:00
oneTimeSetUp() {
2016-08-18 14:19:52 +02:00
th_oneTimeSetUp
MSG='This is a test message'
}
2018-09-30 16:31:34 +02:00
# Load and run shUnit2.
# shellcheck disable=SC2034
2016-08-18 14:19:52 +02:00
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
2018-09-30 16:31:34 +02:00
. "${TH_SHUNIT}"