diff --git a/tests/test.sh b/tests/test.sh index 584a003..17ad827 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,17 +1,36 @@ #!/bin/bash -minishell_output=$(../minishell -c "$1") -minishell_exit_code=$? +compare_shells() { + minishell_output=$(../minishell -c "$1" 2>&1) + minishell_exit_code=$? -bash_output=$(bash -c "$1") -bash_exit_code=$? + bash_output=$(bash -c "$1" 2>&1 | sed 's/ line 1://g') + bash_exit_code=$? -paste <(echo -e "Minishell:\n$minishell_output") <(echo -e "Bash:\n$bash_output") | column -t -s $'\t' -echo "Minishell exit code: $minishell_exit_code" -echo "Bash exit code: $bash_exit_code" + echo -e "\e[33m$1\e[0m" + echo "===================================" -if [ $minishell_exit_code -eq $bash_exit_code ]; then - echo "Exit codes match." -else - echo "Exit codes do not match." -fi \ No newline at end of file + + if [ "$minishell_output" != "$bash_output" ]; then + paste <(echo -e "Minishell:\n$minishell_output" | cat -e) <(echo -e "Bash:\n$bash_output" | cat -e) | column -t -s $'\t' + else + echo -e "\e[32mstdout: Ok!\e[0m" + fi + + if [ $minishell_exit_code -ne $bash_exit_code ]; then + echo "Minishell exit code: $minishell_exit_code" + echo "Bash exit code: $bash_exit_code" + echo "Exit codes do not match." + else + echo -e "\e[32mexit code: Ok!\e[0m" + fi +} + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +while IFS= read -r line; do + compare_shells "$line" +done < "$1" \ No newline at end of file diff --git a/tests/test.txt b/tests/test.txt index 953f1da..7c4a70a 100644 --- a/tests/test.txt +++ b/tests/test.txt @@ -1,85 +1,6 @@ -cd -cd .. -cd . -cd /Users -cd // -cd '//' -cd ////// -cd ./././ -cd / -cd '/etc' -cd '/var' -cd "$PWD/prompt" -cd "doesntexist" -cd "doesntexist" 2>/dev/null -cd ../../.. -cd .. -cd .. -cd ? -cd + -cd _ -cd bark bark -cd '/' -cd $PWD/file_tests -cd $OLDPWD/builtins -echo -echo echo -eCho -eChO -eCHO -echo $ -echo $ $ -ECHO -echo rhobebou -echo stop barking -echo "bonjour" -echo bonjour -echo 'bonjour' -echo -n bonjour -echo -nn bonjour -echo -n -n -n bonjour -echo "-n" bonjour -echo -n"-n" bonjour -echo "-nnnn" bonjour -echo "-nnnn" -n bonjour -echo "-n -n -n"-n bonjour -echo "-n '-n'" bonjour -echo $USER -echo "$USER" -echo "'$USER'" -echo " '$USER' " -echo text"$USER" -echo text"'$USER'" ' $USER ' -echo "text" "$USER" "$USER" -echo ' $USER ' -echo text "$USER" "$USER"text -echo ''''''''''$USER'''''''''' -echo """"""""$USER"""""""" -echo $USER'$USER'text oui oui oui oui $USER oui $USER '' -echo $USER '' $USER $USER '' $USER '' $USER -n $USER -echo ' \' ' \' -echo '\" ' " \"\"" -echo \\\" \\\" \\\" \\\"\\\"\\\" \\\'\\\'\\\' -echo "$USER""$USER""$USER" -echo text"$USER"test -echo '$USER' "$USER" "text \' text" -echo '$USER' -echo $USER " " -echo "$USER""Users/$USER/file""'$USER'"'$USER' -echo "$USER$USER$USER" -echo '$USER'"$USER"'$USER' -echo '"$USER"''$USER'"""$USER" -echo " $USER "'$PWD' -echo " $USER \$ "'$PWD' -echo $USER=4 -echo $USER=thallard -echo $USER -echo $? -echo $PWD/file -echo "$PWD/file" -echo "text" "text$USER" ... "$USER" -echo $PWD + + env | grep "_=" env | grep "_=" env | grep "SHLVL" @@ -111,66 +32,7 @@ ls -la > tmp/file ls -la > tmp/file unset export TEST=100 -unset doesntexist -unset PWD -unset PWD -unset OLDPWD -unset PATH -unset PATH -unset PATH -unset TES\\\\T -unset TES;T -unset TES.T -unset TES+T -unset TES=T -unset TES}T -unset TES{T -unset TES-T -unset -TEST -unset _TEST -unset TES_T -unset TEST_ -unset TE*ST -unset TES#T -unset TES@T -unset TES!T -unset TES$?T -unset ============ -unset +++++++ -unset ________ -unset export -unset echo -unset pwd -unset cd -unset unset -unset sudo -unset TES^T -unset TES!T -unset TES\~T -echo $PWD -echo $PWD|cat -e -echo $PWD hallo | cat -e -echo '$PWD hallo | cat -e' -echo "$PWD hallo | cat -e" -wc < Makefile -l | cat -e > outfile | echo hello | rev > outfile2 -< test.txt < Makefile out | < README.md cat -e -< README.md cat -e | out1 | < in2 cat -env | rev | head -5 | cat -e | rev -< in1 out > out2 > out3 >> out4 -echo ok"hello"ok1"mfg" == echo ok'hello'ok1'mfg' -echo okhellook1"mfg" == echo okhellook1'mfg' -echo "o""k "hellook1 == echo 'o''k 'hellook1 -echo '"***hello***"' -echo "'***hello***'" -echo ok"'hello'"ok1"hello1"ok2 -echo "text" "$USER" "$USER" -echo """"""""$USER"""""""" -echo "-n -n -n"-n bonjour -echo "'$USER'" -echo "$PWD "a -echo " $PWD" + + exit diff --git a/tests/test_cd.txt b/tests/test_cd.txt new file mode 100644 index 0000000..a38a482 --- /dev/null +++ b/tests/test_cd.txt @@ -0,0 +1,25 @@ +cd ; pwd +cd .. ; pwd +cd . ; pwd +cd /Users ; pwd +cd // ; pwd +cd '//' ; pwd +cd ////// ; pwd +cd ./././ ; pwd +cd / ; pwd +cd '/etc' ; pwd +cd '/var' ; pwd +cd "$PWD/prompt" ; pwd +cd "doesntexist" ; pwd +cd "doesntexist" 2>/dev/null ; pwd +cd ../../.. ; pwd +cd .. ; pwd +cd .. ; pwd +cd ? ; pwd +cd + ; pwd +cd _ ; pwd +cd bark bark ; pwd +cd '/' ; pwd +cd $PWD/file_tests ; pwd +cd $OLDPWD/builtins ; pwd +cd ~ ; pwd \ No newline at end of file diff --git a/tests/test_echo.txt b/tests/test_echo.txt new file mode 100644 index 0000000..40fb2f9 --- /dev/null +++ b/tests/test_echo.txt @@ -0,0 +1,81 @@ +echo +echo echo +eCho +eChO +eCHO +echo $ +echo $ $ +ECHO +echo rhobebou +echo stop barking +echo "bonjour" +echo bonjour +echo 'bonjour' +echo -n bonjour +echo -nn bonjour +echo -n -n -n bonjour +echo "-n" bonjour +echo -n"-n" bonjour +echo "-nnnn" bonjour +echo "-nnnn" -n bonjour +echo "-n -n -n"-n bonjour +echo "-n '-n'" bonjour +echo $USER +echo "$USER" +echo "'$USER'" +echo " '$USER' " +echo text"$USER" +echo text"'$USER'" ' $USER ' +echo "text" "$USER" "$USER" +echo ' $USER ' +echo text "$USER" "$USER"text +echo ''''''''''$USER'''''''''' +echo """"""""$USER"""""""" +echo $USER'$USER'text oui oui oui oui $USER oui $USER '' +echo $USER '' $USER $USER '' $USER '' $USER -n $USER +echo ' \' ' \' +echo '\" ' " \"\"" +echo \\\" \\\" \\\" \\\"\\\"\\\" \\\'\\\'\\\' +echo "$USER""$USER""$USER" +echo text"$USER"test +echo '$USER' "$USER" "text \' text" +echo '$USER' +echo $USER " " +echo "$USER""Users/$USER/file""'$USER'"'$USER' +echo "$USER$USER$USER" +echo '$USER'"$USER"'$USER' +echo '"$USER"''$USER'"""$USER" +echo " $USER "'$PWD' +echo " $USER \$ "'$PWD' +echo $USER=4 +echo $USER=thallard +echo $USER +echo $? +echo $PWD/file +echo "$PWD/file" +echo "text" "text$USER" ... "$USER" +echo $PWD +echo $PWD|cat -e +echo $PWD hallo | cat -e +echo '$PWD hallo | cat -e' +echo "$PWD hallo | cat -e" +wc < Makefile -l | cat -e > outfile | echo hello | rev > outfile2 +< test.txt < Makefile out | < README.md cat -e +< README.md cat -e | out1 | < in2 cat +env | rev | head -5 | cat -e | rev +< in1 out > out2 > out3 >> out4 +echo ok"hello"ok1"mfg" == echo ok'hello'ok1'mfg' +echo okhellook1"mfg" == echo okhellook1'mfg' +echo "o""k "hellook1 == echo 'o''k 'hellook1 +echo '"***hello***"' +echo "'***hello***'" +echo ok"'hello'"ok1"hello1"ok2 +echo "text" "$USER" "$USER" +echo """"""""$USER"""""""" +echo "-n -n -n"-n bonjour +echo "'$USER'" +echo "$PWD "a +echo " $PWD" \ No newline at end of file diff --git a/tests/test_env.txt b/tests/test_env.txt new file mode 100644 index 0000000..2c9f94f --- /dev/null +++ b/tests/test_env.txt @@ -0,0 +1,3 @@ +env | grep "_=" +env | grep "_=" +env | grep "SHLVL" \ No newline at end of file diff --git a/tests/test_exit.txt b/tests/test_exit.txt deleted file mode 100644 index 39e3906..0000000 --- a/tests/test_exit.txt +++ /dev/null @@ -1,2 +0,0 @@ -echo "yeah" -exit diff --git a/tests/export_test.txt b/tests/test_export.txt similarity index 100% rename from tests/export_test.txt rename to tests/test_export.txt diff --git a/tests/test_unset.txt b/tests/test_unset.txt new file mode 100644 index 0000000..679c0c1 --- /dev/null +++ b/tests/test_unset.txt @@ -0,0 +1,36 @@ +unset doesntexist +unset PWD +unset PWD +unset OLDPWD +unset PATH +unset PATH +unset PATH +unset TES\\\\T +unset TES;T +unset TES.T +unset TES+T +unset TES=T +unset TES}T +unset TES{T +unset TES-T +unset -TEST +unset _TEST +unset TES_T +unset TEST_ +unset TE*ST +unset TES#T +unset TES@T +unset TES!T +unset TES$?T +unset ============ +unset +++++++ +unset ________ +unset export +unset echo +unset pwd +unset cd +unset unset +unset sudo +unset TES^T +unset TES!T +unset TES\~T \ No newline at end of file