test unitaire avance
This commit is contained in:
11
README.md
11
README.md
@@ -183,6 +183,17 @@ test
|
||||
- [exit code status](https://tldp.org/LDP/abs/html/exitcodes.html)
|
||||
- [`char **s` vs `char *s[]`](https://stackoverflow.com/questions/46830654/what-is-the-difference-between-extern-char-environ-and-extern-char-environ)
|
||||
- [extern and global](https://stackoverflow.com/questions/2652545/extern-and-global-in-c)
|
||||
- [on which stream deos bash redirect its prompt](https://unix.stackexchange.com/questions/20826/which-stream-does-bash-write-its-prompt-to)
|
||||
- [fd redirections &](https://putaindecode.io/articles/maitriser-les-redirections-shell)
|
||||
- [fd redirections &-](https://wiki.bash-hackers.org/howto/redirection_tutorial)
|
||||
- [redirect prompt output](https://stackoverflow.com/questions/2559076/how-do-i-redirect-output-to-a-variable-in-shell)
|
||||
- [read, pipes, process substitution](https://stackoverflow.com/questions/15184358/how-to-avoid-bash-command-substitution-to-remove-the-newline-character)
|
||||
- [process substitution](https://www.linuxjournal.com/content/shell-process-redirection)
|
||||
- [read, IFS](https://unix.stackexchange.com/questions/164508/why-do-newline-characters-get-lost-when-using-command-substitution)
|
||||
- [process substitution](https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution)
|
||||
- [send one command to two pipes](https://stackoverflow.com/questions/13107783/pipe-output-to-two-different-commands)
|
||||
- [send two commands to one pipe](https://askubuntu.com/questions/133386/how-to-merge-and-pipe-results-from-two-different-commands-to-single-command)
|
||||
- ["[" vs "[[" in bash](https://stackoverflow.com/questions/13542832/difference-between-single-and-double-square-brackets-in-bash)
|
||||
|
||||
|
||||
```text
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/25 22:21:16 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/11/26 15:03:37 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -82,8 +82,8 @@ static int here_doc_write(char *delimiter, int doc_fd)
|
||||
signal_action.sa_handler = sigint_handler_heredoc;
|
||||
sigaction(SIGINT, &signal_action, NULL);
|
||||
switch_heredoc_sigint = 0;
|
||||
//rl_event_hook = void_func_return_readline;
|
||||
rl_signal_event_hook = void_func_return_readline;
|
||||
rl_event_hook = void_func_return_readline;
|
||||
//rl_signal_event_hook = void_func_return_readline;
|
||||
line_count = 0;
|
||||
while (1)
|
||||
{
|
||||
@@ -114,6 +114,8 @@ static int here_doc_write(char *delimiter, int doc_fd)
|
||||
free(line);
|
||||
}
|
||||
free(line);
|
||||
signal_action.sa_handler = SIG_IGN;
|
||||
sigaction(SIGINT, &signal_action, NULL);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,118 @@
|
||||
#!/bin/bash
|
||||
|
||||
#bash -i &> file.log
|
||||
#exit
|
||||
cp ../minishell .
|
||||
|
||||
#myoutput=$(echo "echo hello ; exit" | bash -i)
|
||||
RED="\001\e[0;31m\002"
|
||||
GREEN="\001\e[0;32m\002"
|
||||
YELLOW="\001\e[0;33m\002"
|
||||
BLUE="\001\e[0;34m\002"
|
||||
MAGENTA="\001\e[0;35m\002"
|
||||
CYAN="\001\e[0;36m\002"
|
||||
WHITE="\001\e[0;37m\002"
|
||||
|
||||
#echo "follow\n"
|
||||
#echo $myoutput
|
||||
B_RED="\001\e[1;31m\002"
|
||||
B_GREEN="\001\e[1;32m\002"
|
||||
B_YELLOW="\001\e[1;33m\002"
|
||||
B_BLUE="\001\e[1;34m\002"
|
||||
B_MAGENTA="\001\e[1;35m\002"
|
||||
B_CYAN="\001\e[1;36m\002"
|
||||
B_WHITE="\001\e[1;37m\002"
|
||||
|
||||
#echo "echo hello" | (bash -i &>file.log)
|
||||
#echo hello
|
||||
#exit
|
||||
ENDCO="\001\e[0m\002"
|
||||
|
||||
#echo "echo hello" | bash -i 2>&1 | \
|
||||
#(
|
||||
# read myoutput;
|
||||
# echo "myoutput :\n";
|
||||
# echo $myoutput;
|
||||
#)
|
||||
list_files="\
|
||||
tunit_0.sh"
|
||||
# tunit_1.sh \
|
||||
# tunit_2.sh \
|
||||
# tunit_3.sh \
|
||||
# "
|
||||
|
||||
#myoutput=$(echo "echo hello" | bash -i 2>&1 | (read foo; echo $foo))
|
||||
TOTAL_TEST=0
|
||||
SUCCESS_TEST=0
|
||||
|
||||
myoutput=$( (echo "echo hello" ; echo "echo hugo") | bash -i 2>&1)
|
||||
echo "myoutput :"
|
||||
echo "$myoutput"
|
||||
function test_bash
|
||||
{
|
||||
# execute commands in bash and minishell
|
||||
bash_execution=$( echo "$@" | bash -i 2>&1 )
|
||||
minishell_execution=$( echo "$@" | ./minishell )
|
||||
#echo "minishell_execution :"
|
||||
#echo "$minishell_execution"
|
||||
#echo "$minishell_execution" | cat -e
|
||||
echo "bash_execution :"
|
||||
echo "$bash_execution"
|
||||
echo "$bash_execution" | cat -e
|
||||
echo ""
|
||||
|
||||
# extract informations
|
||||
first_command=$( head -1 <<< "$@" )
|
||||
echo "first_command:"
|
||||
echo "$first_command"
|
||||
echo ""
|
||||
|
||||
#f_cmd_length=${#first_command}
|
||||
#bash_prompt=$( head -1 <<< "$bash_execution" | sed "s/${first_command}//g")
|
||||
bash_prompt=$( head -1 <<< "$bash_execution")
|
||||
#bash_prompt=${bash_prompt::-$f_cmd_length}
|
||||
echo "bash_prompt :"
|
||||
echo "$bash_prompt"
|
||||
echo "$bash_prompt" | cat -e
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
myoutput=$( grep -v "simplonco" <<< "$bash_execution" )
|
||||
echo "myoutput :"
|
||||
echo "$myoutput"
|
||||
echo ""
|
||||
|
||||
((SUCCESS_TEST++))
|
||||
}
|
||||
|
||||
function print_results
|
||||
{
|
||||
if [ $SUCCESS_TEST -eq 0 ]
|
||||
then
|
||||
echo -en $B_RED $SUCCESS_TEST $ENDCO
|
||||
elif [ $SUCCESS_TEST -eq $TOTAL_TEST ]
|
||||
then
|
||||
echo -en $B_GREEN $SUCCESS_TEST $ENDCO
|
||||
else
|
||||
echo -en $B_MAGENTA $SUCCESS_TEST $ENDCO
|
||||
fi
|
||||
echo -e $B_WHITE"/ $TOTAL_TEST"$ENDCO
|
||||
}
|
||||
|
||||
# parse tests files line by line, grouping lines non-separated by an empty line
|
||||
for i in $list_files
|
||||
do
|
||||
filename=$i
|
||||
echo -e "\n"$B_YELLOW"test file : $i"$ENDCO
|
||||
command_test=""
|
||||
last_line="$(tail -1 $i)"
|
||||
((TOTAL_TEST=0))
|
||||
((SUCCESS_TEST=0))
|
||||
while read line
|
||||
do
|
||||
if [ "$line" != "" ]
|
||||
then
|
||||
if [ "$command_test" == "" ]
|
||||
then
|
||||
command_test="$line"
|
||||
else
|
||||
command_test+=$'\n'
|
||||
command_test+="$line"
|
||||
fi
|
||||
if [ "$line" == "$last_line" ]
|
||||
then
|
||||
((TOTAL_TEST++))
|
||||
test_bash "$command_test"
|
||||
fi
|
||||
elif [ "$command_test" != "" ]
|
||||
then
|
||||
((TOTAL_TEST++))
|
||||
test_bash "$command_test"
|
||||
command_test=""
|
||||
fi
|
||||
done < $filename
|
||||
print_results
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user