fix bug last line et ajout info sur next command si option print

This commit is contained in:
hugogogo
2021-12-03 12:24:23 +01:00
parent 6ac25b11ae
commit 27f8059d8a
7 changed files with 142 additions and 22 deletions

View File

@@ -47,7 +47,9 @@
SUCCESS_TEST=0
TOTAL_TEST=0
TOTAL_SUCCESS=0
LINE_NUMBER=0
LOG=0
PRINT=0
mkdir -p ./logs
echo "" > ./logs/bash_log.txt
echo "" > ./logs/minishell_log.txt
@@ -117,6 +119,11 @@
LOG=1
START=2
fi
if [ "$1" == "print" ]
then
PRINT=1
START=2
fi
list_files=""
for (( i = $START ; i <= "$#" ; i++ ))
do
@@ -137,10 +144,19 @@
# function that will launch the command in bash and minishell and compare them
function test_minishell
{
# if print option, print wich command is about to be executed
if [ "$PRINT" == 1 ]
then
NEXT_CMD="command line $LINE_NUMBER : "
INDENT="$(for (( i=1; i<=${#NEXT_CMD}; i++ )); do echo -n ' '; done)"
echo -en $CYAN"$NEXT_CMD"$YELLOW
echo -n "${@//$'\n'/$'\n'$INDENT}"
echo -e $ENDCO
fi
# execute commands in bash and minishell
bash_execution=$( echo "$@" | bash 2>/dev/null )
minishell_execution=$( echo "$@" | ./minishell 2>/dev/null )
# if log options, log results
# if log option, log results
if [ "$LOG" == 1 ]
then
echo "$@" | bash -i &>>$BASH_LOG
@@ -152,7 +168,7 @@
(( SUCCESS_TEST++ ))
(( TOTAL_SUCCESS++ ))
else
echo -e $B_RED"ERROR :"$ENDCO
echo -e $B_RED"ERROR : line number $LINE_NUMBER"$ENDCO
echo ""
echo -e $B_MAGENTA"[bash execution] :"$ENDCO
echo "$@" | bash -i
@@ -188,11 +204,12 @@
filename=$i
echo -e "\n"$B_YELLOW"test file : $i"$ENDCO
command_test=""
last_line="$(tail -1 $i)"
LAST_LINE_NUMBER=$(wc -l < $filename)
UNIT_TEST=0
SUCCESS_TEST=0
while read line
do
(( LINE_NUMBER++ ))
if [ -n "$line" ]
then
# if line start with # skip it
@@ -205,7 +222,7 @@
command_test+=$'\n'
command_test+="$line"
fi
if [ "$line" == "$last_line" ]
if [ $LINE_NUMBER -eq $LAST_LINE_NUMBER ]
then
(( UNIT_TEST++ ))
(( TOTAL_TEST++ ))