Fixes for QA

This commit is contained in:
DarkFeather 2017-01-05 14:10:57 -06:00
parent cbea946586
commit 0c359bd4ec

View File

@ -90,27 +90,30 @@ function decrementdate() {
## QA Functions ## ## QA Functions ##
# This is for QA to test sanitizing input # This is for QA to test sanitizing input
if [ -z "$qapadding" ]; then qapadding=40; fi
function qaunittest { function qaunittest {
if [ -z "$1" ] || [ -z "$2" ]; then unset actualreturn;
echo Usage: qaunittest function input expectedreturn inputarguments if [ -z "$1" ]; then
exit echo Usage: qaunittest title function expectedreturn input inputarguments
exit 1
fi fi
function="$1" header="$1"
userinput="$2" function="$2"
expectedreturn="$3" expectedreturn="$3"
fnargs="$4" userinput="$4"
input="input""$inputcount" fnargs="$5"
cmd="$(printf "source /usr/local/src/SharedLibraries/Bash/header;%s '%s' '%s' %s >/dev/null;echo \$%s" "$function" "$input" "Input" "$fnargs" "$input")" cmd="$(printf "source /usr/local/src/SharedLibraries/Bash/header;%s %s" "$function" "$fnargs")"
$input="$(bash -c "$cmd" <<EOM actualreturn="`bash -c "$cmd" 2>&1 <<EOM
$(echo -ne $userinput) $(echo -ne $userinput)
EOM EOM
)" `"
if [ "${!input}" == "$expectedreturn" ]; then printf "$header";
tput setaf 2; printf "PASS "; tput sgr0; echo -- found ${!input} in \'$(echo $cmd | cut -f 2 -d ';')\' printf ":%*s" $(($qapadding - $(echo $header | wc -c) - 1)) '['
if [ "$actualreturn" == "$expectedreturn" ]; then
tput setaf 2; printf "PASS"; tput sgr0; printf ']\n';
else else
tput setaf 1; printf "FAIL "; tput sgr0; echo -- found ${!input} \(expected $expectedreturn\) in \'$(echo $cmd | cut -f 2 -d ';')\' tput setaf 1; printf "FAIL"; tput sgr0; printf '] -- found %s (expected %s) running '\''%s %s < "%s"'\''\n' "$actualreturn" "$expectedreturn" "$function" "$fnargs" "$userinput";
fi fi
export inputcount=$(($inputcount + 1))
return return
} }