mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
here_doc: handle input with correct end marker
This commit is contained in:
parent
a6d1386574
commit
7c6d061c6c
8 changed files with 191 additions and 44 deletions
2
tests/here_doc_input_plus_eof.input
Normal file
2
tests/here_doc_input_plus_eof.input
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
input
|
||||
EOF
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/07 11:43:32 by khais #+# #+# */
|
||||
/* Updated: 2025/03/11 11:42:29 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/11 11:44:34 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -68,9 +68,28 @@ static void test_here_doc_only_end_marker(void)
|
|||
do_leak_check();
|
||||
}
|
||||
|
||||
static void test_here_doc_input_plus_end_marker(void)
|
||||
{
|
||||
t_worddesc *marker;
|
||||
int infile;
|
||||
int result;
|
||||
|
||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
||||
marker = worddesc_create(ft_strdup("EOF"), 0, NULL);
|
||||
infile = open("./here_doc_input_plus_eof.input", O_RDONLY);
|
||||
result = here_doc(marker, infile);
|
||||
close(infile);
|
||||
worddesc_destroy(marker);
|
||||
assert(result != -1);
|
||||
assert_strequal("input\n", get_next_line(result));
|
||||
close(result);
|
||||
do_leak_check();
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_here_doc_filename_generation();
|
||||
test_here_doc_invalid_args();
|
||||
test_here_doc_only_end_marker();
|
||||
test_here_doc_input_plus_end_marker();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 15:21:09 by khais #+# #+# */
|
||||
/* Updated: 2025/03/09 12:37:10 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/11 11:46:04 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,9 +17,11 @@ void assert_strequal(char *str1, char *str2)
|
|||
{
|
||||
int ret;
|
||||
|
||||
ret = ft_strcmp(str1, str2);
|
||||
ft_dprintf(STDERR_FILENO, "Expected\t[%s]\n", str1);
|
||||
ft_dprintf(STDERR_FILENO, "to eq \t[%s]\n", str2);
|
||||
if (str1 == str2)
|
||||
return ;
|
||||
ret = ft_strcmp(str1, str2);
|
||||
assert(ret == 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue