fix bug last line et ajout info sur next command si option print
This commit is contained in:
@@ -1,7 +1 @@
|
||||
|
||||
[01;32msimplonco@simplonco-Latitude-E6320[00m:[01;34m~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests[00m$ echo hello
|
||||
hello
|
||||
[01;32msimplonco@simplonco-Latitude-E6320[00m:[01;34m~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests[00m$ exit
|
||||
[01;32msimplonco@simplonco-Latitude-E6320[00m:[01;34m~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests[00m$ echo you
|
||||
you
|
||||
[01;32msimplonco@simplonco-Latitude-E6320[00m:[01;34m~/Nextcloud/informatique/42/minishell/minishell/tests/unit_tests[00m$ exit
|
||||
|
||||
@@ -1,7 +1 @@
|
||||
|
||||
[1;32mhulamy@NoName[0m:[1;34m/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests
|
||||
s/unit_tests[0m> echo hello
|
||||
hello
|
||||
[1;32mhulamy@NoName[0m:[1;34m/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests
|
||||
s/unit_tests[0m> exit
|
||||
[1;32mhulamy@NoName[0m:[1;34m/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests
|
||||
|
||||
@@ -1 +1,8 @@
|
||||
echo "pipes"
|
||||
echo bonjour ; |
|
||||
|
||||
echo bonjour | |
|
||||
|
||||
|
|
||||
|
||||
echo bonjour |;
|
||||
|
||||
|
||||
1
tests/unit_tests/test
Normal file
1
tests/unit_tests/test
Normal file
@@ -0,0 +1 @@
|
||||
bonjour 1
|
||||
@@ -1,5 +1,111 @@
|
||||
echo hello
|
||||
echo test
|
||||
|
||||
# comment
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo you
|
||||
echo you
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo you
|
||||
echo you
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo you
|
||||
echo you
|
||||
|
||||
@@ -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++ ))
|
||||
|
||||
@@ -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 $?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user