test unitaires a peu pres ok :)
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
echo "builtins"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
echo "exit status"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
echo "expensions"
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[1;37mmybash a very long prompt to test the output in case of a redirection in a file> [0mecho hello
|
|
||||||
hello
|
|
||||||
[1;37mmybash a very long prompt to test the output in case of a redirection in a file> [0mexit
|
|
||||||
@@ -1 +1,60 @@
|
|||||||
|
|
||||||
|
[1;33m
|
||||||
|
|
||||||
|
|
||||||
|
file: ut_vrac.sh
|
||||||
|
[0m[1;37m
|
||||||
|
|
||||||
|
$
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
file_name_in_current_dir
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
/bin/echo bonjour
|
||||||
|
-----------[0m
|
||||||
|
bonjour
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
not_cmd
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
echo bonjour > $test w/ t
|
||||||
|
ls
|
||||||
|
rm '$test'
|
||||||
|
-----------[0m
|
||||||
|
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
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
"exit retour a la ligne"
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
minishell
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
l^Ds
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
|||||||
1
tests/unit_tests/logs/log_err.txt
Normal file
1
tests/unit_tests/logs/log_err.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[1;32mhulamy@NoName[0m:[1;34m/home/simplonco/Nextcloud/informatique/42/minishell/minishell/tests
|
||||||
@@ -1 +1,61 @@
|
|||||||
|
|
||||||
|
[1;33m
|
||||||
|
|
||||||
|
|
||||||
|
file: ut_vrac.sh
|
||||||
|
[0m[1;37m
|
||||||
|
|
||||||
|
$
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
file_name_in_current_dir
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
/bin/echo bonjour
|
||||||
|
-----------[0m
|
||||||
|
bonjour
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
not_cmd
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
echo bonjour > $test w/ t
|
||||||
|
ls
|
||||||
|
rm '$test'
|
||||||
|
-----------[0m
|
||||||
|
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
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
"exit retour a la ligne"
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
minishell
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
[1;37m
|
||||||
|
|
||||||
|
l^Ds
|
||||||
|
-----------[0m
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
echo bonjour ; |
|
|
||||||
|
|
||||||
echo bonjour | |
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
||||||
echo bonjour |;
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
echo "redirections"
|
|
||||||
@@ -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
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
bonjour 1
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
echo hello
|
|
||||||
echo test
|
|
||||||
|
|
||||||
# comment
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo you
|
|
||||||
echo you
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo you
|
|
||||||
echo you
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo you
|
|
||||||
echo you
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
echo "ho !"
|
|
||||||
|
|
||||||
echo "it's you again"
|
|
||||||
|
|
||||||
echo "welcome back"
|
|
||||||
@@ -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"
|
|
||||||
@@ -1,24 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/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
|
# COLORS
|
||||||
RED="\001\e[0;31m\002"
|
RED="\001\e[0;31m\002"
|
||||||
GREEN="\001\e[0;32m\002"
|
GREEN="\001\e[0;32m\002"
|
||||||
@@ -48,7 +29,7 @@
|
|||||||
TOTAL_TEST=0
|
TOTAL_TEST=0
|
||||||
TOTAL_SUCCESS=0
|
TOTAL_SUCCESS=0
|
||||||
LINE_NUMBER=0
|
LINE_NUMBER=0
|
||||||
LOG=0
|
OPTION=0
|
||||||
PRINT=0
|
PRINT=0
|
||||||
mkdir -p ./logs
|
mkdir -p ./logs
|
||||||
echo "" > ./logs/bash_log.txt
|
echo "" > ./logs/bash_log.txt
|
||||||
@@ -58,13 +39,13 @@
|
|||||||
|
|
||||||
# default list of files to be use
|
# default list of files to be use
|
||||||
default_files="\
|
default_files="\
|
||||||
vrac.sh
|
ut_builtins.sh
|
||||||
pipes.sh
|
ut_exit_status.sh
|
||||||
expensions.sh
|
ut_expensions.sh
|
||||||
redirections.sh
|
ut_heredocs.sh
|
||||||
exit_status.sh
|
ut_pipes.sh
|
||||||
builtins.sh"
|
ut_redirections.sh
|
||||||
#heredocs.sh
|
ut_vrac.sh"
|
||||||
|
|
||||||
# print usage
|
# print usage
|
||||||
function print_usage
|
function print_usage
|
||||||
@@ -88,8 +69,10 @@
|
|||||||
echo " options :"
|
echo " options :"
|
||||||
echo -en "$ENDCO"
|
echo -en "$ENDCO"
|
||||||
echo -en "$CYAN"
|
echo -en "$CYAN"
|
||||||
echo " help - print usage"
|
echo " help - print usage"
|
||||||
echo " log - log output into logs/<logs_files.txt>"
|
echo " -p1 - prints errors"
|
||||||
|
echo " -p2 - prints errors and commands"
|
||||||
|
echo " -p3 - prints errors and commands and errors output"
|
||||||
echo -en "$ENDCO"
|
echo -en "$ENDCO"
|
||||||
echo ""
|
echo ""
|
||||||
echo -en "$GREEN"
|
echo -en "$GREEN"
|
||||||
@@ -104,26 +87,40 @@
|
|||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# list of tests files, by default ot in parameters
|
# check for argments, like options or files list
|
||||||
if [ $# == 0 ]
|
# if no file list, default file list is used
|
||||||
|
list_files="$default_files"
|
||||||
|
if [ $# -gt 0 ]
|
||||||
then
|
then
|
||||||
list_files="$default_files"
|
START=1
|
||||||
else
|
|
||||||
if [ "$1" == "help" ]
|
if [ "$1" == "help" ]
|
||||||
then
|
then
|
||||||
print_usage
|
print_usage
|
||||||
else
|
START=0
|
||||||
START=1
|
elif [ "$1" == "-p1" ]
|
||||||
if [ "$1" == "log" ]
|
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
|
then
|
||||||
LOG=1
|
START=0
|
||||||
START=2
|
else
|
||||||
fi
|
|
||||||
if [ "$1" == "print" ]
|
|
||||||
then
|
|
||||||
PRINT=1
|
|
||||||
START=2
|
START=2
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
if [ $START -gt 0 ]
|
||||||
|
then
|
||||||
list_files=""
|
list_files=""
|
||||||
for (( i = $START ; i <= "$#" ; i++ ))
|
for (( i = $START ; i <= "$#" ; i++ ))
|
||||||
do
|
do
|
||||||
@@ -135,47 +132,67 @@
|
|||||||
fi
|
fi
|
||||||
list_files+="${!i}"
|
list_files+="${!i}"
|
||||||
else
|
else
|
||||||
echo "${!i} is not a valid file"
|
print_usage
|
||||||
|
echo " \"${!i}\" is not a valid file or option, see usage above"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
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 that will launch the command in bash and minishell and compare them
|
||||||
function test_minishell
|
function test_minishell
|
||||||
{
|
{
|
||||||
# if print option, print wich command is about to be executed
|
# if -p2|3, print which command is about to be executed
|
||||||
if [ "$PRINT" == 1 ]
|
if [ $PRINT -gt 1 ]
|
||||||
then
|
then
|
||||||
NEXT_CMD="command line $LINE_NUMBER : "
|
NEXT_CMD="command line $(( $LINE_NUMBER - 1 )) : "
|
||||||
INDENT="$(for (( i=1; i<=${#NEXT_CMD}; i++ )); do echo -n ' '; done)"
|
print_next_command "$NEXT_CMD" "$@" "$CYAN"
|
||||||
echo -en $CYAN"$NEXT_CMD"$YELLOW
|
|
||||||
echo -n "${@//$'\n'/$'\n'$INDENT}"
|
|
||||||
echo -e $ENDCO
|
|
||||||
fi
|
fi
|
||||||
# execute commands in bash and minishell
|
# execute commands in bash, and logs results
|
||||||
bash_execution=$( echo "$@" | bash 2>/dev/null )
|
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 )
|
minishell_execution=$( echo "$@" | ./minishell 2>/dev/null )
|
||||||
# if log option, log results
|
echo -e $B_WHITE"\n\n$@\n-----------"$ENDCO >>$MINISHELL_LOG
|
||||||
if [ "$LOG" == 1 ]
|
echo "$minishell_execution" >> $MINISHELL_LOG
|
||||||
then
|
|
||||||
echo "$@" | bash -i &>>$BASH_LOG
|
|
||||||
echo "$@" | ./minishell &>>$MINISHELL_LOG
|
|
||||||
fi
|
|
||||||
#compare output
|
#compare output
|
||||||
if [ "$bash_execution" = "$minishell_execution" ]
|
if [ "$bash_execution" = "$minishell_execution" ]
|
||||||
then
|
then
|
||||||
(( SUCCESS_TEST++ ))
|
(( SUCCESS_TEST++ ))
|
||||||
(( TOTAL_SUCCESS++ ))
|
(( TOTAL_SUCCESS++ ))
|
||||||
else
|
else
|
||||||
echo -e $B_RED"ERROR : line number $LINE_NUMBER"$ENDCO
|
# if -p1..3 print error for command
|
||||||
echo ""
|
if [ $PRINT -eq 1 ]
|
||||||
echo -e $B_MAGENTA"[bash execution] :"$ENDCO
|
then
|
||||||
echo "$@" | bash -i
|
ERROR_CMD="ERROR line $(( $LINE_NUMBER - 1 )), command : "
|
||||||
echo ""
|
print_next_command "$ERROR_CMD" "$@" "$B_RED"
|
||||||
echo -e $B_MAGENTA"[minishell execution] :"$ENDCO
|
elif [ $PRINT -eq 2 ]
|
||||||
echo "$@" | ./minishell
|
then
|
||||||
echo ""
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,9 +221,14 @@
|
|||||||
filename=$i
|
filename=$i
|
||||||
echo -e "\n"$B_YELLOW"test file : $i"$ENDCO
|
echo -e "\n"$B_YELLOW"test file : $i"$ENDCO
|
||||||
command_test=""
|
command_test=""
|
||||||
|
LINE_NUMBER=0
|
||||||
LAST_LINE_NUMBER=$(wc -l < $filename)
|
LAST_LINE_NUMBER=$(wc -l < $filename)
|
||||||
UNIT_TEST=0
|
UNIT_TEST=0
|
||||||
SUCCESS_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
|
while read line
|
||||||
do
|
do
|
||||||
(( LINE_NUMBER++ ))
|
(( LINE_NUMBER++ ))
|
||||||
@@ -246,3 +268,10 @@
|
|||||||
echo ""
|
echo ""
|
||||||
print_results "all" $TOTAL_SUCCESS $TOTAL_TEST
|
print_results "all" $TOTAL_SUCCESS $TOTAL_TEST
|
||||||
fi
|
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
|
||||||
11
tests/unit_tests/ut_bonus.sh
Normal file
11
tests/unit_tests/ut_bonus.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
echo bonjour ; |
|
||||||
|
|
||||||
|
echo bonjour |;
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
echo coucou | ;
|
||||||
|
|
||||||
|
echo ;;
|
||||||
|
|
||||||
|
echo bonjour \; ls
|
||||||
108
tests/unit_tests/ut_builtins.sh
Normal file
108
tests/unit_tests/ut_builtins.sh
Normal 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
|
||||||
|
|
||||||
17
tests/unit_tests/ut_exit_status.sh
Normal file
17
tests/unit_tests/ut_exit_status.sh
Normal 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
|
||||||
|
$?
|
||||||
|
|
||||||
35
tests/unit_tests/ut_expensions.sh
Normal file
35
tests/unit_tests/ut_expensions.sh
Normal 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
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ COMMANDE=' echo "hugo"'
|
|||||||
# EOF'
|
# EOF'
|
||||||
|
|
||||||
#echo "$COMMANDE" | bash -i &>file.log
|
#echo "$COMMANDE" | bash -i &>file.log
|
||||||
echo "$COMMANDE" | ./minishell &>file.log
|
#echo "$COMMANDE" | ./minishell &>file.log
|
||||||
|
|
||||||
#cat << EOF
|
#cat << EOF
|
||||||
#hello
|
#hello
|
||||||
36
tests/unit_tests/ut_pipes.sh
Normal file
36
tests/unit_tests/ut_pipes.sh
Normal 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
|
||||||
|
|
||||||
54
tests/unit_tests/ut_redirections.sh
Normal file
54
tests/unit_tests/ut_redirections.sh
Normal 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
|
||||||
|
|
||||||
11
tests/unit_tests/ut_to_do_manually.sh
Normal file
11
tests/unit_tests/ut_to_do_manually.sh
Normal 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+\
|
||||||
19
tests/unit_tests/ut_vrac.sh
Normal file
19
tests/unit_tests/ut_vrac.sh
Normal 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
|
||||||
|
|
||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user