diff --git a/.gitignore b/.gitignore index 49c6c0e..a40b9d1 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ test minishell testexec.sh tests/* +!tests/Makefile !tests/*.c !tests/*.h infile diff --git a/Makefile b/Makefile index 9304110..c1a1cb7 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ export CFLAGS srcs = \ objs = $(srcs:.c=.o) +export objs minishell_objs = $(addsuffix .o,src/$(NAME)) $(objs) all_objs = $(minishell_objs) deps = $(all_objs:.o=.d) @@ -36,6 +37,7 @@ clean: fclean: clean rm -f $(NAME) + +make -C tests fclean re: +make fclean @@ -45,10 +47,19 @@ norm: norminette src | grep -v OK || true tests: + @echo "Running tests with AddressSanitizer..." +CFLAGS="$(CFLAGS) $(ASAN)" make re shellspec + +CFLAGS="$(CFLAGS) $(ASAN)" make -C tests + + @echo "Running tests with UndefinedBehaviourSanitizer..." +CFLAGS="$(CFLAGS) $(UBSAN)" make re shellspec + +CFLAGS="$(CFLAGS) $(UBTSAN)" make -C tests + + @echo "Running tests with ThreadSanitizer..." +CFLAGS="$(CFLAGS) $(TSAN)" make re shellspec + +CFLAGS="$(CFLAGS) $(TSAN)" make -C tests + @echo "All tests passed!" diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..fef31ea --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,21 @@ +rawtests = \ + metacharacters \ + +tests = $(addprefix test_,$(rawtests)) +test_objs = $(addsuffix .o,$(tests)) +objs := $(addprefix ../,$(objs)) + +.PHONY: run + +%.o: %.c + $(CC) -c $(CFLAGS) $(LDFLAGS) -o $*.o $*.c + $(CC) -MM $(CFLAGS) $(LDFLAGS) $*.c > $*.d + +test_%: %.o $(objs) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $*.o $(objs) $(LDLIBS) + +run: $(tests) + $(addprefix ./,$(addsuffix &&,$(tests))) echo "Finished running C tests" + +fclean: + rm -f $(tests) diff --git a/tests/metacharacters.c b/tests/metacharacters.c new file mode 100644 index 0000000..85c8e3b --- /dev/null +++ b/tests/metacharacters.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* metacharacters.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kcolin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/06 15:21:00 by kcolin #+# #+# */ +/* Updated: 2025/02/06 15:57:40 by kcolin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../src/parser/matchers/metacharacter.h" +#include +#include +#include + +void test_metacharacters(void) +{ + dup2(STDERR_FILENO, STDIN_FILENO); + char c = 'a'; + printf("not metachar:"); + while (c != 'z') + { + printf("%c", c); + assert(!is_metacharacter(c)); + c++; + } + c = 'A'; + while (c != 'Z') + { + printf("%c", c); + assert(!is_metacharacter(c)); + c++; + } + c = '0'; + while (c != '9') + { + printf("%c", c); + assert(!is_metacharacter(c)); + c++; + } + char *metachars = " \t\n|&;()<>"; + int i = 0; + printf("\nmetachar:"); + while (metachars[i] != '\0') + { + printf("%c", metachars[i]); + assert(is_metacharacter(metachars[i])); + i++; + } + printf("\n"); +} + +int main(void) +{ + test_metacharacters(); + return (0); +}