mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
here_doc: handle input with only an end marker
This commit is contained in:
parent
442aa85e84
commit
a6d1386574
5 changed files with 54 additions and 12 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/07 11:43:32 by khais #+# #+# */
|
||||
/* Updated: 2025/03/11 11:19:16 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/11 11:42:29 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include "testutil.h"
|
||||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "../src/executing/here_doc/here_doc.h"
|
||||
|
||||
static void test_here_doc_filename_generation(void)
|
||||
|
|
@ -34,15 +35,42 @@ static void test_here_doc_filename_generation(void)
|
|||
do_leak_check();
|
||||
}
|
||||
|
||||
static void test_here_doc_null_args(void)
|
||||
static void test_here_doc_invalid_args(void)
|
||||
{
|
||||
t_worddesc *marker;
|
||||
|
||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
||||
assert(-1 == here_doc(NULL));
|
||||
assert(-1 == here_doc(NULL, 0));
|
||||
marker = worddesc_create(NULL, 0, NULL);
|
||||
assert(-1 == here_doc(marker, 0));
|
||||
worddesc_destroy(marker);
|
||||
marker = worddesc_create(ft_strdup("EOF"), 0, NULL);
|
||||
assert(-1 == here_doc(marker, -1));
|
||||
worddesc_destroy(marker);
|
||||
do_leak_check();
|
||||
}
|
||||
|
||||
static void test_here_doc_only_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_only_eof.input", O_RDONLY);
|
||||
result = here_doc(marker, infile);
|
||||
close(infile);
|
||||
assert(result != -1);
|
||||
assert(NULL == get_next_line(result));
|
||||
close(result);
|
||||
worddesc_destroy(marker);
|
||||
do_leak_check();
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_here_doc_filename_generation();
|
||||
test_here_doc_null_args();
|
||||
test_here_doc_invalid_args();
|
||||
test_here_doc_only_end_marker();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue