tests heredocs
This commit is contained in:
@@ -193,7 +193,9 @@ test
|
|||||||
- [process substitution](https://www.gnu.org/software/bash/manual/bash.html#Process-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 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)
|
- [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)
|
- ["\[" vs "\[\[" in bash](https://stackoverflow.com/questions/13542832/difference-between-single-and-double-square-brackets-in-bash)
|
||||||
|
- [redirections in bash](https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean)
|
||||||
|
- [bash variable of variable](https://stackoverflow.com/questions/10757380/bash-variable-variables)
|
||||||
|
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
|
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/02 01:38:22 by lperrey ### ########.fr */
|
/* Updated: 2021/12/03 06:55:40 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -18,7 +18,9 @@ static int init_readline_hook(void);
|
|||||||
int init(t_all *c)
|
int init(t_all *c)
|
||||||
{
|
{
|
||||||
ft_bzero(c, sizeof (*c));
|
ft_bzero(c, sizeof (*c));
|
||||||
|
// rl_instream = stdin;
|
||||||
rl_outstream = stderr;
|
rl_outstream = stderr;
|
||||||
|
// rl_outstream = stdout;
|
||||||
rl_startup_hook = init_readline_hook;
|
rl_startup_hook = init_readline_hook;
|
||||||
readline(NULL);
|
readline(NULL);
|
||||||
rl_startup_hook = NULL;
|
rl_startup_hook = NULL;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/01 14:45:04 by lperrey ### ########.fr */
|
/* Updated: 2021/12/02 17:11:55 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -23,6 +23,9 @@ void shell_loop(t_all *c)
|
|||||||
{
|
{
|
||||||
if (line_input)
|
if (line_input)
|
||||||
free(line_input);
|
free(line_input);
|
||||||
|
// write(2, c->prompt, ft_strlen(c->prompt));
|
||||||
|
// rl_already_prompted = 1;
|
||||||
|
// line_input = read_input(NULL, c);
|
||||||
line_input = read_input(c->prompt, c);
|
line_input = read_input(c->prompt, c);
|
||||||
if (line_input && *line_input)
|
if (line_input && *line_input)
|
||||||
{
|
{
|
||||||
@@ -53,7 +56,7 @@ static char *read_input(char *prompt, t_all *c)
|
|||||||
sigaction(SIGINT, &signal_behaviour, NULL);
|
sigaction(SIGINT, &signal_behaviour, NULL);
|
||||||
if (!line_input)
|
if (!line_input)
|
||||||
{
|
{
|
||||||
write(1, "exit\n", 5);
|
write(2, "exit\n", 5);
|
||||||
exit_free(c, get_last_exit_status());
|
exit_free(c, get_last_exit_status());
|
||||||
}
|
}
|
||||||
return (line_input);
|
return (line_input);
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
cp ../minishell .
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
ENDCO="\001\e[0m\002"
|
|
||||||
|
|
||||||
list_files="\
|
|
||||||
tunit_0.sh"
|
|
||||||
# tunit_1.sh \
|
|
||||||
# tunit_2.sh \
|
|
||||||
# tunit_3.sh \
|
|
||||||
# "
|
|
||||||
|
|
||||||
TOTAL_TEST=0
|
|
||||||
SUCCESS_TEST=0
|
|
||||||
|
|
||||||
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