From 131ba36d935f596726e98d5d4d14686e60d3d54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 18 Mar 2025 14:55:58 +0100 Subject: [PATCH] cmdlist refactor: use cmdlist instead of command_list as a shorthand I hope this doesn't break too much code ^^ --- Makefile | 8 +-- src/parser/cmdgroup/cmdgroup.h | 4 +- .../command_list.c => cmdlist/cmdlist.c} | 12 ++-- .../command_list.h => cmdlist/cmdlist.h} | 12 ++-- .../cmdlist_builder.c} | 16 ++--- .../cmdlist_builder.h} | 12 ++-- .../cmdlist_item.c} | 6 +- .../cmdlist_item.h} | 12 ++-- .../cmdlist_item_type.h} | 10 +-- .../{command_list => cmdlist}/operator.c | 0 .../{command_list => cmdlist}/operator.h | 0 tests/Makefile | 4 +- .../{parse_command_list.c => parse_cmdlist.c} | 8 +-- .../{parse_command_list.h => parse_cmdlist.h} | 14 ++--- tests/test_cmdlist_use_after_free.c | 4 +- ..._command_lists.c => test_parse_cmdlists.c} | 62 +++++++++---------- tests/testutil.c | 8 +-- tests/testutil.h | 4 +- 18 files changed, 98 insertions(+), 98 deletions(-) rename src/parser/{command_list/command_list.c => cmdlist/cmdlist.c} (92%) rename src/parser/{command_list/command_list.h => cmdlist/cmdlist.h} (91%) rename src/parser/{command_list/command_list_builder.c => cmdlist/cmdlist_builder.c} (85%) rename src/parser/{command_list/command_list_builder.h => cmdlist/cmdlist_builder.h} (85%) rename src/parser/{command_list/command_list_item.c => cmdlist/cmdlist_item.c} (88%) rename src/parser/{command_list/command_list_item.h => cmdlist/cmdlist_item.h} (81%) rename src/parser/{command_list/command_list_item_type.h => cmdlist/cmdlist_item_type.h} (79%) rename src/parser/{command_list => cmdlist}/operator.c (100%) rename src/parser/{command_list => cmdlist}/operator.h (100%) rename tests/{parse_command_list.c => parse_cmdlist.c} (83%) rename tests/{parse_command_list.h => parse_cmdlist.h} (70%) rename tests/{test_parse_command_lists.c => test_parse_cmdlists.c} (65%) diff --git a/Makefile b/Makefile index ec182c8..360d167 100644 --- a/Makefile +++ b/Makefile @@ -31,10 +31,10 @@ srcs = \ src/ft_errno.c \ src/get_command.c \ src/parser/cmdgroup/cmdgroup.c \ - src/parser/command_list/command_list_builder.c \ - src/parser/command_list/command_list.c \ - src/parser/command_list/command_list_item.c \ - src/parser/command_list/operator.c \ + src/parser/cmdlist/cmdlist_builder.c \ + src/parser/cmdlist/cmdlist.c \ + src/parser/cmdlist/cmdlist_item.c \ + src/parser/cmdlist/operator.c \ src/parser/matchers/blank.c \ src/parser/matchers/identifier.c \ src/parser/matchers/metacharacter.c \ diff --git a/src/parser/cmdgroup/cmdgroup.h b/src/parser/cmdgroup/cmdgroup.h index 3a65b03..ad0a9c6 100644 --- a/src/parser/cmdgroup/cmdgroup.h +++ b/src/parser/cmdgroup/cmdgroup.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/11 15:11:57 by khais #+# #+# */ -/* Updated: 2025/03/18 12:27:27 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:03:31 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ # define CMDGROUP_H # include "../wordlist/wordlist.h" -# include "../command_list/command_list.h" +# include "../cmdlist/cmdlist.h" # include "../../buffer/buffer.h" /* diff --git a/src/parser/command_list/command_list.c b/src/parser/cmdlist/cmdlist.c similarity index 92% rename from src/parser/command_list/command_list.c rename to src/parser/cmdlist/cmdlist.c index 7f93895..cb66ab2 100644 --- a/src/parser/command_list/command_list.c +++ b/src/parser/cmdlist/cmdlist.c @@ -1,19 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* command_list.c :+: :+: :+: */ +/* cmdlist.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:49:46 by khais #+# #+# */ -/* Updated: 2025/03/18 14:43:39 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:02:38 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#include "command_list.h" -#include "command_list_item.h" -#include "command_list_builder.h" -#include "command_list_item_type.h" +#include "cmdlist.h" +#include "cmdlist_item.h" +#include "cmdlist_builder.h" +#include "cmdlist_item_type.h" #include "operator.h" #include "libft.h" #include diff --git a/src/parser/command_list/command_list.h b/src/parser/cmdlist/cmdlist.h similarity index 91% rename from src/parser/command_list/command_list.h rename to src/parser/cmdlist/cmdlist.h index f64bc90..c4c1f9e 100644 --- a/src/parser/command_list/command_list.h +++ b/src/parser/cmdlist/cmdlist.h @@ -1,17 +1,17 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* command_list.h :+: :+: :+: */ +/* cmdlist.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:45:01 by khais #+# #+# */ -/* Updated: 2025/03/18 12:59:56 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:10:28 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef COMMAND_LIST_H -# define COMMAND_LIST_H +#ifndef CMDLIST_H +# define CMDLIST_H # include "../wordlist/wordlist.h" # include "../pipeline/pipeline.h" @@ -81,11 +81,11 @@ typedef struct s_cmdlist ** ** In example above, operators[1] == OP_END */ - t_operator *operators; + t_operator *operators; } t_cmdlist; t_cmdlist *cmdlist_from_wordlist(const t_wordlist *wordlist); void cmdlist_destroy(t_cmdlist *cmd); void cmdlist_debug(t_cmdlist *cmd, t_buffer **indent, bool is_last); -#endif // COMMAND_LIST_H +#endif // CMDLIST_H diff --git a/src/parser/command_list/command_list_builder.c b/src/parser/cmdlist/cmdlist_builder.c similarity index 85% rename from src/parser/command_list/command_list_builder.c rename to src/parser/cmdlist/cmdlist_builder.c index 2115cad..bd45e7e 100644 --- a/src/parser/command_list/command_list_builder.c +++ b/src/parser/cmdlist/cmdlist_builder.c @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* command_list_builder.c :+: :+: :+: */ +/* cmdlist_builder.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/26 13:51:18 by khais #+# #+# */ -/* Updated: 2025/03/18 13:31:57 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:03:41 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#include "command_list_builder.h" +#include "cmdlist_builder.h" #include "libft.h" /* @@ -21,7 +21,7 @@ ** Does not do error checking about repeated operators, or operators in the ** wrong place. */ -static int command_list_count_pipelines(t_wordlist *words) +static int cmdlist_count_pipelines(t_wordlist *words) { t_wordlist *current_word; int count; @@ -40,11 +40,11 @@ static int command_list_count_pipelines(t_wordlist *words) } /* -** Allocate memory for a new command_list, given the input word stream. +** Allocate memory for a new cmdlist, given the input word stream. ** ** Handles malloc error. */ -static t_cmdlist *allocate_command_list(t_wordlist *words) +static t_cmdlist *allocate_cmdlist(t_wordlist *words) { t_cmdlist *output; @@ -53,7 +53,7 @@ static t_cmdlist *allocate_command_list(t_wordlist *words) output = ft_calloc(1, sizeof(t_cmdlist)); if (output == NULL) return (NULL); - output->num_cmds = command_list_count_pipelines(words); + output->num_cmds = cmdlist_count_pipelines(words); output->cmds = ft_calloc(output->num_cmds, sizeof(struct s_cmdlist_item **)); if (output->cmds == NULL) @@ -74,7 +74,7 @@ t_cmdlist_builder *setup_cmdlist_builder( t_wordlist **words) { ft_bzero(builder, sizeof(t_cmdlist_builder)); - builder->cmdlist = allocate_command_list(*words); + builder->cmdlist = allocate_cmdlist(*words); if (builder->cmdlist == NULL) return (NULL); builder->current_wordlist = NULL; diff --git a/src/parser/command_list/command_list_builder.h b/src/parser/cmdlist/cmdlist_builder.h similarity index 85% rename from src/parser/command_list/command_list_builder.h rename to src/parser/cmdlist/cmdlist_builder.h index ace809a..7a7f0e2 100644 --- a/src/parser/command_list/command_list_builder.h +++ b/src/parser/cmdlist/cmdlist_builder.h @@ -1,19 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* command_list_builder.h :+: :+: :+: */ +/* cmdlist_builder.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/26 13:50:25 by khais #+# #+# */ -/* Updated: 2025/03/18 12:59:57 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:02:53 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef COMMAND_LIST_BUILDER_H -# define COMMAND_LIST_BUILDER_H +#ifndef CMDLIST_BUILDER_H +# define CMDLIST_BUILDER_H -# include "command_list.h" +# include "cmdlist.h" typedef struct s_cmdlist_builder { @@ -49,4 +49,4 @@ void cmdlist_builder_next_word( t_cmdlist_builder *builder, t_wordlist **words); -#endif // COMMAND_LIST_BUILDER_H +#endif // CMDLIST_BUILDER_H diff --git a/src/parser/command_list/command_list_item.c b/src/parser/cmdlist/cmdlist_item.c similarity index 88% rename from src/parser/command_list/command_list_item.c rename to src/parser/cmdlist/cmdlist_item.c index dbbfa1a..5f37634 100644 --- a/src/parser/command_list/command_list_item.c +++ b/src/parser/cmdlist/cmdlist_item.c @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* command_list_item.c :+: :+: :+: */ +/* cmdlist_item.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/18 13:02:02 by khais #+# #+# */ -/* Updated: 2025/03/18 13:35:25 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:03:13 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#include "command_list_item.h" +#include "cmdlist_item.h" #include "libft.h" void cmdlist_item_destroy(t_cmdlist_item *cmd) diff --git a/src/parser/command_list/command_list_item.h b/src/parser/cmdlist/cmdlist_item.h similarity index 81% rename from src/parser/command_list/command_list_item.h rename to src/parser/cmdlist/cmdlist_item.h index 0fc2abc..d7dfa92 100644 --- a/src/parser/command_list/command_list_item.h +++ b/src/parser/cmdlist/cmdlist_item.h @@ -1,20 +1,20 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* command_list_item.h :+: :+: :+: */ +/* cmdlist_item.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/18 12:54:31 by khais #+# #+# */ -/* Updated: 2025/03/18 13:34:14 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:03:04 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef COMMAND_LIST_ITEM_H -# define COMMAND_LIST_ITEM_H +#ifndef CMDLIST_ITEM_H +# define CMDLIST_ITEM_H # include "../cmdgroup/cmdgroup.h" -# include "command_list_item_type.h" +# include "cmdlist_item_type.h" typedef struct s_cmdlist_item { @@ -29,4 +29,4 @@ typedef struct s_cmdlist_item void cmdlist_item_destroy(t_cmdlist_item *cmd); t_cmdlist_item *cmdlist_item_create(void); -#endif // COMMAND_LIST_ITEM_H +#endif // CMDLIST_ITEM_H diff --git a/src/parser/command_list/command_list_item_type.h b/src/parser/cmdlist/cmdlist_item_type.h similarity index 79% rename from src/parser/command_list/command_list_item_type.h rename to src/parser/cmdlist/cmdlist_item_type.h index 7e9e029..0810605 100644 --- a/src/parser/command_list/command_list_item_type.h +++ b/src/parser/cmdlist/cmdlist_item_type.h @@ -1,17 +1,17 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* command_list_item_type.h :+: :+: :+: */ +/* cmdlist_item_type.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/18 12:56:30 by khais #+# #+# */ -/* Updated: 2025/03/18 12:58:38 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:02:27 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef COMMAND_LIST_ITEM_TYPE_H -# define COMMAND_LIST_ITEM_TYPE_H +#ifndef CMDLIST_ITEM_TYPE_H +# define CMDLIST_ITEM_TYPE_H typedef enum e_cmdlist_item_type { @@ -20,4 +20,4 @@ typedef enum e_cmdlist_item_type TYPE_PIPELINE, } t_cmdlist_item_type; -#endif // COMMAND_LIST_ITEM_TYPE_H +#endif // CMDLIST_ITEM_TYPE_H diff --git a/src/parser/command_list/operator.c b/src/parser/cmdlist/operator.c similarity index 100% rename from src/parser/command_list/operator.c rename to src/parser/cmdlist/operator.c diff --git a/src/parser/command_list/operator.h b/src/parser/cmdlist/operator.h similarity index 100% rename from src/parser/command_list/operator.h rename to src/parser/cmdlist/operator.h diff --git a/tests/Makefile b/tests/Makefile index 86bbe47..3eba639 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -8,7 +8,7 @@ rawtests = \ test_redirection_parsing \ test_quote_removal \ test_metacharacters \ - test_parse_command_lists \ + test_parse_cmdlists \ test_parse_pipelines \ test_parse_simple_cmds \ test_env_manip \ @@ -22,7 +22,7 @@ run_tests = $(addprefix run_test_,$(rawtests)) test_objs = $(addsuffix .o,$(tests)) objs := $(addprefix ../,$(objs)) \ testutil.o \ - parse_command_list.o \ + parse_cmdlist.o \ parse_pipeline.o \ all_objs = $(objs) $(test_objs) diff --git a/tests/parse_command_list.c b/tests/parse_cmdlist.c similarity index 83% rename from tests/parse_command_list.c rename to tests/parse_cmdlist.c index cb318a7..a79d6bc 100644 --- a/tests/parse_command_list.c +++ b/tests/parse_cmdlist.c @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* parse_command_list.c :+: :+: :+: */ +/* parse_cmdlist.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/11 15:54:43 by khais #+# #+# */ -/* Updated: 2025/03/11 15:55:01 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:05:39 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../src/parser/command_list/command_list.h" +#include "../src/parser/cmdlist/cmdlist.h" #include "../src/parser/wordsplit/wordsplit.h" #include "libft.h" #include "unistd.h" #include -t_cmdlist *parse_command_list(char *input) +t_cmdlist *parse_cmdlist(char *input) { ft_dprintf(STDERR_FILENO, "Now checking command list with input [%s]\n", input); t_wordlist *words = minishell_wordsplit(input); diff --git a/tests/parse_command_list.h b/tests/parse_cmdlist.h similarity index 70% rename from tests/parse_command_list.h rename to tests/parse_cmdlist.h index ae0b193..d34f162 100644 --- a/tests/parse_command_list.h +++ b/tests/parse_cmdlist.h @@ -1,20 +1,20 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* parse_command_list.h :+: :+: :+: */ +/* parse_cmdlist.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/11 15:55:10 by khais #+# #+# */ -/* Updated: 2025/03/11 15:55:25 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:05:25 by khais ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef PARSE_COMMAND_LIST_H -# define PARSE_COMMAND_LIST_H +#ifndef PARSE_CMDLIST_H +# define PARSE_CMDLIST_H -# include "../src/parser/command_list/command_list.h" +# include "../src/parser/cmdlist/cmdlist.h" -t_cmdlist *parse_command_list(char *input); +t_cmdlist *parse_cmdlist(char *input); -#endif // PARSE_COMMAND_LIST_H +#endif // PARSE_CMDLIST_H diff --git a/tests/test_cmdlist_use_after_free.c b/tests/test_cmdlist_use_after_free.c index 85b6e31..b8af093 100644 --- a/tests/test_cmdlist_use_after_free.c +++ b/tests/test_cmdlist_use_after_free.c @@ -6,12 +6,12 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/03 11:40:37 by khais #+# #+# */ -/* Updated: 2025/03/18 14:23:19 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:05:18 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "../src/parser/wordsplit/wordsplit.h" -#include "../src/parser/command_list/command_list.h" +#include "../src/parser/cmdlist/cmdlist.h" #include "libft.h" #include diff --git a/tests/test_parse_command_lists.c b/tests/test_parse_cmdlists.c similarity index 65% rename from tests/test_parse_command_lists.c rename to tests/test_parse_cmdlists.c index 236c3b1..82fa6c6 100644 --- a/tests/test_parse_command_lists.c +++ b/tests/test_parse_cmdlists.c @@ -1,35 +1,35 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* test_parse_command_lists.c :+: :+: :+: */ +/* test_parse_cmdlists.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:40:48 by khais #+# #+# */ -/* Updated: 2025/03/18 13:09:51 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:05:05 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" -#include "../src/parser/command_list/command_list.h" +#include "../src/parser/cmdlist/cmdlist.h" #include "testutil.h" #include "unistd.h" #include -#include "parse_command_list.h" +#include "parse_cmdlist.h" -static void test_parse_command_list_empty(void) +static void test_parse_cmdlist_empty(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list(""); + t_cmdlist *cmd = parse_cmdlist(""); assert(cmd == NULL); cmdlist_destroy(cmd); } -static void test_parse_command_list_single_pipeline(void) +static void test_parse_cmdlist_single_pipeline(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this | cat -e"); + t_cmdlist *cmd = parse_cmdlist("echo this | cat -e"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_END); @@ -37,10 +37,10 @@ static void test_parse_command_list_single_pipeline(void) cmdlist_destroy(cmd); } -static void test_parse_command_list_simple_and(void) +static void test_parse_cmdlist_simple_and(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this | cat -e && echo works | wc -c"); + t_cmdlist *cmd = parse_cmdlist("echo this | cat -e && echo works | wc -c"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_AND); @@ -49,10 +49,10 @@ static void test_parse_command_list_simple_and(void) cmdlist_destroy(cmd); } -static void test_parse_command_list_simple_or(void) +static void test_parse_cmdlist_simple_or(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c"); + t_cmdlist *cmd = parse_cmdlist("echo this | cat -e || echo works | wc -c"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); @@ -61,10 +61,10 @@ static void test_parse_command_list_simple_or(void) cmdlist_destroy(cmd); } -static void test_parse_command_list_triple_or(void) +static void test_parse_cmdlist_triple_or(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c || echo as well | cut -d' ' -f1"); + t_cmdlist *cmd = parse_cmdlist("echo this | cat -e || echo works | wc -c || echo as well | cut -d' ' -f1"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); @@ -75,10 +75,10 @@ static void test_parse_command_list_triple_or(void) cmdlist_destroy(cmd); } -static void test_parse_command_list_triple_both_operators(void) +static void test_parse_cmdlist_triple_both_operators(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1"); + t_cmdlist *cmd = parse_cmdlist("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); @@ -90,10 +90,10 @@ static void test_parse_command_list_triple_both_operators(void) cmdlist_destroy(cmd); } -static void test_parse_command_list_quad_both_operators(void) +static void test_parse_cmdlist_quad_both_operators(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1 || echo final"); + t_cmdlist *cmd = parse_cmdlist("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1 || echo final"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); @@ -106,18 +106,18 @@ static void test_parse_command_list_quad_both_operators(void) cmdlist_destroy(cmd); } -static void test_parse_command_list_invalid_pipeline(void) +static void test_parse_cmdlist_invalid_pipeline(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this | | cat -e || echo does not work"); + t_cmdlist *cmd = parse_cmdlist("echo this | | cat -e || echo does not work"); assert(cmd == NULL); cmdlist_destroy(cmd); } -static void test_parse_command_list_simple_command(void) +static void test_parse_cmdlist_simple_command(void) { ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); - t_cmdlist *cmd = parse_command_list("echo this"); + t_cmdlist *cmd = parse_cmdlist("echo this"); assert(cmd != NULL); assert_pipelineequal("echo this", cmd, 0); assert(cmd->operators[0] == OP_END); @@ -127,23 +127,23 @@ static void test_parse_command_list_simple_command(void) int main(void) { - test_parse_command_list_empty(); + test_parse_cmdlist_empty(); do_leak_check(); - test_parse_command_list_single_pipeline(); + test_parse_cmdlist_single_pipeline(); do_leak_check(); - test_parse_command_list_simple_and(); + test_parse_cmdlist_simple_and(); do_leak_check(); - test_parse_command_list_simple_or(); + test_parse_cmdlist_simple_or(); do_leak_check(); - test_parse_command_list_triple_or(); + test_parse_cmdlist_triple_or(); do_leak_check(); - test_parse_command_list_triple_both_operators(); + test_parse_cmdlist_triple_both_operators(); do_leak_check(); - test_parse_command_list_quad_both_operators(); + test_parse_cmdlist_quad_both_operators(); do_leak_check(); - test_parse_command_list_invalid_pipeline(); + test_parse_cmdlist_invalid_pipeline(); do_leak_check(); - test_parse_command_list_simple_command(); + test_parse_cmdlist_simple_command(); do_leak_check(); return (0); } diff --git a/tests/testutil.c b/tests/testutil.c index a6a84e1..17efe6d 100644 --- a/tests/testutil.c +++ b/tests/testutil.c @@ -6,20 +6,20 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 15:21:09 by khais #+# #+# */ -/* Updated: 2025/03/18 13:09:16 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:05:45 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include #include "testutil.h" -#include "parse_command_list.h" +#include "parse_cmdlist.h" #include "unistd.h" #include #include "parse_pipeline.h" #include "../src/parser/wordlist/wordlist.h" #include "../src/parser/wordsplit/wordsplit.h" -#include "../src/parser/command_list/command_list_item.h" +#include "../src/parser/cmdlist/cmdlist_item.h" void assert_strequal(char *str1, char *str2) { @@ -128,7 +128,7 @@ t_cmdgroup *parse_cmdgroup(char *input) void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int item_number) { ft_dprintf(STDERR_FILENO, "checking that item %d of cmdlist %p matches [%s]\n", item_number, got_cmd, expected_str); - t_cmdlist *expected = parse_command_list(expected_str); + t_cmdlist *expected = parse_cmdlist(expected_str); if (expected == NULL) { ft_dprintf(STDERR_FILENO, "expecting the list to be null\n"); diff --git a/tests/testutil.h b/tests/testutil.h index 9662f81..f76ec7c 100644 --- a/tests/testutil.h +++ b/tests/testutil.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 15:57:21 by khais #+# #+# */ -/* Updated: 2025/03/11 17:26:49 by khais ### ########.fr */ +/* Updated: 2025/03/18 15:05:34 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ # define TESTUTIL_H # include "../src/parser/simple_cmd/simple_cmd.h" -# include "../src/parser/command_list/command_list.h" +# include "../src/parser/cmdlist/cmdlist.h" # include "../src/parser/cmdgroup/cmdgroup.h" void assert_strequal(char *str1, char *str2);