test unitaires a peu pres ok :)

This commit is contained in:
hugogogo
2021-12-03 22:32:07 +01:00
parent 27f8059d8a
commit a288ad473e
26 changed files with 506 additions and 513 deletions

View File

@@ -1 +0,0 @@
echo "builtins"

View File

@@ -1 +0,0 @@
echo "exit status"

View File

@@ -1 +0,0 @@
echo "expensions"

View File

@@ -1,3 +0,0 @@
mybash a very long prompt to test the output in case of a redirection in a file> echo hello
hello
mybash a very long prompt to test the output in case of a redirection in a file> exit

View File

@@ -1 +1,60 @@

file: ut_vrac.sh

$
-----------

file_name_in_current_dir
-----------

/bin/echo bonjour
-----------
bonjour

not_cmd
-----------

echo bonjour > $test w/ t
ls
rm '$test'
-----------
logs
minishell
tests_discord.md
unitests.sh
ut_bonus.sh
ut_builtins.sh
ut_exit_status.sh
ut_expensions.sh
ut_heredocs.sh
ut_pipes.sh
ut_redirections.sh
ut_to_do_manually.sh
ut_vrac.sh
wip

"exit retour a la ligne"
-----------

minishell
-----------

l^Ds
-----------

View File

@@ -0,0 +1 @@
hulamy@NoName:/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests

View File

@@ -1 +1,61 @@

file: ut_vrac.sh

$
-----------

file_name_in_current_dir
-----------

/bin/echo bonjour
-----------
bonjour

not_cmd
-----------

echo bonjour > $test w/ t
ls
rm '$test'
-----------
logs
minishell
$test
tests_discord.md
unitests.sh
ut_bonus.sh
ut_builtins.sh
ut_exit_status.sh
ut_expensions.sh
ut_heredocs.sh
ut_pipes.sh
ut_redirections.sh
ut_to_do_manually.sh
ut_vrac.sh
wip

"exit retour a la ligne"
-----------

minishell
-----------

l^Ds
-----------

View File

@@ -1,8 +0,0 @@
echo bonjour ; |
echo bonjour | |
|
echo bonjour |;

View File

@@ -1 +0,0 @@
echo "redirections"

View File

@@ -1,105 +0,0 @@
# Minishell tests
Here are some tests for the minishell project of school 42 cursus. It's not exaustive, so don't limit yourself with this tests.
These tests are not all mines. Credits to vgoldman, mashar, and jecaudal.
tmarx
# Tests
- [ ] echo bonjour ; |
- [ ] echo bonjour | |
- [ ] |
- [ ] echo bonjour |;
- [ ] echo bonjour \; ls
- [ ] echo bonjour > test\ 1
- [ ] cd $HOME/Documents
- [ ] echo "\s" & echo "\\s"
- [ ] echo \>
- [ ] echo -n -n -nnnn -nnnnm
- [ ] cat /dev/random | head -n 1 | cat -e
- [ ] unset var1 # with undefined var1
- [ ] export "" et unset ""
- [ ] echo test > file test1
- [ ] $
- [ ] not_cmd bonjour > salut
- [ ] env puis export puis env # vars aren't sorted
- [ ] cat Makefile | grep pr | head -n 5 | cd test (mybin) # check status code
- [ ] cat Makefile | grep pr | head -n 5 | cat test (bin) # check status code
- [ ] cat Makefile | grep pr | head -n 5 | hello (NA) # check status code
- [ ] echo bonjour >>> test
- [ ] echo bonjour > > out
- [ ] echo 2 >> out1 > out2
- [ ] echo 2 > out1 >> out2
- [ ] cat < test # with non-existent test
- [ ] export var; export var=test
- [ ] echo bonjour > $test # with test not defined
- [ ] file_name_in_current_dir
- [ ] cd ../../../../../.. ; pwd
- [ ] ctrl-C . 130 sur bin(ex : sleep 10)&line vide
- [ ] ctrl-\ .131 sur bin
- [ ] echo "bip | bip ; coyotte > < \" "
- [ ] cat | cat | cat | ls # check outputs order
- [ ] $bla # with bla not defined
- [ ] export var ="cat Makefile | grep >"
- [ ] export "test=ici"=coucou
- [ ] c$var Makefile # with var=at
- [ ] $LESS$VAR
- [ ] /bin/echo bonjour
- [ ] not_cmd
- [ ] sleep 5 | exit
- [ ] echo bonjour > $test w/ t
- [ ] "exit retour a la ligne"
- [ ] minishell # binary not in path without "./" before
- [ ] cat diufosgid # check exit code
- [ ] exit # should return the last exit code value
- [ ] exit -10
- [ ] exit +10
- [ ] ;
- [ ] echo coucou | ;
- [ ] echo "$HOME"
- [ ] echo '$HOME'
- [ ] export ; env # display is different for both commands
- [ ] echo \$HOME
- [ ] > log echo coucou
- [ ] echo hudifg d | | hugdfihd
- [ ] echo
- [ ] echo simple
- [ ] echo -n simple
- [ ] echo '\'
- [ ] echo "\"
- [ ] echo "\\"
- [ ] echo "\n \n \n"
- [ ] echo "\n \\n \\\n"
- [ ] echo ;;
- [ ] echo hi";" hihi
- [ ] echo hi " ; " hihi
- [ ] cd
- [ ] cd .
- [ ] cd ~
- [ ] cd /
- [ ] cd no_file
- [ ] cd a b c d
- [ ] pwd a
- [ ] pwd a b c d
- [ ] export LOL=lala ROR=rara
- [ ] unset LOL ROR
- [ ] 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+\
- [ ] echo $?
- [ ] l^Ds
- [ ] echo |
- [ ] | echo
- [ ] sort | ls # check output order
- [ ] cat < >
- [ ] cat < <
- [ ] cat > >
- [ ] > a ls > b < Makefile
- [ ] echo > a Hello World!
- [ ] > a echo Hello World!
- [ ] cat < Makefile | grep gcc > output
- [ ] exit 0 | exit 1
- [ ] exit 1 | exit 0

View File

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

View File

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

View File

@@ -1,5 +0,0 @@
echo "ho !"
echo "it's you again"
echo "welcome back"

View File

@@ -1,10 +0,0 @@
echo "let's"
echo "see what"
echo "you've"
echo "got"
echo "show"
echo "me"
echo "what"
echo "you"
echo "goooot"

View File

@@ -1,24 +1,5 @@
#!/bin/bash
## explanation :
## 1. check for arguments (files for tests)
## if found, check for validity, and launch test on them
## if not found, launch test on default file list
## 2. execute the main for-loop
## it will iterate through the commands of each files
## if a line start with a # it's skipped
## if commands are not separated by empty line, it concat them
## then it calls the compare function "test_minishell" with commands
## and it calls the print function with the results
## 3. the compare function "test_minishell"
## it takes the commands in argument
## it launch bash and minishell with the commands
## if multiple commands, they are executed in a row before exit the shell
## if error, it prints right away the two outputs
## 4. the print function, print results
## it's use after each files
## and at the end
# COLORS
RED="\001\e[0;31m\002"
GREEN="\001\e[0;32m\002"
@@ -48,7 +29,7 @@
TOTAL_TEST=0
TOTAL_SUCCESS=0
LINE_NUMBER=0
LOG=0
OPTION=0
PRINT=0
mkdir -p ./logs
echo "" > ./logs/bash_log.txt
@@ -58,13 +39,13 @@
# default list of files to be use
default_files="\
vrac.sh
pipes.sh
expensions.sh
redirections.sh
exit_status.sh
builtins.sh"
#heredocs.sh
ut_builtins.sh
ut_exit_status.sh
ut_expensions.sh
ut_heredocs.sh
ut_pipes.sh
ut_redirections.sh
ut_vrac.sh"
# print usage
function print_usage
@@ -88,8 +69,10 @@
echo " options :"
echo -en "$ENDCO"
echo -en "$CYAN"
echo " help - print usage"
echo " log - log output into logs/<logs_files.txt>"
echo " help - print usage"
echo " -p1 - prints errors"
echo " -p2 - prints errors and commands"
echo " -p3 - prints errors and commands and errors output"
echo -en "$ENDCO"
echo ""
echo -en "$GREEN"
@@ -104,26 +87,40 @@
echo ""
}
# list of tests files, by default ot in parameters
if [ $# == 0 ]
# check for argments, like options or files list
# if no file list, default file list is used
list_files="$default_files"
if [ $# -gt 0 ]
then
list_files="$default_files"
else
START=1
if [ "$1" == "help" ]
then
print_usage
else
START=1
if [ "$1" == "log" ]
START=0
elif [ "$1" == "-p1" ]
then
PRINT=1
OPTION=1
elif [ "$1" == "-p2" ]
then
PRINT=2
OPTION=1
elif [ "$1" == "-p3" ]
then
PRINT=3
OPTION=1
fi
if [ $OPTION -eq 1 ]
then
if [ $# -eq 1 ]
then
LOG=1
START=2
fi
if [ "$1" == "print" ]
then
PRINT=1
START=0
else
START=2
fi
fi
if [ $START -gt 0 ]
then
list_files=""
for (( i = $START ; i <= "$#" ; i++ ))
do
@@ -135,47 +132,67 @@
fi
list_files+="${!i}"
else
echo "${!i} is not a valid file"
print_usage
echo " \"${!i}\" is not a valid file or option, see usage above"
fi
done
fi
fi
# if print option, print next command
function print_next_command
{
TEXT=$1
CMD=$2
COLOR=$3
INDENT="$(for (( i=1; i<=${#TEXT}; i++ )); do echo -n ' '; done)"
echo -en $COLOR"$TEXT"$YELLOW
echo -n "${CMD//$'\n'/$'\n'$INDENT}"
echo -e $ENDCO
}
# 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 ]
# if -p2|3, print which command is about to be executed
if [ $PRINT -gt 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
NEXT_CMD="command line $(( $LINE_NUMBER - 1 )) : "
print_next_command "$NEXT_CMD" "$@" "$CYAN"
fi
# execute commands in bash and minishell
# execute commands in bash, and logs results
bash_execution=$( echo "$@" | bash 2>/dev/null )
echo -e $B_WHITE"\n\n$@\n-----------"$ENDCO >>$BASH_LOG
echo "$bash_execution" >> $BASH_LOG
minishell_execution=$( echo "$@" | ./minishell 2>/dev/null )
# if log option, log results
if [ "$LOG" == 1 ]
then
echo "$@" | bash -i &>>$BASH_LOG
echo "$@" | ./minishell &>>$MINISHELL_LOG
fi
echo -e $B_WHITE"\n\n$@\n-----------"$ENDCO >>$MINISHELL_LOG
echo "$minishell_execution" >> $MINISHELL_LOG
#compare output
if [ "$bash_execution" = "$minishell_execution" ]
then
(( SUCCESS_TEST++ ))
(( TOTAL_SUCCESS++ ))
else
echo -e $B_RED"ERROR : line number $LINE_NUMBER"$ENDCO
echo ""
echo -e $B_MAGENTA"[bash execution] :"$ENDCO
echo "$@" | bash -i
echo ""
echo -e $B_MAGENTA"[minishell execution] :"$ENDCO
echo "$@" | ./minishell
echo ""
# if -p1..3 print error for command
if [ $PRINT -eq 1 ]
then
ERROR_CMD="ERROR line $(( $LINE_NUMBER - 1 )), command : "
print_next_command "$ERROR_CMD" "$@" "$B_RED"
elif [ $PRINT -eq 2 ]
then
echo -e $B_RED" "'\'" ERROR"$ENDCO
elif [ $PRINT -eq 3 ]
then
echo -e $B_RED" "'\'" ERROR"$ENDCO
echo -e $B_MAGENTA"[bash execution] :"$ENDCO
echo "$@" | bash -i
echo ""
echo -e $B_MAGENTA"[minishell execution] :"$ENDCO
echo "$@" | ./minishell
echo ""
fi
fi
}
@@ -204,9 +221,14 @@
filename=$i
echo -e "\n"$B_YELLOW"test file : $i"$ENDCO
command_test=""
LINE_NUMBER=0
LAST_LINE_NUMBER=$(wc -l < $filename)
UNIT_TEST=0
SUCCESS_TEST=0
# write name of file in log files
echo -en $B_YELLOW "\n\n\nfile: $filename\n" $ENDCO >>$BASH_LOG
echo -en $B_YELLOW "\n\n\nfile: $filename\n" $ENDCO >>$MINISHELL_LOG
# do the loop
while read line
do
(( LINE_NUMBER++ ))
@@ -246,3 +268,10 @@
echo ""
print_results "all" $TOTAL_SUCCESS $TOTAL_TEST
fi
# ask to show the diff
read -p 'you want to see the diff ? (y?)' DIFF
if [[ "${DIFF,,}" =~ y|yes ]]
then
diff -y --width=100 --color=always "$BASH_LOG" "$MINISHELL_LOG"
fi

View File

@@ -0,0 +1,11 @@
echo bonjour ; |
echo bonjour |;
;
echo coucou | ;
echo ;;
echo bonjour \; ls

View File

@@ -0,0 +1,108 @@
#
# ENV
#
env
#
# EXPORT
#
export var
export var=test
export var ="cat Makefile | grep >"
export "test=ici"=coucou
export LOL=lala ROR=rara
export "HI= hi"
export "HI =hi"
export
env
# display is different for both commands
env
export
env
#
# UNSET
#
export BLOU=
env
unset BLOU
env
unset LOL ROR
env
unset blablabla
env
export ""
env
unset ""
env
#
# ECHO
#
echo
echo simple
echo -n simple
echo -n -n -nnnn -nnnnm
#
# PWD
#
pwd a
pwd a b c d
#
# CD
#
cd
pwd
cd .
pwd
cd ~
pwd
cd /
pwd
cd no_file
pwd
cd a b c d
pwd
cd $HOME/Documents
pwd
cd ../../../../../..
pwd
#
# EXIT
#
exit -10
exit +10

View File

@@ -0,0 +1,17 @@
echo $?
cat Makefile | grep pr | head -n 5 | cd test (mybin)
$?
cat Makefile | grep pr | head -n 5 | cat test (bin)
$?
cat Makefile | grep pr | head -n 5 | hello (NA)
$?
cat diufosgid
$?
exit
$?

View File

@@ -0,0 +1,35 @@
echo "bip | bip ; coyotte > < \" "
export vat=at
c$var Makefile
$blablabla
$LESS$VAR
echo '\'
echo "\"
echo "\\"
echo "\n \n \n"
echo "\n \\n \\\n"
echo hi";" hihi
echo hi " ; " hihi
echo "\s"
echo "\\s"
echo \>
echo "$HOME"
echo '$HOME'
echo \$HOME

View File

@@ -6,7 +6,7 @@ COMMANDE=' echo "hugo"'
# EOF'
#echo "$COMMANDE" | bash -i &>file.log
echo "$COMMANDE" | ./minishell &>file.log
#echo "$COMMANDE" | ./minishell &>file.log
#cat << EOF
#hello

View File

@@ -0,0 +1,36 @@
echo bonjour ; |
echo bonjour | |
|
echo bonjour |;
cat Makefile | grep pr | head -n 5 | cd test (mybin)
cat Makefile | grep pr | head -n 5 | cat test (bin)
cat Makefile | grep pr | head -n 5 | hello (NA)
cat | cat | cat | ls
echo hudifg d | | hugdfihd
echo |
| echo
sort | ls
exit 0 | exit 1
exit 1 | exit 0
cat < Makefile | grep gcc > output
ls
rm output
rm output
sleep 5 | exit

View File

@@ -0,0 +1,54 @@
echo bonjour > $test
ls
rm '$test'
> log echo coucou
ls
rm log
cat < >
cat < <
cat > >
> a ls > b < Makefile
ls
rm a b
echo > a Hello World!
ls
rm a
> a echo Hello World!
ls
rm a
echo bonjour > test\ 1
ls
rm test
echo bonjour >>> test
echo bonjour > > out
ls
rm out
echo 2 >> out1 > out2
ls
rm out1 out2
echo 2 > out1 >> out2
ls
rm out1 out2
cat < blablabla
echo test > file test1
ls
rm file
not_cmd bonjour > salut
ls
rm salut

View File

@@ -0,0 +1,11 @@
cat /dev/random | head -n 1 | cat -e
ctrl-C . 130 sur bin(ex : sleep 10)&line vide
ctrl-\ .131 sur bin
/bin/ls
write something the press ctrl+c
write something then press ctrl+d
write something then press ctrl+\

View File

@@ -0,0 +1,19 @@
$
file_name_in_current_dir
/bin/echo bonjour
not_cmd
echo bonjour > $test w/ t
ls
rm '$test'
"exit retour a la ligne"
minishell
# binary not in path without "./" before
l^Ds

View File

@@ -1,200 +0,0 @@
echo bonjour ; |
echo bonjour | |
|
echo bonjour |;
echo bonjour \; ls
echo bonjour > test\ 1
cd $HOME/Documents
echo "\s" & echo "\\s"
echo \>
echo -n -n -nnnn -nnnnm
cat /dev/random | head -n 1 | cat -e
unset blablabla
export "" et unset ""
echo test > file test1
$
not_cmd bonjour > salut
env
export
env
cat Makefile | grep pr | head -n 5 | cd test (mybin)
$?
cat Makefile | grep pr | head -n 5 | cat test (bin)
$?
cat Makefile | grep pr | head -n 5 | hello (NA)
$?
echo bonjour >>> test
echo bonjour > > out
echo 2 >> out1 > out2
echo 2 > out1 >> out2
cat < blablabla
export var; export var=test
echo bonjour > $test
file_name_in_current_dir
cd ../../../../../.. ; pwd
ctrl-C . 130 sur bin(ex : sleep 10)&line vide
ctrl-\ .131 sur bin
echo "bip | bip ; coyotte > < \" "
cat | cat | cat | ls
$blablabla
export var ="cat Makefile | grep >"
export "test=ici"=coucou
export vat=at
c$var Makefile
$LESS$VAR
/bin/echo bonjour
not_cmd
sleep 5 | exit
echo bonjour > $test w/ t
"exit retour a la ligne"
minishell
# binary not in path without "./" before
cat diufosgid
$?
exit
$?
exit -10
exit +10
;
echo coucou | ;
echo "$HOME"
echo '$HOME'
export ; env
# display is different for both commands
echo \$HOME
> log echo coucou
echo hudifg d | | hugdfihd
echo
echo simple
echo -n simple
echo '\'
echo "\"
echo "\\"
echo "\n \n \n"
echo "\n \\n \\\n"
echo ;;
echo hi";" hihi
echo hi " ; " hihi
cd
cd .
cd ~
cd /
cd no_file
cd a b c d
pwd a
pwd a b c d
export LOL=lala ROR=rara
unset LOL ROR
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+\
echo $?
l^Ds
echo |
| echo
sort | ls
cat < >
cat < <
cat > >
> a ls > b < Makefile
echo > a Hello World!
> a echo Hello World!
cat < Makefile | grep gcc > output
exit 0 | exit 1
exit 1 | exit 0