mirror of
https://github.com/deajan/obackup.git
synced 2024-11-15 12:13:41 +01:00
83 lines
2.6 KiB
Bash
Executable File
83 lines
2.6 KiB
Bash
Executable File
#! /bin/sh
|
|
# vim:et:ft=sh:sts=2:sw=2
|
|
#
|
|
# shUnit2 unit test for failure functions
|
|
#
|
|
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
|
|
# Released under the LGPL (GNU Lesser General Public License)
|
|
#
|
|
# Author: kate.ward@forestent.com (Kate Ward)
|
|
# https://github.com/kward/shunit2
|
|
#
|
|
# Disable source following.
|
|
# shellcheck disable=SC1090,SC1091
|
|
|
|
# These variables will be overridden by the test helpers.
|
|
stdoutF="${TMPDIR:-/tmp}/STDOUT"
|
|
stderrF="${TMPDIR:-/tmp}/STDERR"
|
|
|
|
# Load test helpers.
|
|
. ./shunit2_test_helpers
|
|
|
|
testFail() {
|
|
( 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}"
|
|
}
|
|
|
|
testFailNotEquals() {
|
|
( 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}"
|
|
}
|
|
|
|
testFailSame() {
|
|
( 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}"
|
|
}
|
|
|
|
oneTimeSetUp() {
|
|
th_oneTimeSetUp
|
|
|
|
MSG='This is a test message'
|
|
}
|
|
|
|
# Load and run shUnit2.
|
|
# shellcheck disable=SC2034
|
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
|
. "${TH_SHUNIT}"
|