3 # Copyright (C)2007-2012 Versabanq Innovations Inc. and contributors.
4 # Licensed under the GNU Library General Public License, version 2.
5 # See the included file named LICENSE for license information.
6 # You can get wvtest from: http://github.com/apenwarr/wvtest
8 # Include this file in your shell script by using:
13 # we don't quote $TEXT in case it contains newlines; newlines
14 # aren't allowed in test output. However, we set -f so that
15 # at least shell glob characters aren't processed.
22 if [ -n "$BASH_VERSION" ]; then
26 WVCALLER_FILE=${BASH_SOURCE[2]}
27 WVCALLER_LINE=${BASH_LINENO[1]}
33 WVCALLER_FILE="unknown"
42 TEXT=$(_wvtextclean "$2")
44 if [ "$CODE" -ne 0 ]; then
47 echo "! $WVCALLER_FILE:$WVCALLER_LINE $TEXT $OK" >&2
48 if [ "$CODE" -ne 0 ]; then
71 # Use WVPASSSH instead of WVPASS when the command includes pipe or
72 # output redirection. The whole command must be one argument - quote
79 if bash -o pipefail -c "$@"; then
95 _wvcheck 1 "NOT($TEXT)"
99 _wvcheck 0 "NOT($TEXT)"
115 _wvcheck $(_wvgetrv [ "$#" -eq 2 ]) "exactly 2 arguments"
116 echo "Comparing:" >&2
120 _wvcheck $(_wvgetrv [ "$1" = "$2" ]) "'$1' = '$2'"
127 _wvcheck $(_wvgetrv [ "$#" -eq 2 ]) "exactly 2 arguments"
128 echo "Comparing:" >&2
132 _wvcheck $(_wvgetrv [ "$1" != "$2" ]) "'$1' != '$2'"
140 _wvcheck $(_wvgetrv [ $RC -eq 0 ]) "return code($RC) == 0"
148 _wvcheck $(_wvgetrv [ $RC -ne 0 ]) "return code($RC) != 0"
156 echo "Testing \"$*\" in $WVCALLER_FILE:" >&2
158 local dir=test.$(echo $* | tr -s '[[:blank:]]' _ | tr "A-Z" "a-z")
165 export NOVABOOT_TEST=1
166 export NOVABOOT_CONFIG_DIR=/dev/null # Do not read config from /etc/novaboot.d
167 export XDG_CONFIG_HOME=/dev/null # Do not read user config from ~/.config/novaboot
169 PATH=$(dirname $PWD):$PATH # Find our version of novaboot first
171 function create_script ()
173 (echo "#!/usr/bin/env novaboot"; cat) > script
177 function create_dummy ()