mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
cmdgroup: start implementing debug routines
This commit is contained in:
parent
d069abcd43
commit
55d21196b8
6 changed files with 22 additions and 92 deletions
|
|
@ -1,11 +0,0 @@
|
||||||
It "echos output"
|
|
||||||
Data
|
|
||||||
#|hello
|
|
||||||
#|there
|
|
||||||
End
|
|
||||||
|
|
||||||
When call ./minishell
|
|
||||||
The output line 1 should eq "hello"
|
|
||||||
The output line 2 should eq "there"
|
|
||||||
The output line 3 should be undefined
|
|
||||||
End
|
|
||||||
|
|
@ -6,16 +6,21 @@
|
||||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
|
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/02/20 15:00:46 by khais ### ########.fr */
|
/* Updated: 2025/03/18 12:00:23 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
#include "get_command.h"
|
#include "get_command.h"
|
||||||
|
#include "parser/cmdgroup/cmdgroup.h"
|
||||||
|
#include "parser/wordlist/wordlist.h"
|
||||||
|
#include "parser/wordsplit/wordsplit.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[], char **envp)
|
int main(int argc, char *argv[], char **envp)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
|
t_cmdgroup *cmd;
|
||||||
|
t_wordlist *words;
|
||||||
|
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
@ -23,8 +28,12 @@ int main(int argc, char *argv[], char **envp)
|
||||||
line = get_command();
|
line = get_command();
|
||||||
while (line != NULL)
|
while (line != NULL)
|
||||||
{
|
{
|
||||||
ft_printf("%s\n", line);
|
words = minishell_wordsplit(line);
|
||||||
free(line);
|
free(line);
|
||||||
|
cmd = cmdgroup_from_wordlist(words);
|
||||||
|
wordlist_destroy(words);
|
||||||
|
cmdgroup_debug(cmd);
|
||||||
|
cmdgroup_destroy(cmd);
|
||||||
line = get_command();
|
line = get_command();
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,12 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/11 15:18:02 by khais #+# #+# */
|
/* Created: 2025/03/11 15:18:02 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/18 11:48:33 by khais ### ########.fr */
|
/* Updated: 2025/03/18 12:08:36 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cmdgroup.h"
|
#include "cmdgroup.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "cmdgroup_item.h"
|
|
||||||
#include "cmdgroup_item_type.h"
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words)
|
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words)
|
||||||
|
|
@ -30,5 +28,10 @@ t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words)
|
||||||
|
|
||||||
void cmdgroup_destroy(t_cmdgroup *cmd)
|
void cmdgroup_destroy(t_cmdgroup *cmd)
|
||||||
{
|
{
|
||||||
(void)cmd;
|
free(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmdgroup_debug(t_cmdgroup *cmd)
|
||||||
|
{
|
||||||
|
ft_printf("%p\n", cmd);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/11 15:11:57 by khais #+# #+# */
|
/* Created: 2025/03/11 15:11:57 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/18 12:07:29 by khais ### ########.fr */
|
/* Updated: 2025/03/18 12:07:47 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -35,5 +35,6 @@ typedef struct s_cmdgroup
|
||||||
|
|
||||||
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words);
|
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words);
|
||||||
void cmdgroup_destroy(t_cmdgroup *cmd);
|
void cmdgroup_destroy(t_cmdgroup *cmd);
|
||||||
|
void cmdgroup_debug(t_cmdgroup *cmd);
|
||||||
|
|
||||||
#endif // CMDGROUP_H
|
#endif // CMDGROUP_H
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
# file are prefixed with test_
|
# file are prefixed with test_
|
||||||
rawtests = \
|
rawtests = \
|
||||||
expansion \
|
expansion \
|
||||||
test_cmdgroup_parsing \
|
|
||||||
test_here_doc \
|
test_here_doc \
|
||||||
test_wordlist_idx \
|
test_wordlist_idx \
|
||||||
test_redirection_parsing \
|
test_redirection_parsing \
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* test_cmdgroup_parsing.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/03/18 11:49/19 by khais #+# #+# */
|
|
||||||
/* Updated: 2025/03/18 11:49:19 by khais ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "testutil.h"
|
|
||||||
#include <assert.h>
|
|
||||||
#include "libft.h"
|
|
||||||
#include "../src/parser/cmdgroup/cmdgroup.h"
|
|
||||||
#include "../src/parser/cmdgroup/cmdgroup_item.h"
|
|
||||||
|
|
||||||
static void test_cmdgroup_parsing_empty(void)
|
|
||||||
{
|
|
||||||
t_cmdgroup *cmd;
|
|
||||||
|
|
||||||
// arange
|
|
||||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
|
||||||
cmd = parse_cmdgroup("");
|
|
||||||
// assert
|
|
||||||
assert(NULL == cmd);
|
|
||||||
// cleanup
|
|
||||||
cmdgroup_destroy(cmd);
|
|
||||||
do_leak_check();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_cmdgroup_parsing_single_cmdlist(void)
|
|
||||||
{
|
|
||||||
t_cmdgroup *cmd;
|
|
||||||
|
|
||||||
// arange
|
|
||||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
|
||||||
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
|
|
||||||
// assert
|
|
||||||
assert(NULL != cmd);
|
|
||||||
// TODO
|
|
||||||
// cleanup
|
|
||||||
cmdgroup_destroy(cmd);
|
|
||||||
do_leak_check();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_cmdgroup_parsing_two_cmdlist(void)
|
|
||||||
{
|
|
||||||
t_cmdgroup *cmd;
|
|
||||||
|
|
||||||
// arange
|
|
||||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
|
||||||
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
|
|
||||||
// assert
|
|
||||||
// TODO
|
|
||||||
assert(NULL != cmd);
|
|
||||||
assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0);
|
|
||||||
// cleanup
|
|
||||||
cmdgroup_destroy(cmd);
|
|
||||||
do_leak_check();
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
test_cmdgroup_parsing_empty();
|
|
||||||
test_cmdgroup_parsing_single_cmdlist();
|
|
||||||
test_cmdgroup_parsing_two_cmdlist();
|
|
||||||
// redirections
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue