mtn trois modes - interactif normal, interactif avec signaux (wip), et script

This commit is contained in:
hugogogo
2021-12-20 12:12:56 +01:00
parent a6a676590a
commit e966ea9670

View File

@@ -39,6 +39,7 @@ cd $(dirname $0)
TOTAL_SUCCESS=0 TOTAL_SUCCESS=0
LINE_NUMBER=0 LINE_NUMBER=0
PRINT=0 PRINT=0
SCRIPT=0
LIST_FILES="" LIST_FILES=""
DEFAULT_FILES="" DEFAULT_FILES=""
DEFAULT_FILES_USAGE="" DEFAULT_FILES_USAGE=""
@@ -84,6 +85,7 @@ cd $(dirname $0)
echo -en $GREEN"\n[options]\n" echo -en $GREEN"\n[options]\n"
echo -en $CYAN"help : print usage\n" echo -en $CYAN"help : print usage\n"
echo -en $CYAN" -p : print tests commands\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 $GREEN"\n[files list ...] if empty, defaults files will be used :\n"
echo -en $CYAN"$DEFAULT_FILES_USAGE" echo -en $CYAN"$DEFAULT_FILES_USAGE"
echo -en $ENDCO"\n" echo -en $ENDCO"\n"
@@ -134,22 +136,29 @@ cd $(dirname $0)
then then
LIST_FILES="$DEFAULT_FILES" LIST_FILES="$DEFAULT_FILES"
break break
else
continue
fi fi
fi elif [ "$file" = "-s" ]
find_path
if [ -e "$file" ]
then then
if [ -n "$LIST_FILES" ] SCRIPT=1
if [ $# -eq 1 ]
then then
LIST_FILES+=$'\n' LIST_FILES="$DEFAULT_FILES"
break
fi fi
LIST_FILES+="$file"
else else
print_usage find_path
echo " <$file> is not a valid file or option, see usage above" if [ -e "$file" ]
exit 0 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 fi
done done
fi fi
@@ -222,8 +231,8 @@ cd $(dirname $0)
done done
} }
# function test minishell in script mode, it cannot handle signals and ctrl-d # function test minishell in interactive mode and handle signals and ctrl-d
function test_minishell_interactif function test_minishell_signals
{ {
# in this order, so that it's not the minishell or bash that goes in background # in this order, so that it's not the minishell or bash that goes in background
bash_execution=$( send_command & bash 2>/dev/null ) bash_execution=$( send_command & bash 2>/dev/null )
@@ -232,8 +241,7 @@ cd $(dirname $0)
rm -rf $CURRENT_D/tmp/* rm -rf $CURRENT_D/tmp/*
} }
# function test minishell in script mode, it cannot handle signals and ctrl-d # function test minishell in script mode
# receive parameters : $1 commands to execute, $2 name of the file
function test_minishell_script function test_minishell_script
{ {
bash_execution=$( echo "$commands" | bash 2>/dev/null ) bash_execution=$( echo "$commands" | bash 2>/dev/null )
@@ -242,6 +250,15 @@ cd $(dirname $0)
rm -rf $CURRENT_D/tmp/* 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 # function that will launch the command in bash and minishell and compare them
# receive parameters : $1 commands to execute, $2 name of the file # receive parameters : $1 commands to execute, $2 name of the file
function test_minishell function test_minishell
@@ -254,9 +271,12 @@ cd $(dirname $0)
# execute commands, and logs results # execute commands, and logs results
if [ "$ROOT" -eq 1 ] if [ "$ROOT" -eq 1 ]
then then
test_minishell_interactif test_minishell_signals
else elif [ "$SCRIPT" -eq 1 ]
then
test_minishell_script test_minishell_script
else
test_minishell_normal
fi fi
# for env, special treatment # for env, special treatment