mirror of
https://github.com/deajan/obackup.git
synced 2024-12-25 06:53:41 +01:00
Added basic shunit2 tests
This commit is contained in:
parent
bda19b3822
commit
6cbb732d7c
@ -80,10 +80,10 @@ SQL_USER=root
|
|||||||
|
|
||||||
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exclude list.
|
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exclude list.
|
||||||
## Every found database will be backed up as separate backup task.
|
## Every found database will be backed up as separate backup task.
|
||||||
DATABASES_ALL=yes
|
DATABASES_ALL=no
|
||||||
DATABASES_ALL_EXCLUDE_LIST="test;mysql"
|
DATABASES_ALL_EXCLUDE_LIST="test;information_schema"
|
||||||
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
||||||
#DATABASES_LIST="somedatabase"
|
DATABASES_LIST="mysql"
|
||||||
|
|
||||||
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max exec time generates a warning and stops current backup task.
|
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max exec time generates a warning and stops current backup task.
|
||||||
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
|
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
|
||||||
@ -102,9 +102,9 @@ COMPRESSION_LEVEL=3
|
|||||||
## You can exclude directories from the avove backup task creation, ex: avoid backing up "/home/dir2" by adding it to RECURSIVE_EXCLUDE_LIST.
|
## You can exclude directories from the avove backup task creation, ex: avoid backing up "/home/dir2" by adding it to RECURSIVE_EXCLUDE_LIST.
|
||||||
|
|
||||||
## Directories backup list. List of semicolon separated directories that will be backed up.
|
## Directories backup list. List of semicolon separated directories that will be backed up.
|
||||||
DIRECTORY_LIST="/opt/testData"
|
DIRECTORY_LIST="/opt/obackup/testData"
|
||||||
RECURSIVE_DIRECTORY_LIST="/opt/testDataRecursive"
|
RECURSIVE_DIRECTORY_LIST="/opt/obackup/testDataRecursive"
|
||||||
RECURSIVE_EXCLUDE_LIST="/opt/testDataRecursive/Excluded"
|
RECURSIVE_EXCLUDE_LIST="/opt/obackup/testDataRecursive/Excluded"
|
||||||
|
|
||||||
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
|
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
|
||||||
RSYNC_PATTERN_FIRST=include
|
RSYNC_PATTERN_FIRST=include
|
||||||
|
@ -80,10 +80,10 @@ SQL_USER=root
|
|||||||
|
|
||||||
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exclude list.
|
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exclude list.
|
||||||
## Every found database will be backed up as separate backup task.
|
## Every found database will be backed up as separate backup task.
|
||||||
DATABASES_ALL=yes
|
DATABASES_ALL=no
|
||||||
DATABASES_ALL_EXCLUDE_LIST="test;mysql"
|
DATABASES_ALL_EXCLUDE_LIST="test"
|
||||||
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
||||||
#DATABASES_LIST="somedatabase"
|
DATABASES_LIST="mysql;information_schema"
|
||||||
|
|
||||||
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max exec time generates a warning and stops current backup task.
|
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max exec time generates a warning and stops current backup task.
|
||||||
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
|
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
|
||||||
@ -102,9 +102,9 @@ COMPRESSION_LEVEL=3
|
|||||||
## You can exclude directories from the avove backup task creation, ex: avoid backing up "/home/dir2" by adding it to RECURSIVE_EXCLUDE_LIST.
|
## You can exclude directories from the avove backup task creation, ex: avoid backing up "/home/dir2" by adding it to RECURSIVE_EXCLUDE_LIST.
|
||||||
|
|
||||||
## Directories backup list. List of semicolon separated directories that will be backed up.
|
## Directories backup list. List of semicolon separated directories that will be backed up.
|
||||||
DIRECTORY_LIST="/opt/testData"
|
DIRECTORY_LIST="/opt/obackup/testData"
|
||||||
RECURSIVE_DIRECTORY_LIST="/opt/testDataRecursive"
|
RECURSIVE_DIRECTORY_LIST="/opt/obackup/testDataRecursive"
|
||||||
RECURSIVE_EXCLUDE_LIST="/opt/testDataRecursive/Excluded"
|
RECURSIVE_EXCLUDE_LIST="/opt/obackup/testDataRecursive/Excluded"
|
||||||
|
|
||||||
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
|
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
|
||||||
RSYNC_PATTERN_FIRST=include
|
RSYNC_PATTERN_FIRST=include
|
||||||
|
@ -80,10 +80,10 @@ SQL_USER=root
|
|||||||
|
|
||||||
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exclude list.
|
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exclude list.
|
||||||
## Every found database will be backed up as separate backup task.
|
## Every found database will be backed up as separate backup task.
|
||||||
DATABASES_ALL=yes
|
DATABASES_ALL=no
|
||||||
DATABASES_ALL_EXCLUDE_LIST="test;mysql"
|
DATABASES_ALL_EXCLUDE_LIST="test"
|
||||||
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
||||||
#DATABASES_LIST="somedatabase"
|
DATABASES_LIST="mysql;information_schema"
|
||||||
|
|
||||||
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max exec time generates a warning and stops current backup task.
|
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max exec time generates a warning and stops current backup task.
|
||||||
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
|
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
|
||||||
@ -102,9 +102,9 @@ COMPRESSION_LEVEL=3
|
|||||||
## You can exclude directories from the avove backup task creation, ex: avoid backing up "/home/dir2" by adding it to RECURSIVE_EXCLUDE_LIST.
|
## You can exclude directories from the avove backup task creation, ex: avoid backing up "/home/dir2" by adding it to RECURSIVE_EXCLUDE_LIST.
|
||||||
|
|
||||||
## Directories backup list. List of semicolon separated directories that will be backed up.
|
## Directories backup list. List of semicolon separated directories that will be backed up.
|
||||||
DIRECTORY_LIST="/opt/testData"
|
DIRECTORY_LIST="/opt/obackup/testData"
|
||||||
RECURSIVE_DIRECTORY_LIST="/opt/testDataRecursive"
|
RECURSIVE_DIRECTORY_LIST="/opt/obackup/testDataRecursive"
|
||||||
RECURSIVE_EXCLUDE_LIST="/opt/testDataRecursive/Excluded"
|
RECURSIVE_EXCLUDE_LIST="/opt/obackup/testDataRecursive/Excluded"
|
||||||
|
|
||||||
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
|
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
|
||||||
RSYNC_PATTERN_FIRST=include
|
RSYNC_PATTERN_FIRST=include
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
NON_RECURSIVE_DIR="/opt/testData"
|
|
||||||
RECURSIVE_DIR="/opt/testDataRecursive"
|
|
||||||
|
|
||||||
mkdir -p $SIMPLE_LIST
|
|
||||||
mkdir -p $RECURSIVE_LIST/Excluded
|
|
||||||
mkdir -p $RECURSIVE_LIST/a
|
|
||||||
mkdir -p $RECURSIVE_LIST/b
|
|
||||||
mkdir -p "$RECURSIVE_LIST/c d"
|
|
||||||
mkdir -p "$RECURSIVE_LIST/e
|
|
||||||
|
|
||||||
touch $SIMPLE_LIST/file_1
|
|
||||||
touch $RECURSIVE_LIST/file_2
|
|
||||||
touch $RECURSIVE_LIST/Excluded/file_3
|
|
||||||
touch $RECURSIVE_LIST/a/file_4
|
|
||||||
touch $RECURSIVE_LIST/b/file_5
|
|
||||||
touch "$RECURSIVE_LIST/c d/file_6"
|
|
||||||
touch $RECURSIVE_LIST/e/file_7
|
|
||||||
|
|
151
dev/tests/run_tests.sh
Executable file
151
dev/tests/run_tests.sh
Executable file
@ -0,0 +1,151 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Stupid and very basic tests v0.0000001-alpha-dev-pre-everything
|
||||||
|
|
||||||
|
DEV_DIR="/home/git/obackup/dev"
|
||||||
|
|
||||||
|
SOURCE_DIR="/opt/obackup"
|
||||||
|
TARGET_DIR="/home/storage/backup"
|
||||||
|
|
||||||
|
TARGET_DIR_SQL_LOCAL="/home/storage/backup/sql"
|
||||||
|
TARGET_DIR_FILE_LOCAL="/home/storage/backup/files"
|
||||||
|
|
||||||
|
TARGET_DIR_SQL_PULL="/home/storage/backup/sql-pull"
|
||||||
|
TARGET_DIR_FILE_PULL="/home/storage/backup/files-pull"
|
||||||
|
|
||||||
|
TARGET_DIR_SQL_PUSH="/home/storage/backup/sql-push"
|
||||||
|
TARGET_DIR_FILE_PUSH="/home/storage/backup/files-push"
|
||||||
|
|
||||||
|
|
||||||
|
SIMPLE_DIR="/testData"
|
||||||
|
RECURSIVE_DIR="/testDataRecursive"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function oneTimeSetUp () {
|
||||||
|
source "$DEV_DIR/ofunctions.sh"
|
||||||
|
|
||||||
|
sed -i 's/^IS_STABLE=no/IS_STABLE=yes/' "$DEV_DIR/n_obackup.sh"
|
||||||
|
|
||||||
|
mkdir -p $SOURCE_DIR$SIMPLE_DIR
|
||||||
|
mkdir -p $SOURCE_DIR$RECURSIVE_DIR/Excluded
|
||||||
|
mkdir -p $SOURCE_DIR$RECURSIVE_DIR/a
|
||||||
|
mkdir -p $SOURCE_DIR$RECURSIVE_DIR/b
|
||||||
|
mkdir -p "$SOURCE_DIR$RECURSIVE_DIR/c d"
|
||||||
|
mkdir -p $SOURCE_DIR$RECURSIVE_DIR/e
|
||||||
|
|
||||||
|
touch $SOURCE_DIR$SIMPLE_DIR/file_1
|
||||||
|
touch $SOURCE_DIR$RECURSIVE_DIR/file_2
|
||||||
|
touch $SOURCE_DIR$RECURSIVE_DIR/Excluded/file_3
|
||||||
|
touch $SOURCE_DIR$RECURSIVE_DIR/a/file_4
|
||||||
|
touch $SOURCE_DIR$RECURSIVE_DIR/b/file_5
|
||||||
|
touch "$SOURCE_DIR$RECURSIVE_DIR/c d/file_6"
|
||||||
|
touch $SOURCE_DIR$RECURSIVE_DIR/e/file_7
|
||||||
|
|
||||||
|
# Big file
|
||||||
|
dd if=/dev/urandom of=$SOURCE_DIR$RECURSIVE_DIR/e/file_8 bs=1M count=2
|
||||||
|
}
|
||||||
|
|
||||||
|
function oneTimeTearDown () {
|
||||||
|
sed -i 's/^IS_STABLE=yes/IS_STABLE=no/' "$DEV_DIR/n_obackup.sh"
|
||||||
|
|
||||||
|
rm -rf $TARGET_DIR
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_FirstLocalRun () {
|
||||||
|
# Basic return code tests. Need to go deep into file presence testing
|
||||||
|
cd "$DEV_DIR"
|
||||||
|
./n_obackup.sh tests/conf/local.conf > /dev/null
|
||||||
|
assertEquals "Return code" "0" $?
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_SecondLocalRun () {
|
||||||
|
# Only tests presence of rotated files
|
||||||
|
cd "$DEV_DIR"
|
||||||
|
./n_obackup.sh tests/conf/local.conf > /dev/null
|
||||||
|
assertEquals "Return code" "0" $?
|
||||||
|
|
||||||
|
[ -f "$TARGET_DIR_SQL_LOCAL/mysql.sql.xz.obackup.1" ]
|
||||||
|
assertEquals "SQL rotated file" "0" $?
|
||||||
|
|
||||||
|
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR).obackup.1" ]
|
||||||
|
assertEquals "Files rotated file" "0" $?
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_FirstPullRun () {
|
||||||
|
# Basic return code tests. Need to go deep into file presence testing
|
||||||
|
cd "$DEV_DIR"
|
||||||
|
./n_obackup.sh tests/conf/pull.conf > /dev/null
|
||||||
|
assertEquals "Return code" "0" $?
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_SecondPullRun () {
|
||||||
|
# Only tests presence of rotated files
|
||||||
|
cd "$DEV_DIR"
|
||||||
|
./n_obackup.sh tests/conf/pull.conf > /dev/null
|
||||||
|
assertEquals "Return code" "0" $?
|
||||||
|
|
||||||
|
[ -f "$TARGET_DIR_SQL_PULL/mysql.sql.xz.obackup.1" ]
|
||||||
|
assertEquals "SQL rotated file" "0" $?
|
||||||
|
|
||||||
|
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR).obackup.1" ]
|
||||||
|
assertEquals "Files rotated file" "0" $?
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_FirstPushRun () {
|
||||||
|
# Basic return code tests. Need to go deep into file presence testing
|
||||||
|
cd "$DEV_DIR"
|
||||||
|
./n_obackup.sh tests/conf/push.conf > /dev/null
|
||||||
|
assertEquals "Return code" "0" $?
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_SecondPushRun () {
|
||||||
|
# Only tests presence of rotated files
|
||||||
|
cd "$DEV_DIR"
|
||||||
|
./n_obackup.sh tests/conf/push.conf > /dev/null
|
||||||
|
assertEquals "Return code" "0" $?
|
||||||
|
|
||||||
|
[ -f "$TARGET_DIR_SQL_PUSH/mysql.sql.xz.obackup.1" ]
|
||||||
|
assertEquals "SQL rotated file" "0" $?
|
||||||
|
|
||||||
|
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR).obackup.1" ]
|
||||||
|
assertEquals "Files rotated file" "0" $?
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_WaitForTaskCompletion () {
|
||||||
|
# Tests if wait for task completion works correctly
|
||||||
|
|
||||||
|
sleep 20 &
|
||||||
|
pids="$!"
|
||||||
|
sleep 25 &
|
||||||
|
pids="$pids;$!"
|
||||||
|
|
||||||
|
WaitForTaskCompletion $pids 0 0 ${FUNCNAME[0]} false true 0
|
||||||
|
assertEquals "WaitForTaskCompletion test 1" "0" $?
|
||||||
|
|
||||||
|
sleep 20 &
|
||||||
|
pids="$!"
|
||||||
|
sleep 25 &
|
||||||
|
pids="$pids;$!"
|
||||||
|
|
||||||
|
WaitForTaskCompletion $pids 10 0 ${FUNCNAME[0]} false true 0
|
||||||
|
assertEquals "WaitForTaskCompletion test 2" "0" $?
|
||||||
|
|
||||||
|
sleep 20 &
|
||||||
|
pids="$!"
|
||||||
|
sleep 25 &
|
||||||
|
pids="$pids;$!"
|
||||||
|
|
||||||
|
WaitForTaskCompletion $pids 0 10 ${FUNCNAME[0]} false true 0
|
||||||
|
assertEquals "WaitForTaskCompletion test 3" "2" $?
|
||||||
|
|
||||||
|
sleep 20 &
|
||||||
|
pids="$!"
|
||||||
|
sleep 25 &
|
||||||
|
pids="$pids;$!"
|
||||||
|
|
||||||
|
WaitForTaskCompletion $pids 0 22 ${FUNCNAME[0]} false true 0
|
||||||
|
assertEquals "WaitForTaskCompletion test 4" "1" $?
|
||||||
|
}
|
||||||
|
|
||||||
|
. ./shunit2/shunit2
|
1067
dev/tests/shunit2/shunit2
Executable file
1067
dev/tests/shunit2/shunit2
Executable file
File diff suppressed because it is too large
Load Diff
124
dev/tests/shunit2/shunit2_test.sh
Executable file
124
dev/tests/shunit2/shunit2_test.sh
Executable file
@ -0,0 +1,124 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# $Id$
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# Copyright 2008 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the LGPL (GNU Lesser General Public License)
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
#
|
||||||
|
# shUnit2 unit test suite runner.
|
||||||
|
#
|
||||||
|
# This script runs all the unit tests that can be found, and generates a nice
|
||||||
|
# report of the tests.
|
||||||
|
|
||||||
|
MY_NAME=`basename $0`
|
||||||
|
MY_PATH=`dirname $0`
|
||||||
|
|
||||||
|
PREFIX='shunit2_test_'
|
||||||
|
SHELLS='/bin/sh /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh'
|
||||||
|
TESTS=''
|
||||||
|
for test in ${PREFIX}[a-z]*.sh; do
|
||||||
|
TESTS="${TESTS} ${test}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# load common unit test functions
|
||||||
|
. ../lib/versions
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
echo "usage: ${MY_NAME} [-e key=val ...] [-s shell(s)] [-t test(s)]"
|
||||||
|
}
|
||||||
|
|
||||||
|
env=''
|
||||||
|
|
||||||
|
# process command line flags
|
||||||
|
while getopts 'e:hs:t:' opt; do
|
||||||
|
case ${opt} in
|
||||||
|
e) # set an environment variable
|
||||||
|
key=`expr "${OPTARG}" : '\([^=]*\)='`
|
||||||
|
val=`expr "${OPTARG}" : '[^=]*=\(.*\)'`
|
||||||
|
if [ -z "${key}" -o -z "${val}" ]; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
eval "${key}='${val}'"
|
||||||
|
export ${key}
|
||||||
|
env="${env:+${env} }${key}"
|
||||||
|
;;
|
||||||
|
h) usage; exit 0 ;; # output help
|
||||||
|
s) shells=${OPTARG} ;; # list of shells to run
|
||||||
|
t) tests=${OPTARG} ;; # list of tests to run
|
||||||
|
*) usage; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift `expr ${OPTIND} - 1`
|
||||||
|
|
||||||
|
# fill shells and/or tests
|
||||||
|
shells=${shells:-${SHELLS}}
|
||||||
|
tests=${tests:-${TESTS}}
|
||||||
|
|
||||||
|
# error checking
|
||||||
|
if [ -z "${tests}" ]; then
|
||||||
|
th_error 'no tests found to run; exiting'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# System data
|
||||||
|
#
|
||||||
|
|
||||||
|
# test run info
|
||||||
|
shells: ${shells}
|
||||||
|
tests: ${tests}
|
||||||
|
EOF
|
||||||
|
for key in ${env}; do
|
||||||
|
eval "echo \"${key}=\$${key}\""
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
|
||||||
|
# output system data
|
||||||
|
echo "# system info"
|
||||||
|
echo "$ date"
|
||||||
|
date
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "$ uname -mprsv"
|
||||||
|
uname -mprsv
|
||||||
|
|
||||||
|
#
|
||||||
|
# run tests
|
||||||
|
#
|
||||||
|
|
||||||
|
for shell in ${shells}; do
|
||||||
|
echo
|
||||||
|
|
||||||
|
# check for existance of shell
|
||||||
|
if [ ! -x ${shell} ]; then
|
||||||
|
th_warn "unable to run tests with the ${shell} shell"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# Running the test suite with ${shell}
|
||||||
|
#
|
||||||
|
EOF
|
||||||
|
|
||||||
|
SHUNIT_SHELL=${shell} # pass shell onto tests
|
||||||
|
shell_name=`basename ${shell}`
|
||||||
|
shell_version=`versions_shellVersion "${shell}"`
|
||||||
|
|
||||||
|
echo "shell name: ${shell_name}"
|
||||||
|
echo "shell version: ${shell_version}"
|
||||||
|
|
||||||
|
# execute the tests
|
||||||
|
for suite in ${tests}; do
|
||||||
|
suiteName=`expr "${suite}" : "${PREFIX}\(.*\).sh"`
|
||||||
|
echo
|
||||||
|
echo "--- Executing the '${suiteName}' test suite ---"
|
||||||
|
( exec ${shell} ./${suite} 2>&1; )
|
||||||
|
done
|
||||||
|
done
|
206
dev/tests/shunit2/shunit2_test_asserts.sh
Executable file
206
dev/tests/shunit2/shunit2_test_asserts.sh
Executable file
@ -0,0 +1,206 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# $Id$
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# Copyright 2008 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the LGPL (GNU Lesser General Public License)
|
||||||
|
#
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
#
|
||||||
|
# shUnit2 unit test for assert functions
|
||||||
|
|
||||||
|
# load test helpers
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# suite tests
|
||||||
|
#
|
||||||
|
|
||||||
|
commonEqualsSame()
|
||||||
|
{
|
||||||
|
fn=$1
|
||||||
|
|
||||||
|
( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'equal' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'equal; with msg' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} 'abc def' 'abc def' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'equal with spaces' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'not equal' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'null values' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
}
|
||||||
|
|
||||||
|
commonNotEqualsSame()
|
||||||
|
{
|
||||||
|
fn=$1
|
||||||
|
|
||||||
|
( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not same' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} "${MSG}" 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not same, with msg' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertEquals()
|
||||||
|
{
|
||||||
|
commonEqualsSame 'assertEquals'
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertNotEquals()
|
||||||
|
{
|
||||||
|
commonNotEqualsSame 'assertNotEquals'
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertSame()
|
||||||
|
{
|
||||||
|
commonEqualsSame 'assertSame'
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertNotSame()
|
||||||
|
{
|
||||||
|
commonNotEqualsSame 'assertNotSame'
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertNull()
|
||||||
|
{
|
||||||
|
( assertNull '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'null' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNull "${MSG}" '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'null, with msg' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNull 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'not null' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNull >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertNotNull()
|
||||||
|
{
|
||||||
|
( assertNotNull 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not null' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNotNull "${MSG}" 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not null, with msg' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNotNull 'x"b' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not null, with double-quote' $? \
|
||||||
|
"${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNotNull "x'b" >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not null, with single-quote' $? \
|
||||||
|
"${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNotNull 'x$b' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not null, with dollar' $? \
|
||||||
|
"${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNotNull 'x`b' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'not null, with backtick' $? \
|
||||||
|
"${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertNotNull '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
# there is no test for too few arguments as $1 might actually be null
|
||||||
|
|
||||||
|
( assertNotNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertTrue()
|
||||||
|
{
|
||||||
|
( assertTrue 0 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'true' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertTrue "${MSG}" 0 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'true, with msg' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertTrue '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'true condition' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertTrue 1 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'false' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertTrue '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'false condition' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertTrue '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertTrue >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertTrue arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertFalse()
|
||||||
|
{
|
||||||
|
( assertFalse 1 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'false' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertFalse "${MSG}" 1 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'false, with msg' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertFalse '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertTrueWithNoOutput 'false condition' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertFalse 0 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'true' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertFalse '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertFalse '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertFalse >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
|
||||||
|
( assertFalse arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# suite functions
|
||||||
|
#
|
||||||
|
|
||||||
|
oneTimeSetUp()
|
||||||
|
{
|
||||||
|
th_oneTimeSetUp
|
||||||
|
|
||||||
|
MSG='This is a test message'
|
||||||
|
}
|
||||||
|
|
||||||
|
# load and run shUnit2
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
||||||
|
. ${TH_SHUNIT}
|
86
dev/tests/shunit2/shunit2_test_failures.sh
Executable file
86
dev/tests/shunit2/shunit2_test_failures.sh
Executable file
@ -0,0 +1,86 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# $Id$
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# Copyright 2008 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the LGPL (GNU Lesser General Public License)
|
||||||
|
#
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
#
|
||||||
|
# shUnit2 unit test for failure functions
|
||||||
|
|
||||||
|
# load common unit-test functions
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# suite tests
|
||||||
|
#
|
||||||
|
|
||||||
|
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}"
|
||||||
|
}
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# suite functions
|
||||||
|
#
|
||||||
|
|
||||||
|
oneTimeSetUp()
|
||||||
|
{
|
||||||
|
th_oneTimeSetUp
|
||||||
|
|
||||||
|
MSG='This is a test message'
|
||||||
|
}
|
||||||
|
|
||||||
|
# load and run shUnit2
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
||||||
|
. ${TH_SHUNIT}
|
229
dev/tests/shunit2/shunit2_test_helpers
Normal file
229
dev/tests/shunit2/shunit2_test_helpers
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
# $Id$
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# Copyright 2008 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the LGPL (GNU Lesser General Public License)
|
||||||
|
#
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
#
|
||||||
|
# shUnit2 unit test common functions
|
||||||
|
|
||||||
|
# treat unset variables as an error when performing parameter expansion
|
||||||
|
set -u
|
||||||
|
|
||||||
|
# set shwordsplit for zsh
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit
|
||||||
|
|
||||||
|
#
|
||||||
|
# constants
|
||||||
|
#
|
||||||
|
|
||||||
|
# path to shUnit2 library. can be overridden by setting SHUNIT_INC
|
||||||
|
TH_SHUNIT=${SHUNIT_INC:-./shunit2}
|
||||||
|
|
||||||
|
# configure debugging. set the DEBUG environment variable to any
|
||||||
|
# non-empty value to enable debug output, or TRACE to enable trace
|
||||||
|
# output.
|
||||||
|
TRACE=${TRACE:+'th_trace '}
|
||||||
|
[ -n "${TRACE}" ] && DEBUG=1
|
||||||
|
[ -z "${TRACE}" ] && TRACE=':'
|
||||||
|
|
||||||
|
DEBUG=${DEBUG:+'th_debug '}
|
||||||
|
[ -z "${DEBUG}" ] && DEBUG=':'
|
||||||
|
|
||||||
|
#
|
||||||
|
# variables
|
||||||
|
#
|
||||||
|
|
||||||
|
th_RANDOM=0
|
||||||
|
|
||||||
|
#
|
||||||
|
# functions
|
||||||
|
#
|
||||||
|
|
||||||
|
# message functions
|
||||||
|
th_trace() { echo "${MY_NAME}:TRACE $@" >&2; }
|
||||||
|
th_debug() { echo "${MY_NAME}:DEBUG $@" >&2; }
|
||||||
|
th_info() { echo "${MY_NAME}:INFO $@" >&2; }
|
||||||
|
th_warn() { echo "${MY_NAME}:WARN $@" >&2; }
|
||||||
|
th_error() { echo "${MY_NAME}:ERROR $@" >&2; }
|
||||||
|
th_fatal() { echo "${MY_NAME}:FATAL $@" >&2; }
|
||||||
|
|
||||||
|
# output subtest name
|
||||||
|
th_subtest() { echo " $@" >&2; }
|
||||||
|
|
||||||
|
th_oneTimeSetUp()
|
||||||
|
{
|
||||||
|
# these files will be cleaned up automatically by shUnit2
|
||||||
|
stdoutF="${SHUNIT_TMPDIR}/stdout"
|
||||||
|
stderrF="${SHUNIT_TMPDIR}/stderr"
|
||||||
|
returnF="${SHUNIT_TMPDIR}/return"
|
||||||
|
expectedF="${SHUNIT_TMPDIR}/expected"
|
||||||
|
}
|
||||||
|
|
||||||
|
# generate a random number
|
||||||
|
th_generateRandom()
|
||||||
|
{
|
||||||
|
tfgr_random=${th_RANDOM}
|
||||||
|
|
||||||
|
while [ "${tfgr_random}" = "${th_RANDOM}" ]; do
|
||||||
|
if [ -n "${RANDOM:-}" ]; then
|
||||||
|
# $RANDOM works
|
||||||
|
tfgr_random=${RANDOM}${RANDOM}${RANDOM}$$
|
||||||
|
elif [ -r '/dev/urandom' ]; then
|
||||||
|
tfgr_random=`od -vAn -N4 -tu4 </dev/urandom |sed 's/^[^0-9]*//'`
|
||||||
|
else
|
||||||
|
tfgr_date=`date '+%H%M%S'`
|
||||||
|
tfgr_random=`expr ${tfgr_date} \* $$`
|
||||||
|
unset tfgr_date
|
||||||
|
fi
|
||||||
|
[ "${tfgr_random}" = "${th_RANDOM}" ] && sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
th_RANDOM=${tfgr_random}
|
||||||
|
unset tfgr_random
|
||||||
|
}
|
||||||
|
|
||||||
|
# this section returns the data section from the specified section of a file. a
|
||||||
|
# datasection is defined by a [header], one or more lines of data, and then a
|
||||||
|
# blank line.
|
||||||
|
th_getDataSect()
|
||||||
|
{
|
||||||
|
th_sgrep "\\[$1\\]" "$2" |sed '1d'
|
||||||
|
}
|
||||||
|
|
||||||
|
# this function greps a section from a file. a section is defined as a group of
|
||||||
|
# lines preceeded and followed by blank lines.
|
||||||
|
th_sgrep()
|
||||||
|
{
|
||||||
|
th_pattern_=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
sed -e '/./{H;$!d;}' -e "x;/${th_pattern_}/"'!d;' $@ |sed '1d'
|
||||||
|
|
||||||
|
unset th_pattern_
|
||||||
|
}
|
||||||
|
|
||||||
|
# Custom assert that checks for true return value (0), and no output to STDOUT
|
||||||
|
# or STDERR. If a non-zero return value is encountered, the output of STDERR
|
||||||
|
# will be output.
|
||||||
|
#
|
||||||
|
# Args:
|
||||||
|
# th_test_: string: name of the subtest
|
||||||
|
# th_rtrn_: integer: the return value of the subtest performed
|
||||||
|
# th_stdout_: string: filename where stdout was redirected to
|
||||||
|
# th_stderr_: string: filename where stderr was redirected to
|
||||||
|
th_assertTrueWithNoOutput()
|
||||||
|
{
|
||||||
|
th_test_=$1
|
||||||
|
th_rtrn_=$2
|
||||||
|
th_stdout_=$3
|
||||||
|
th_stderr_=$4
|
||||||
|
|
||||||
|
assertTrue "${th_test_}; expected return value of zero" ${th_rtrn_}
|
||||||
|
[ ${th_rtrn_} -ne ${SHUNIT_TRUE} ] && cat "${th_stderr_}"
|
||||||
|
assertFalse "${th_test_}; expected no output to STDOUT" \
|
||||||
|
"[ -s '${th_stdout_}' ]"
|
||||||
|
assertFalse "${th_test_}; expected no output to STDERR" \
|
||||||
|
"[ -s '${th_stderr_}' ]"
|
||||||
|
|
||||||
|
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
||||||
|
}
|
||||||
|
|
||||||
|
# Custom assert that checks for non-zero return value, output to STDOUT, but no
|
||||||
|
# output to STDERR.
|
||||||
|
#
|
||||||
|
# Args:
|
||||||
|
# th_test_: string: name of the subtest
|
||||||
|
# th_rtrn_: integer: the return value of the subtest performed
|
||||||
|
# th_stdout_: string: filename where stdout was redirected to
|
||||||
|
# th_stderr_: string: filename where stderr was redirected to
|
||||||
|
th_assertFalseWithOutput()
|
||||||
|
{
|
||||||
|
th_test_=$1
|
||||||
|
th_rtrn_=$2
|
||||||
|
th_stdout_=$3
|
||||||
|
th_stderr_=$4
|
||||||
|
|
||||||
|
assertFalse "${th_test_}; expected non-zero return value" ${th_rtrn_}
|
||||||
|
assertTrue "${th_test_}; expected output to STDOUT" \
|
||||||
|
"[ -s '${th_stdout_}' ]"
|
||||||
|
assertFalse "${th_test_}; expected no output to STDERR" \
|
||||||
|
"[ -s '${th_stderr_}' ]"
|
||||||
|
[ -s "${th_stdout_}" -a ! -s "${th_stderr_}" ] || \
|
||||||
|
_th_showOutput ${SHUNIT_FALSE} "${th_stdout_}" "${th_stderr_}"
|
||||||
|
|
||||||
|
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
||||||
|
}
|
||||||
|
|
||||||
|
# Custom assert that checks for non-zero return value, no output to STDOUT, but
|
||||||
|
# output to STDERR.
|
||||||
|
#
|
||||||
|
# Args:
|
||||||
|
# th_test_: string: name of the subtest
|
||||||
|
# th_rtrn_: integer: the return value of the subtest performed
|
||||||
|
# th_stdout_: string: filename where stdout was redirected to
|
||||||
|
# th_stderr_: string: filename where stderr was redirected to
|
||||||
|
th_assertFalseWithError()
|
||||||
|
{
|
||||||
|
th_test_=$1
|
||||||
|
th_rtrn_=$2
|
||||||
|
th_stdout_=$3
|
||||||
|
th_stderr_=$4
|
||||||
|
|
||||||
|
assertFalse "${th_test_}; expected non-zero return value" ${th_rtrn_}
|
||||||
|
assertFalse "${th_test_}; expected no output to STDOUT" \
|
||||||
|
"[ -s '${th_stdout_}' ]"
|
||||||
|
assertTrue "${th_test_}; expected output to STDERR" \
|
||||||
|
"[ -s '${th_stderr_}' ]"
|
||||||
|
[ ! -s "${th_stdout_}" -a -s "${th_stderr_}" ] || \
|
||||||
|
_th_showOutput ${SHUNIT_FALSE} "${th_stdout_}" "${th_stderr_}"
|
||||||
|
|
||||||
|
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
||||||
|
}
|
||||||
|
|
||||||
|
# Some shells, zsh on Solaris in particular, return immediately from a sub-shell
|
||||||
|
# when a non-zero return value is encountered. To properly catch these values,
|
||||||
|
# they are either written to disk, or recognized as an error the file is empty.
|
||||||
|
th_clearReturn() { cp /dev/null "${returnF}"; }
|
||||||
|
th_queryReturn()
|
||||||
|
{
|
||||||
|
if [ -s "${returnF}" ]; then
|
||||||
|
th_return=`cat "${returnF}"`
|
||||||
|
else
|
||||||
|
th_return=${SHUNIT_ERROR}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Providing external and internal calls to the showOutput helper function.
|
||||||
|
th_showOutput() { _th_showOutput $@; }
|
||||||
|
_th_showOutput()
|
||||||
|
{
|
||||||
|
_th_return_=$1
|
||||||
|
_th_stdout_=$2
|
||||||
|
_th_stderr_=$3
|
||||||
|
|
||||||
|
isSkipping
|
||||||
|
if [ $? -eq ${SHUNIT_FALSE} -a ${_th_return_} != ${SHUNIT_TRUE} ]; then
|
||||||
|
if [ -n "${_th_stdout_}" -a -s "${_th_stdout_}" ]; then
|
||||||
|
echo '>>> STDOUT' >&2
|
||||||
|
cat "${_th_stdout_}" >&2
|
||||||
|
fi
|
||||||
|
if [ -n "${_th_stderr_}" -a -s "${_th_stderr_}" ]; then
|
||||||
|
echo '>>> STDERR' >&2
|
||||||
|
cat "${_th_stderr_}" >&2
|
||||||
|
fi
|
||||||
|
if [ -n "${_th_stdout_}" -o -n "${_th_stderr_}" ]; then
|
||||||
|
echo '<<< end output' >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset _th_return_ _th_stdout_ _th_stderr_
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# main
|
||||||
|
#
|
||||||
|
|
||||||
|
${TRACE} 'trace output enabled'
|
||||||
|
${DEBUG} 'debug output enabled'
|
246
dev/tests/shunit2/shunit2_test_macros.sh
Executable file
246
dev/tests/shunit2/shunit2_test_macros.sh
Executable file
@ -0,0 +1,246 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# $Id$
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# Copyright 2008 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the LGPL (GNU Lesser General Public License)
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
#
|
||||||
|
# shUnit2 unit test for macros.
|
||||||
|
|
||||||
|
# load test helpers
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# suite tests
|
||||||
|
#
|
||||||
|
|
||||||
|
testAssertEquals()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_EQUALS_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_ASSERT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_EQUALS_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertNotEquals()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_NOT_EQUALS_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NOT_EQUALS_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_ASSERT_NOT_EQUALS_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NOT_EQUALS_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testSame()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_SAME_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_ASSERT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_SAME_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testNotSame()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_NOT_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NOT_SAME_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_ASSERT_NOT_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NOT_SAME_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testNull()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_NULL_} 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NULL_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_ASSERT_NULL_} '"some msg"' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NULL_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testNotNull()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_NOT_NULL_} '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NOT_NULL_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_ASSERT_NOT_NULL_} '"some msg"' '""' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_NOT_NULL_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stdoutF}" "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertTrue()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_TRUE_} ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_TRUE_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
|
||||||
|
( ${_ASSERT_TRUE_} '"some msg"' ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_TRUE_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertFalse()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_ASSERT_FALSE_} ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_FALSE_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_ASSERT_FALSE_} '"some msg"' ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_ASSERT_FALSE_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testFail()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_FAIL_} >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_FAIL_} '"some msg"' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testFailNotEquals()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_FAIL_NOT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_NOT_EQUALS_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_FAIL_NOT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_NOT_EQUALS_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testFailSame()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_FAIL_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_SAME_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_FAIL_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_SAME_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testFailNotSame()
|
||||||
|
{
|
||||||
|
# start skipping if LINENO not available
|
||||||
|
[ -z "${LINENO:-}" ] && startSkipping
|
||||||
|
|
||||||
|
( ${_FAIL_NOT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_NOT_SAME_ failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
|
||||||
|
( ${_FAIL_NOT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue '_FAIL_NOT_SAME_ w/ msg failure' ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# suite functions
|
||||||
|
#
|
||||||
|
|
||||||
|
oneTimeSetUp()
|
||||||
|
{
|
||||||
|
th_oneTimeSetUp
|
||||||
|
}
|
||||||
|
|
||||||
|
# load and run shUnit2
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
||||||
|
. ${TH_SHUNIT}
|
160
dev/tests/shunit2/shunit2_test_misc.sh
Executable file
160
dev/tests/shunit2/shunit2_test_misc.sh
Executable file
@ -0,0 +1,160 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# $Id$
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# Copyright 2008 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the LGPL (GNU Lesser General Public License)
|
||||||
|
#
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
#
|
||||||
|
# shUnit2 unit tests of miscellaneous things
|
||||||
|
|
||||||
|
# load test helpers
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# suite tests
|
||||||
|
#
|
||||||
|
|
||||||
|
# Note: the test script is prefixed with '#' chars so that shUnit2 does not
|
||||||
|
# incorrectly interpret the embedded functions as real functions.
|
||||||
|
testUnboundVariable()
|
||||||
|
{
|
||||||
|
unittestF="${SHUNIT_TMPDIR}/unittest"
|
||||||
|
sed 's/^#//' >"${unittestF}" <<EOF
|
||||||
|
## treat unset variables as an error when performing parameter expansion
|
||||||
|
#set -u
|
||||||
|
#
|
||||||
|
#boom() { x=\$1; } # this function goes boom if no parameters are passed!
|
||||||
|
#test_boom()
|
||||||
|
#{
|
||||||
|
# assertEquals 1 1
|
||||||
|
# boom # No parameter given
|
||||||
|
# assertEquals 0 \$?
|
||||||
|
#}
|
||||||
|
#. ${TH_SHUNIT}
|
||||||
|
EOF
|
||||||
|
( exec ${SHUNIT_SHELL:-sh} "${unittestF}" >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
assertFalse 'expected a non-zero exit value' $?
|
||||||
|
grep '^ASSERT:Unknown failure' "${stdoutF}" >/dev/null
|
||||||
|
assertTrue 'assert message was not generated' $?
|
||||||
|
grep '^Ran [0-9]* test' "${stdoutF}" >/dev/null
|
||||||
|
assertTrue 'test count message was not generated' $?
|
||||||
|
grep '^FAILED' "${stdoutF}" >/dev/null
|
||||||
|
assertTrue 'failure message was not generated' $?
|
||||||
|
}
|
||||||
|
|
||||||
|
testIssue7()
|
||||||
|
{
|
||||||
|
( assertEquals 'Some message.' 1 2 >"${stdoutF}" 2>"${stderrF}" )
|
||||||
|
diff "${stdoutF}" - >/dev/null <<EOF
|
||||||
|
ASSERT:Some message. expected:<1> but was:<2>
|
||||||
|
EOF
|
||||||
|
rtrn=$?
|
||||||
|
assertEquals ${SHUNIT_TRUE} ${rtrn}
|
||||||
|
[ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
testPrepForSourcing()
|
||||||
|
{
|
||||||
|
assertEquals '/abc' `_shunit_prepForSourcing '/abc'`
|
||||||
|
assertEquals './abc' `_shunit_prepForSourcing './abc'`
|
||||||
|
assertEquals './abc' `_shunit_prepForSourcing 'abc'`
|
||||||
|
}
|
||||||
|
|
||||||
|
testEscapeCharInStr()
|
||||||
|
{
|
||||||
|
actual=`_shunit_escapeCharInStr '\' ''`
|
||||||
|
assertEquals '' "${actual}"
|
||||||
|
assertEquals 'abc\\' `_shunit_escapeCharInStr '\' 'abc\'`
|
||||||
|
assertEquals 'abc\\def' `_shunit_escapeCharInStr '\' 'abc\def'`
|
||||||
|
assertEquals '\\def' `_shunit_escapeCharInStr '\' '\def'`
|
||||||
|
|
||||||
|
actual=`_shunit_escapeCharInStr '"' ''`
|
||||||
|
assertEquals '' "${actual}"
|
||||||
|
assertEquals 'abc\"' `_shunit_escapeCharInStr '"' 'abc"'`
|
||||||
|
assertEquals 'abc\"def' `_shunit_escapeCharInStr '"' 'abc"def'`
|
||||||
|
assertEquals '\"def' `_shunit_escapeCharInStr '"' '"def'`
|
||||||
|
|
||||||
|
actual=`_shunit_escapeCharInStr '$' ''`
|
||||||
|
assertEquals '' "${actual}"
|
||||||
|
assertEquals 'abc\$' `_shunit_escapeCharInStr '$' 'abc$'`
|
||||||
|
assertEquals 'abc\$def' `_shunit_escapeCharInStr '$' 'abc$def'`
|
||||||
|
assertEquals '\$def' `_shunit_escapeCharInStr '$' '$def'`
|
||||||
|
|
||||||
|
# actual=`_shunit_escapeCharInStr "'" ''`
|
||||||
|
# assertEquals '' "${actual}"
|
||||||
|
# assertEquals "abc\\'" `_shunit_escapeCharInStr "'" "abc'"`
|
||||||
|
# assertEquals "abc\\'def" `_shunit_escapeCharInStr "'" "abc'def"`
|
||||||
|
# assertEquals "\\'def" `_shunit_escapeCharInStr "'" "'def"`
|
||||||
|
|
||||||
|
# # must put the backtick in a variable so the shell doesn't misinterpret it
|
||||||
|
# # while inside a backticked sequence (e.g. `echo '`'` would fail).
|
||||||
|
# backtick='`'
|
||||||
|
# actual=`_shunit_escapeCharInStr ${backtick} ''`
|
||||||
|
# assertEquals '' "${actual}"
|
||||||
|
# assertEquals '\`abc' \
|
||||||
|
# `_shunit_escapeCharInStr "${backtick}" ${backtick}'abc'`
|
||||||
|
# assertEquals 'abc\`' \
|
||||||
|
# `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}`
|
||||||
|
# assertEquals 'abc\`def' \
|
||||||
|
# `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}'def'`
|
||||||
|
}
|
||||||
|
|
||||||
|
testEscapeCharInStr_specialChars()
|
||||||
|
{
|
||||||
|
# make sure our forward slash doesn't upset sed
|
||||||
|
assertEquals '/' `_shunit_escapeCharInStr '\' '/'`
|
||||||
|
|
||||||
|
# some shells escape these differently
|
||||||
|
#assertEquals '\\a' `_shunit_escapeCharInStr '\' '\a'`
|
||||||
|
#assertEquals '\\b' `_shunit_escapeCharInStr '\' '\b'`
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test the various ways of declaring functions.
|
||||||
|
#
|
||||||
|
# Prefixing (then stripping) with comment symbol so these functions aren't
|
||||||
|
# treated as real functions by shUnit2.
|
||||||
|
testExtractTestFunctions()
|
||||||
|
{
|
||||||
|
f="${SHUNIT_TMPDIR}/extract_test_functions"
|
||||||
|
sed 's/^#//' <<EOF >"${f}"
|
||||||
|
#testABC() { echo 'ABC'; }
|
||||||
|
#test_def() {
|
||||||
|
# echo 'def'
|
||||||
|
#}
|
||||||
|
#testG3 ()
|
||||||
|
#{
|
||||||
|
# echo 'G3'
|
||||||
|
#}
|
||||||
|
#function test4() { echo '4'; }
|
||||||
|
# test5() { echo '5'; }
|
||||||
|
#some_test_function() { echo 'some func'; }
|
||||||
|
#func_with_test_vars() {
|
||||||
|
# testVariable=1234
|
||||||
|
#}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
actual=`_shunit_extractTestFunctions "${f}"`
|
||||||
|
assertEquals 'testABC test_def testG3 test4 test5' "${actual}"
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# suite functions
|
||||||
|
#
|
||||||
|
|
||||||
|
setUp()
|
||||||
|
{
|
||||||
|
for f in ${expectedF} ${stdoutF} ${stderrF}; do
|
||||||
|
cp /dev/null ${f}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeSetUp()
|
||||||
|
{
|
||||||
|
th_oneTimeSetUp
|
||||||
|
}
|
||||||
|
|
||||||
|
# load and run shUnit2
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
||||||
|
. ${TH_SHUNIT}
|
41
dev/tests/shunit2/shunit2_test_standalone.sh
Executable file
41
dev/tests/shunit2/shunit2_test_standalone.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# $Id$
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# Copyright 2010 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the LGPL (GNU Lesser General Public License)
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
#
|
||||||
|
# shUnit2 unit test for standalone operation.
|
||||||
|
#
|
||||||
|
# This unit test is purely to test that calling shunit2 directly, while passing
|
||||||
|
# the name of a unit test script, works. When run, this script determines if it
|
||||||
|
# is running as a standalone program, and calls main() if it is.
|
||||||
|
|
||||||
|
ARGV0=`basename "$0"`
|
||||||
|
|
||||||
|
# load test helpers
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# suite tests
|
||||||
|
#
|
||||||
|
|
||||||
|
testStandalone()
|
||||||
|
{
|
||||||
|
assertTrue ${SHUNIT_TRUE}
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# main
|
||||||
|
#
|
||||||
|
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
${TH_SHUNIT} "${ARGV0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# are we running as a standalone?
|
||||||
|
if [ "${ARGV0}" = 'shunit2_test_standalone.sh' ]; then
|
||||||
|
if [ $# -gt 0 ]; then main "$@"; else main; fi
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user