Test stdout and stderr now
This commit is contained in:
parent
ee8fdcbc4a
commit
a759c98b95
3 changed files with 59 additions and 16 deletions
49
test.sh
49
test.sh
|
@ -59,18 +59,61 @@ cd $DIR
|
|||
[ ! -f $COMMAND ] && error "script **$COMMAND** not found"
|
||||
|
||||
while IFS='' read -r i || [[ -n "$line" ]]; do
|
||||
# Create temp dir to store stderr
|
||||
errfile=$(mktemp)
|
||||
args=$(echo $i | cut -d: -f1)
|
||||
e_code=$(echo $i | cut -d: -f2)
|
||||
msg "\nScript *${COMMAND}*, paramètres **${args}**\n"
|
||||
ret_o=$(./$COMMAND $args 2>&1)
|
||||
e_stdout=$(echo $i | cut -d: -f3)
|
||||
e_stderr=$(echo $i | cut -d: -f4-)
|
||||
|
||||
msg "\nScript **\"${COMMAND} ${args}\"**\n"
|
||||
ret_o=$(./$COMMAND $args 2>$errfile)
|
||||
ret_c=$?
|
||||
ret_e=$(< "$errfile")
|
||||
rm "$errfile"
|
||||
|
||||
if [[ $ret_c == $e_code ]]
|
||||
then
|
||||
msg "green" "\tLe code de retour est celui attendu (${e_code})\n"
|
||||
else
|
||||
msg "yellow" "\tLe code de retour n'est pas correct script : ${ret_c} attendu : ${e_code}\n"
|
||||
fi
|
||||
msg "blue" "\tRetour : ${ret_o}\n"
|
||||
|
||||
if [[ ! -z $ret_o ]]
|
||||
then
|
||||
if [[ ! -z $e_stdout ]]
|
||||
then
|
||||
if [[ $ret_o == $e_stdout ]]
|
||||
then
|
||||
msg "blue" "\tSTDOUT : $e_stdout\n"
|
||||
else
|
||||
msg "red" "\tSTDOUT n'est pas celui attendu :\n"
|
||||
msg "blue" "\t\tAttendu :\t$e_stdout\n"
|
||||
msg "blue" "\t\tObtenu :\t$ret_o\n"
|
||||
fi
|
||||
else
|
||||
msg "red" "STDOUT (non attendu) : $ret_o\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -z $ret_e ]]
|
||||
then
|
||||
# Script return STDERR
|
||||
if [[ ! -z $e_stderr ]]
|
||||
then
|
||||
# We need stderr to validate test
|
||||
if [[ $e_stderr == $ret_e ]]
|
||||
then
|
||||
msg "blue" "\tSTDERR : $ret_e\n"
|
||||
else
|
||||
msg "red" "\tSTDERR n'est pas celui attendu\n"
|
||||
msg "blue" "\t\tAttendu :\t$e_stderr\n"
|
||||
msg "blue" "\t\tObtenu :\t$ret_e\n"
|
||||
fi
|
||||
msg "red" "\tSDTERR (non attendu) : $ret_e\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
done < "$TEST_FILE"
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue