oubli while_clause and tk_paren_open close #188

This commit is contained in:
Antoine Riard 2017-03-24 19:17:40 +01:00
parent d3324cacd6
commit 890fdd1511
6 changed files with 36 additions and 236 deletions

View file

@ -1,235 +1,5 @@
.x....................xxx...xxxx..x.
----------------------------------------------------------------
21sh/misc/002-simple-command-line (FAILED)
Description:
 The purpose of this test is to check that the Shell is able to execute a simple command line that contains separators `;`, pipes `|`, and a right redirection `>`.
Before test:
 01: rm -rf "./size"
02: rm -rf "TOKEN201703241733"
03: echo '^'$(echo TOKEN201703241733_FILE_TOKEN201703241733_STDOUT | wc -c)'$' > "./size"
STDIN:
 01: mkdir TOKEN201703241733 ; cd TOKEN201703241733 ; touch TOKEN201703241733_FILE ; ls -1 ; ls | cat | wc -c > TOKEN201703241733_STDOUT ; cat TOKEN201703241733_STDOUT
STDOUT:
 SUCCESS expected_to match_regex `TOKEN201703241733_FILE$`
 FAILURE expected_to match_each_regex_of_file `./size`
 01: TOKEN201703241733_FILE
02: 94296 redirect_great.c 24 3 1
03: 23
STDERR:
 SUCCESS expected_to be_empty
 (no output)
----------------------------------------------------------------
21sh/redirections/outputs/truncating/001-creates-file-if-not-exits (FAILED)
Description:
 The right redirection `>` opens the file with the oflag `O_CREAT` so that the file is created if it does not exists.
Before test:
 01: rm -f new_file
STDIN:
 01: ./write_on_stdout TOKEN201703241733 >new_file
STDOUT:
 SUCCESS expected_to_not match_regex `TOKEN201703241733`
 (no output)
STDERR:
 SUCCESS expected_to be_empty
 (no output)
MISC:
 SUCCESS expected_to create_file `new_file` matching_regex `TOKEN201703241733`
 FAILURE expected_to create_file `new_file` with_nb_of_lines `1`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/002-truncates-file-if-exists (FAILED)
Description:
 The right redirection `>` opens the file with the oflag `O_TRUNC` so that the file size is truncated to 0 before writing in it.
Before test:
 01: ./write_on_stdout TOKEN201703241733_first >truncated_file
STDIN:
 01: ./write_on_stdout TOKEN201703241733_second >truncated_file
STDOUT:
 SUCCESS expected_to_not match_regex TOKEN201703241733_second
 (no output)
STDERR:
 SUCCESS expected_to be_empty
 (no output)
MISC:
 SUCCESS expected_to create_file `truncated_file` matching_regex `TOKEN201703241733_second`
 SUCCESS expected_to create_file `truncated_file` not_matching_regex `TOKEN201703241733_first`
 FAILURE expected_to create_file `truncated_file` with_nb_of_lines `1`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/003-whitespace-before-filename (FAILED)
Description:
 The file name for a right redirection can be specified closely to the character `>` or in a separated field.
Before test:
 01: rm -f "new_file"
STDIN:
 01: ./write_on_stdout TOKEN201703241733 > new_file
STDOUT:
 SUCCESS expected_to_not match_regex `TOKEN201703241733`
 (no output)
STDERR:
 SUCCESS expected_to be_empty
 (no output)
MISC:
 SUCCESS expected_to create_file `new_file` matching_regex `TOKEN201703241733`
 FAILURE expected_to create_file `new_file` with_nb_of_lines `1`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/multiple/004-together (FAILED)
Description:
 A right redirection can be associated to the twice outputs by using `&>...`, that means `redirect stdout and stderr to ...`.
Before test:
 01: rm -f "new_file_stderr_and_stdout"
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703241733_1 TOKEN201703241733_2 &>new_file_stderr_and_stdout
STDOUT:
 FAILURE expected_to_not match_regex `TOKEN201703241733_1`
 SUCCESS expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_1
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703241733_1`
 FAILURE expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_2
MISC:
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_1$`
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_2$`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/multiple/005-together-with-whitespaces (FAILED)
Description:
 A right redirection can be associated to the twice outputs by using `&>...`, that means `redirect stdout and stderr to ...`.
In this test, we specify the file name in a separate field.
Before test:
 01: rm -f new_file_stderr_and_stdout
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703241733_1 TOKEN201703241733_2 &> new_file_stderr_and_stdout
STDOUT:
 FAILURE expected_to_not match_regex `TOKEN201703241733_1`
 SUCCESS expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_1
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703241733_1`
 FAILURE expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_2
MISC:
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_1$`
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_2$`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/stderr/001-works (FAILED)
Description:
 The purpose of this test is to check that redirecting the standard error STDERR to a file `2>` works. In this test, the binary writes a token on each standard and error output, so that only the STDOUT is outputted and STDERR is written in a file `new_file_stderr`.
Before test:
 01: rm -f "./new_file_stderr"
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703241733_STDOUT TOKEN201703241733_STDERR 2>new_file_stderr
STDOUT:
 SUCCESS expected_to match_regex `TOKEN201703241733_STDOUT`
 01: TOKEN201703241733_STDOUT
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703241733_STDERR`
 (no output)
MISC:
 SUCCESS expected_to create_file `new_file_stderr` matching_regex `TOKEN201703241733_STDERR`
 FAILURE expected_to create_file `new_file_stderr` with_nb_of_lines 1
----------------------------------------------------------------
21sh/redirections/outputs/truncating/stdout/001-with-explicit-fd (FAILED)
Description:
 The purpose of this test is to check if '1>' redirect STDIN to a file.
We are using echo with one argument. The output should NOT return anything on the standard output.
Before test:
 01: rm -f new_file
STDIN:
 01: /bin/echo TOKEN1 1>new_file
STDOUT:
 SUCCESS expected_to_not match_regex TOKEN1
 (no output)
STDERR:
 (no output)
MISC:
 SUCCESS expected_to create_file new_file matching_regex TOKEN1
 FAILURE expected_to create_file new_file with_nb_of_lines 1
----------------------------------------------------------------
21sh/separators/semicolon/003-parse-error-empty-inline-command (FAILED)
Description:
 The purpose of this test is to check that using the simicolon separator `;` with empty commands results in error.
STDIN:
 01: ./write_on_stdout TOKEN201703241733 ; ; ./exit_with_status 42
STDOUT:
 SUCCESS expected_to be_empty
 (no output)
STDERR:
 SUCCESS expected_to_not be_empty
 SUCCESS might match_regex `([Ss]yntax|[Pp]arse) error`
 01: syntax error near unexpected token `;'
MISC:
 SUCCESS expected_to_not exit_with_status `42`
 FAILURE expected_to_not exit_with_status `0`
....................................
Total tests: 36
Total failed tests: 9
Total failed tests: 0
Total pending tests: 0

23
42sh/VAR Normal file
View file

@ -0,0 +1,23 @@
$TOKEN201703241737_NAME
21sh_error
42ShellTester
42sh
42sh_error
Makefile
README.md
STDBUG
VAR
auteur
donovan_segaults_06-02
file
includes
libft
minishell_error
new_file
objs
pdf
sample
scriptheader.sh
src
update_makefile.sh
write_on_stdout_and_stderr

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 17:24:09 by gwojda ### ########.fr */
/* Updated: 2017/03/24 18:59:40 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,6 +20,7 @@ void token_print(t_list *lst)
{
if (lst->content)
token = lst->content;
DG("%s", read_state(token->type));
lst = lst->next;
}
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/24 17:24:04 by gwojda ### ########.fr */
/* Updated: 2017/03/24 18:58:30 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,6 +43,7 @@ static int handle_instruction(t_list **token, t_btree **ast)
return (ret);
if (do_lexer_routine(token, stream) > 0)
continue ;
token_print(*token);
if ((ret = do_parser_routine(token, ast)) == 1
&& SH_NO_INTERACTIVE(data->opts))
return (ret);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
/* Updated: 2017/03/24 17:23:26 by gwojda ### ########.fr */
/* Updated: 2017/03/24 19:09:05 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -380,15 +380,18 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
return (1);
i = -1;
head = (*stack)->content;
DG("aggregate head %s && sym %s", read_state(*head), read_state(*new_sym));
while (g_aggrematch[++i].top)
if (*new_sym == g_aggrematch[i].top
&& MATCH_STACK(*head, g_aggrematch[i].under))
{
DG("MATH: %s", read_state(g_aggrematch[i].new_sym));
*new_sym = g_aggrematch[i].new_sym;
if (g_aggrematch[i].erase_sym)
{
pop_stack(stack, g_aggrematch[i].erase_sym);
head = (*stack)->content;
DG("stack after pop %s", read_state(*head));
}
if (eval_sym(stack, *new_sym) && !(*state = ERROR))
return (1);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
/* Updated: 2017/03/24 17:23:52 by gwojda ### ########.fr */
/* Updated: 2017/03/24 19:11:10 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -905,6 +905,7 @@ static t_stackmatch g_stackmatch[] =
{WHILE_CLAUSE, NEWLINE_LIST},
{WHILE_CLAUSE, SEQUENCE},
{WHILE_CLAUSE, TK_DO},
{WHILE_CLAUSE, TK_PAREN_OPEN},
{WHILE_CLAUSE, TK_PAREN_CLOSE},
{WHILE_CLAUSE, TK_WHILE},
{WHILE_CLAUSE, TK_LBRACE},
@ -1287,6 +1288,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
return (1);
head = (*stack)->content;
i = 0;
DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
while (g_stackmatch[i].top)
{
if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under)