diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile | 52 | ||||
| m--------- | test/ctest | 0 | ||||
| -rw-r--r-- | test/main_test.c | 7 | ||||
| -rw-r--r-- | test/str/ft_strlen_test.c | 23 | ||||
| -rw-r--r-- | test/test_libft.h | 8 |
5 files changed, 90 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..3f31059 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,52 @@ +MAKE_ARGS = --no-print-directory + +NAME = test_libft + +BUILD_DIR = build +LIBFT_DIR = .. +CTEST_DIR = ctest + +CC = gcc +CCFLAGS = -Wall -Wextra -I$(LIBFT_DIR)/include -I$(CTEST_DIR) +LDFLAGS = -L$(LIBFT_DIR) -lft + +HEADER = $(shell find . -name "*.h") +SRC = $(shell find . -name "*_test.c") +SRC += $(shell find $(CTEST_DIR) -name "*.c") +OBJ = $(SRC:%.c=$(BUILD_DIR)/%.o) + +all: make_build_dirs $(NAME) + +run_raw: all + @./$(NAME) + +make_build_dirs: + @for dir in $$(find . -not -path "*build*" -type d | sed 's/.*/$(BUILD_DIR)\/&/'); \ + do \ + if [ ! -d "$$dir" ]; then \ + mkdir -p $$dir; echo "Making build dir: $$dir"; fi \ + done + +$(NAME): $(OBJ) libft_all + @echo "Test: Linking $@" + @$(CC) -o $@ $(OBJ) $(LDFLAGS) + +$(BUILD_DIR)/%.o: %.c $(HEADER) + @echo "Test: Compiling: $@" + @$(CC) $(CCFLAGS) -c -o $@ $< + +clean: + @echo "Test: Removing objects" + @$(RM) -r $(BUILD_DIR) + +fclean: clean + @echo "Test: Removing library" + @$(RM) $(NAME) + @echo "Test: Removing libft" + @$(MAKE) $(MAKE_ARGS) -C $(LIBFT_DIR) fclean + +re: fclean all + +libft_all: + @echo "Test: Making libft" + @$(MAKE) $(MAKE_ARGS) -C $(LIBFT_DIR) all diff --git a/test/ctest b/test/ctest new file mode 160000 +Subproject 61963f169ff5ae4dc18c5e6e1c7c6972745d6cf diff --git a/test/main_test.c b/test/main_test.c new file mode 100644 index 0000000..6b74ac4 --- /dev/null +++ b/test/main_test.c @@ -0,0 +1,7 @@ +#include "test_libft.h" + +int main(void) +{ + TEST_CALL(ft_strlen); + return 0; +} diff --git a/test/str/ft_strlen_test.c b/test/str/ft_strlen_test.c new file mode 100644 index 0000000..57ccee4 --- /dev/null +++ b/test/str/ft_strlen_test.c @@ -0,0 +1,23 @@ +#include <string.h> +#include "libft.h" +#include "ctest.h" + +TEST_SEGV_FUNC(ft_strlen, char *str) +{ + ft_strlen(str); +} +TEST_SEGV_FUNC_END + +ASSERT_FUNC1(ft_strlen, char*, str) +{ + return ft_strlen(str) == strlen(str); +} +ASSERT_FUNC1_END + + +TEST(ft_strlen) +{ + ASSERT(ft_strlen, "bonjour"); + ASSERT(ft_strlen, "yo"); + ASSERT(ft_strlen, "slt"); +} diff --git a/test/test_libft.h b/test/test_libft.h new file mode 100644 index 0000000..f4d489f --- /dev/null +++ b/test/test_libft.h @@ -0,0 +1,8 @@ +#ifndef TEST_LIBFT_H +# define TEST_LIBFT_H + +# include "ctest.h" + +TEST(ft_strlen); + +#endif |
