From e966ea9670f68a6c8dd26d543a0232c204346dee Mon Sep 17 00:00:00 2001 From: hugogogo Date: Mon, 20 Dec 2021 12:12:56 +0100 Subject: [PATCH] mtn trois modes - interactif normal, interactif avec signaux (wip), et script --- unitests.sh | 54 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/unitests.sh b/unitests.sh index b259faf..c3376a6 100644 --- a/unitests.sh +++ b/unitests.sh @@ -39,6 +39,7 @@ cd $(dirname $0) TOTAL_SUCCESS=0 LINE_NUMBER=0 PRINT=0 + SCRIPT=0 LIST_FILES="" DEFAULT_FILES="" DEFAULT_FILES_USAGE="" @@ -84,6 +85,7 @@ cd $(dirname $0) echo -en $GREEN"\n[options]\n" echo -en $CYAN"help : print usage\n" echo -en $CYAN" -p : print tests commands\n" + echo -en $CYAN" -s : test in script, not interactif\n" echo -en $GREEN"\n[files list ...] if empty, defaults files will be used :\n" echo -en $CYAN"$DEFAULT_FILES_USAGE" echo -en $ENDCO"\n" @@ -134,22 +136,29 @@ cd $(dirname $0) then LIST_FILES="$DEFAULT_FILES" break - else - continue fi - fi - find_path - if [ -e "$file" ] + elif [ "$file" = "-s" ] then - if [ -n "$LIST_FILES" ] + SCRIPT=1 + if [ $# -eq 1 ] then - LIST_FILES+=$'\n' + LIST_FILES="$DEFAULT_FILES" + break fi - LIST_FILES+="$file" else - print_usage - echo " <$file> is not a valid file or option, see usage above" - exit 0 + find_path + if [ -e "$file" ] + then + if [ -n "$LIST_FILES" ] + then + LIST_FILES+=$'\n' + fi + LIST_FILES+="$file" + else + print_usage + echo " <$file> is not a valid file or option, see usage above" + exit 0 + fi fi done fi @@ -222,8 +231,8 @@ cd $(dirname $0) done } -# function test minishell in script mode, it cannot handle signals and ctrl-d - function test_minishell_interactif +# function test minishell in interactive mode and handle signals and ctrl-d + function test_minishell_signals { # in this order, so that it's not the minishell or bash that goes in background bash_execution=$( send_command & bash 2>/dev/null ) @@ -232,8 +241,7 @@ cd $(dirname $0) rm -rf $CURRENT_D/tmp/* } -# function test minishell in script mode, it cannot handle signals and ctrl-d -# receive parameters : $1 commands to execute, $2 name of the file +# function test minishell in script mode function test_minishell_script { bash_execution=$( echo "$commands" | bash 2>/dev/null ) @@ -242,6 +250,15 @@ cd $(dirname $0) rm -rf $CURRENT_D/tmp/* } +# function test minishell in interactiv mode, but cannot handle signals and ctrl-d + function test_minishell_normal + { + bash_execution=$( bash <<<"$commands" 2>/dev/null ) + rm -rf $CURRENT_D/tmp/* + minishell_execution=$( $CURRENT_D/minishell <<<"$commands" 2>/dev/null ) + rm -rf $CURRENT_D/tmp/* + } + # function that will launch the command in bash and minishell and compare them # receive parameters : $1 commands to execute, $2 name of the file function test_minishell @@ -254,9 +271,12 @@ cd $(dirname $0) # execute commands, and logs results if [ "$ROOT" -eq 1 ] then - test_minishell_interactif - else + test_minishell_signals + elif [ "$SCRIPT" -eq 1 ] + then test_minishell_script + else + test_minishell_normal fi # for env, special treatment