cmdlist refactor: use cmdlist instead of command_list as a shorthand

I hope this doesn't break too much code ^^
This commit is contained in:
Khaïs COLIN 2025-03-18 14:55:58 +01:00
parent 56fe943efc
commit 131ba36d93
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
18 changed files with 98 additions and 98 deletions

View file

@ -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)

View file

@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_command_list.c :+: :+: :+: */
/* parse_cmdlist.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <assert.h>
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);

View file

@ -1,20 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_command_list.h :+: :+: :+: */
/* parse_cmdlist.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,12 +6,12 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <assert.h>

View file

@ -1,35 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_parse_command_lists.c :+: :+: :+: */
/* test_parse_cmdlists.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <assert.h>
#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);
}

View file

@ -6,20 +6,20 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <assert.h>
#include "testutil.h"
#include "parse_command_list.h"
#include "parse_cmdlist.h"
#include "unistd.h"
#include <assert.h>
#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");

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);