diff --git a/unitests.sh b/unitests.sh index 28153af..50e8147 100644 --- a/unitests.sh +++ b/unitests.sh @@ -42,6 +42,25 @@ cd $(dirname $0) # copy the executable to current directory cp $MINISHELL . +# to delete the files created during the script + function delete_files + { + files_after="$(ls .)" + diff_files="$(comm -3 <(echo "$FILES_BEFORE") <(echo "$files_after"))" + while read -r line_diff + do + rm -rf "$line_diff" + done < <(echo "$diff_files") + } + +# handle sigint signal + function handler_sigint + { + delete_files + exit 0 + } + trap 'handler_sigint' 2 + # default list of files to be use DEFAULT_FILES="$( find $DEFAULT_DIR | tail -n+2 )" @@ -58,17 +77,6 @@ cd $(dirname $0) echo "" } -# to delete the files created during the script - function delete_files - { - files_after="$(ls .)" - diff_files="$(comm -3 <(echo "$FILES_BEFORE") <(echo "$files_after"))" - while read -r line_diff - do - rm -rf "$line_diff" - done < <(echo "$diff_files") - } - # check for arguments, like options or files list # if no file in arguments, default file list is used function parse_arguments