test unitaire avance
This commit is contained in:
@@ -1,28 +1,118 @@
|
||||
#!/bin/bash
|
||||
|
||||
#bash -i &> file.log
|
||||
#exit
|
||||
cp ../minishell .
|
||||
|
||||
#myoutput=$(echo "echo hello ; exit" | bash -i)
|
||||
RED="\001\e[0;31m\002"
|
||||
GREEN="\001\e[0;32m\002"
|
||||
YELLOW="\001\e[0;33m\002"
|
||||
BLUE="\001\e[0;34m\002"
|
||||
MAGENTA="\001\e[0;35m\002"
|
||||
CYAN="\001\e[0;36m\002"
|
||||
WHITE="\001\e[0;37m\002"
|
||||
|
||||
#echo "follow\n"
|
||||
#echo $myoutput
|
||||
B_RED="\001\e[1;31m\002"
|
||||
B_GREEN="\001\e[1;32m\002"
|
||||
B_YELLOW="\001\e[1;33m\002"
|
||||
B_BLUE="\001\e[1;34m\002"
|
||||
B_MAGENTA="\001\e[1;35m\002"
|
||||
B_CYAN="\001\e[1;36m\002"
|
||||
B_WHITE="\001\e[1;37m\002"
|
||||
|
||||
#echo "echo hello" | (bash -i &>file.log)
|
||||
#echo hello
|
||||
#exit
|
||||
ENDCO="\001\e[0m\002"
|
||||
|
||||
#echo "echo hello" | bash -i 2>&1 | \
|
||||
#(
|
||||
# read myoutput;
|
||||
# echo "myoutput :\n";
|
||||
# echo $myoutput;
|
||||
#)
|
||||
list_files="\
|
||||
tunit_0.sh"
|
||||
# tunit_1.sh \
|
||||
# tunit_2.sh \
|
||||
# tunit_3.sh \
|
||||
# "
|
||||
|
||||
#myoutput=$(echo "echo hello" | bash -i 2>&1 | (read foo; echo $foo))
|
||||
TOTAL_TEST=0
|
||||
SUCCESS_TEST=0
|
||||
|
||||
myoutput=$( (echo "echo hello" ; echo "echo hugo") | bash -i 2>&1)
|
||||
echo "myoutput :"
|
||||
echo "$myoutput"
|
||||
function test_bash
|
||||
{
|
||||
# execute commands in bash and minishell
|
||||
bash_execution=$( echo "$@" | bash -i 2>&1 )
|
||||
minishell_execution=$( echo "$@" | ./minishell )
|
||||
#echo "minishell_execution :"
|
||||
#echo "$minishell_execution"
|
||||
#echo "$minishell_execution" | cat -e
|
||||
echo "bash_execution :"
|
||||
echo "$bash_execution"
|
||||
echo "$bash_execution" | cat -e
|
||||
echo ""
|
||||
|
||||
# extract informations
|
||||
first_command=$( head -1 <<< "$@" )
|
||||
echo "first_command:"
|
||||
echo "$first_command"
|
||||
echo ""
|
||||
|
||||
#f_cmd_length=${#first_command}
|
||||
#bash_prompt=$( head -1 <<< "$bash_execution" | sed "s/${first_command}//g")
|
||||
bash_prompt=$( head -1 <<< "$bash_execution")
|
||||
#bash_prompt=${bash_prompt::-$f_cmd_length}
|
||||
echo "bash_prompt :"
|
||||
echo "$bash_prompt"
|
||||
echo "$bash_prompt" | cat -e
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
myoutput=$( grep -v "simplonco" <<< "$bash_execution" )
|
||||
echo "myoutput :"
|
||||
echo "$myoutput"
|
||||
echo ""
|
||||
|
||||
((SUCCESS_TEST++))
|
||||
}
|
||||
|
||||
function print_results
|
||||
{
|
||||
if [ $SUCCESS_TEST -eq 0 ]
|
||||
then
|
||||
echo -en $B_RED $SUCCESS_TEST $ENDCO
|
||||
elif [ $SUCCESS_TEST -eq $TOTAL_TEST ]
|
||||
then
|
||||
echo -en $B_GREEN $SUCCESS_TEST $ENDCO
|
||||
else
|
||||
echo -en $B_MAGENTA $SUCCESS_TEST $ENDCO
|
||||
fi
|
||||
echo -e $B_WHITE"/ $TOTAL_TEST"$ENDCO
|
||||
}
|
||||
|
||||
# parse tests files line by line, grouping lines non-separated by an empty line
|
||||
for i in $list_files
|
||||
do
|
||||
filename=$i
|
||||
echo -e "\n"$B_YELLOW"test file : $i"$ENDCO
|
||||
command_test=""
|
||||
last_line="$(tail -1 $i)"
|
||||
((TOTAL_TEST=0))
|
||||
((SUCCESS_TEST=0))
|
||||
while read line
|
||||
do
|
||||
if [ "$line" != "" ]
|
||||
then
|
||||
if [ "$command_test" == "" ]
|
||||
then
|
||||
command_test="$line"
|
||||
else
|
||||
command_test+=$'\n'
|
||||
command_test+="$line"
|
||||
fi
|
||||
if [ "$line" == "$last_line" ]
|
||||
then
|
||||
((TOTAL_TEST++))
|
||||
test_bash "$command_test"
|
||||
fi
|
||||
elif [ "$command_test" != "" ]
|
||||
then
|
||||
((TOTAL_TEST++))
|
||||
test_bash "$command_test"
|
||||
command_test=""
|
||||
fi
|
||||
done < $filename
|
||||
print_results
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user