added the folder and makefile structure for the tests and made some tests
This commit is contained in:
29
Makefile
29
Makefile
@@ -4,7 +4,6 @@ LINK = -lreadline
|
||||
|
||||
SRCDIR = srcs
|
||||
OBJDIR = .objs
|
||||
BONUS_OBJDIR = bonus_objs
|
||||
INCDIR = includes/
|
||||
LIBFT_DIR = lib/libft
|
||||
|
||||
@@ -33,16 +32,38 @@ $(NAME): $(LIBFT) $(OBJS)
|
||||
@$(CC) $(WFLAGS) $(OBJS) $(LIBFT) -o $(NAME) $(LINK)
|
||||
@echo "$(CYAN)Build completed: $(NAME)$(RESET)"
|
||||
|
||||
|
||||
|
||||
# test part
|
||||
|
||||
TEST_SRCDIR = tests
|
||||
TEST_OBJDIR = .TEST_objs
|
||||
TEST_SRCS = $(shell find $(TEST_SRCDIR) -name "*.c")
|
||||
TEST_OBJS = $(patsubst $(TEST_SRCDIR)/%.c, $(TEST_OBJDIR)/%.o, $(TEST_SRCS))
|
||||
TEST_DEPS = $(TEST_OBJS:.o=.d)
|
||||
|
||||
$(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK)
|
||||
|
||||
test: $(LIBFT) $(TEST_OBJS)
|
||||
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o test $(LINK)
|
||||
@echo "$(CYAN)Test build completed: test$(RESET)"
|
||||
|
||||
# test part end
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJDIR)
|
||||
@rm -rf $(OBJDIR) $(TEST_OBJDIR)
|
||||
@make -C $(LIBFT_DIR) clean
|
||||
@echo "$(CYAN)Project cleaned$(RESET)"
|
||||
|
||||
fclean: clean
|
||||
@make -C $(LIBFT_DIR) fclean
|
||||
@rm $(NAME)
|
||||
@rm $(NAME) test
|
||||
@echo "$(CYAN)Executable removed$(RESET)"
|
||||
|
||||
re: fclean all
|
||||
|
||||
-include $(DEPS)
|
||||
-include $(DEPS) $(TEST_DEPS)
|
||||
|
||||
@@ -17,7 +17,7 @@ char *powerline(void)
|
||||
tilt = " ";
|
||||
printf("%s----------------------------------------------\
|
||||
----------------------------------%s", POW5, RESET);
|
||||
printf("\n%s MMOAT %s%s%s%s%s %s%s%s ",
|
||||
printf("\n%s MMOAT %s%s%s%s%s %s%s%s ",
|
||||
POW1, POW2, POW3, POW4, tilt, pwd, RESET, POW5, RESET);
|
||||
return (readline(""));
|
||||
}
|
||||
|
||||
57
tests/parse.c
Normal file
57
tests/parse.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
void truncate_after_exit_word(char **lst)
|
||||
{
|
||||
int i;
|
||||
int depth;
|
||||
int truncate_mode;
|
||||
|
||||
i = 0;
|
||||
depth = 0;
|
||||
truncate_mode = FALSE;
|
||||
while (lst[i])
|
||||
{
|
||||
if (truncate_mode)
|
||||
{
|
||||
free(lst[i]);
|
||||
lst[i] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lst[i][0] == '(')
|
||||
depth += 1;
|
||||
if (lst[i][ft_strlen(lst[i]) - 1] == ')')
|
||||
depth -= 1;
|
||||
if (!ft_strncmp(lst[i], "exit", 4) && depth == 0)
|
||||
truncate_mode = TRUE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/*void print_tab(char **lst)*/
|
||||
/*{*/
|
||||
/* int i = 0;*/
|
||||
/* while (lst[i])*/
|
||||
/* {*/
|
||||
/* printf("%s\n", lst[i]);*/
|
||||
/* i++;*/
|
||||
/* }*/
|
||||
/*}*/
|
||||
|
||||
int main (int ac, char **av)
|
||||
{
|
||||
(void)ac;
|
||||
|
||||
char *str = av[1];
|
||||
char **lst;
|
||||
|
||||
if (str)
|
||||
{
|
||||
// replace by a custom split that also the token alone and under the form of a linked list
|
||||
lst = ft_split(str, ' ');
|
||||
truncate_after_exit_word(lst);
|
||||
print_tab(lst);
|
||||
free_tab(lst);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user