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

@@ -1,7 +1 @@
simplonco@simplonco-Latitude-E6320:~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests$ echo hello
hello
simplonco@simplonco-Latitude-E6320:~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests$ exit
simplonco@simplonco-Latitude-E6320:~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests$ echo you
you
simplonco@simplonco-Latitude-E6320:~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests$ exit

View File

@@ -1,7 +1 @@
hulamy@NoName:/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests
s/unit_tests> echo hello
hello
hulamy@NoName:/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests
s/unit_tests> exit
hulamy@NoName:/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests

View File

@@ -1 +1,8 @@
echo "pipes"
echo bonjour ; |
echo bonjour | |
|
echo bonjour |;

1
tests/unit_tests/test Normal file
View File

@@ -0,0 +1 @@
bonjour 1

View File

@@ -1,5 +1,111 @@
echo hello
echo test
# comment
echo you
echo you
echo you
echo you
echo you
echo you

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++ ))

View File

@@ -111,7 +111,8 @@ echo "$HOME"
echo '$HOME'
export ; env # display is different for both commands
export ; env
# display is different for both commands
echo \$HOME
@@ -165,10 +166,10 @@ export "HI= hi"
export "HI =hi"
/bin/ls
write something the press ctrl+c
write something then press ctrl+d
write something then press ctrl+\
# /bin/ls
# write something the press ctrl+c
# write something then press ctrl+d
# write something then press ctrl+\
echo $?