cmdlist: use new architecture (STUB)

I fixed the tests, and the basic functionallity of detecting pipelines works,
but detecting nested cmdgroups is not yet implemented
This commit is contained in:
Khaïs COLIN 2025-03-18 12:36:19 +01:00
parent 8f7e7f7dfe
commit 56fe943efc
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
13 changed files with 116 additions and 69 deletions

View file

@ -2,11 +2,11 @@
# file are prefixed with test_
rawtests = \
expansion \
test_cmdlist_use_after_free \
test_here_doc \
test_wordlist_idx \
test_redirection_parsing \
test_quote_removal \
test_cmdlist_use_after_free \
test_metacharacters \
test_parse_command_lists \
test_parse_pipelines \

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmdlist_use_after_free.c :+: :+: :+: */
/* test_cmdlist_use_after_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/03 11:40:37 by khais #+# #+# */
/* Updated: 2025/03/04 13:27:54 by khais ### ########.fr */
/* Updated: 2025/03/18 14:23:19 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,8 +17,11 @@
int main(void)
{
t_wordlist *words = minishell_wordsplit("|");
t_cmdlist *cmd = cmdlist_from_wordlist(words);
t_wordlist *words;
t_cmdlist *cmd;
cmd = NULL;
words = minishell_wordsplit("|");
cmd = cmdlist_from_wordlist(words);
wordlist_destroy(words);
assert(cmd == NULL);
return (0);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:40:48 by khais #+# #+# */
/* Updated: 2025/03/11 16:30:05 by khais ### ########.fr */
/* Updated: 2025/03/18 13:09:51 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,7 +33,7 @@ static void test_parse_command_list_single_pipeline(void)
assert(cmd != NULL);
assert_pipelineequal("echo this | cat -e", cmd, 0);
assert(cmd->operators[0] == OP_END);
assert(cmd->num_pipelines == 1);
assert(cmd->num_cmds == 1);
cmdlist_destroy(cmd);
}
@ -45,7 +45,7 @@ static void test_parse_command_list_simple_and(void)
assert_pipelineequal("echo this | cat -e", cmd, 0);
assert(cmd->operators[0] == OP_AND);
assert_pipelineequal("echo works | wc -c", cmd, 1);
assert(cmd->num_pipelines == 2);
assert(cmd->num_cmds == 2);
cmdlist_destroy(cmd);
}
@ -57,7 +57,7 @@ static void test_parse_command_list_simple_or(void)
assert_pipelineequal("echo this | cat -e", cmd, 0);
assert(cmd->operators[0] == OP_OR);
assert_pipelineequal("echo works | wc -c", cmd, 1);
assert(cmd->num_pipelines == 2);
assert(cmd->num_cmds == 2);
cmdlist_destroy(cmd);
}
@ -71,7 +71,7 @@ static void test_parse_command_list_triple_or(void)
assert_pipelineequal("echo works | wc -c", cmd, 1);
assert(cmd->operators[1] == OP_OR);
assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2);
assert(cmd->num_pipelines == 3);
assert(cmd->num_cmds == 3);
cmdlist_destroy(cmd);
}
@ -86,7 +86,7 @@ static void test_parse_command_list_triple_both_operators(void)
assert(cmd->operators[1] == OP_AND);
assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2);
assert(cmd->operators[2] == OP_END);
assert(cmd->num_pipelines == 3);
assert(cmd->num_cmds == 3);
cmdlist_destroy(cmd);
}
@ -121,7 +121,7 @@ static void test_parse_command_list_simple_command(void)
assert(cmd != NULL);
assert_pipelineequal("echo this", cmd, 0);
assert(cmd->operators[0] == OP_END);
assert(cmd->num_pipelines == 1);
assert(cmd->num_cmds == 1);
cmdlist_destroy(cmd);
}

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 15:21:09 by khais #+# #+# */
/* Updated: 2025/03/18 11:50:23 by khais ### ########.fr */
/* Updated: 2025/03/18 13:09:16 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@
#include "parse_pipeline.h"
#include "../src/parser/wordlist/wordlist.h"
#include "../src/parser/wordsplit/wordsplit.h"
#include "../src/parser/cmdgroup/cmdgroup_item.h"
#include "../src/parser/command_list/command_list_item.h"
void assert_strequal(char *str1, char *str2)
{
@ -84,9 +84,9 @@ void assert_pipelineequal_raw(t_pipeline *expected, t_pipeline *got)
void assert_pipelineequal(char *expected, t_cmdlist *cmd, int idx)
{
ft_printf("Expected command list %p to have at least %d pipelines, and got %d\n", cmd, idx + 1, cmd->num_pipelines);
assert(cmd->num_pipelines >= idx + 1);
t_pipeline *got = cmd->pipelines[idx];
ft_printf("Expected command list %p to have at least %d pipelines, and got %d\n", cmd, idx + 1, cmd->num_cmds);
assert(cmd->num_cmds >= idx + 1);
t_pipeline *got = cmd->cmds[idx]->inner.pipeline;
ft_dprintf(STDERR_FILENO, "Expected pipeline %p to equal [%s]\n", got, expected);
t_pipeline *expected_pipeline = parse_pipeline(expected);
assert_pipelineequal_raw(expected_pipeline, got);
@ -136,7 +136,7 @@ void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int
}
ft_dprintf(STDERR_FILENO, "checking if the list matches...\n");
int i = 0;
while (i < expected->num_pipelines)
while (i < expected->num_cmds)
{
i++;
}