From 2e5ca2ab6276b7b24895ade28e1533356ef523dc Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 16 Jan 2020 18:51:11 +0100 Subject: Testing config with travis --- test/Makefile | 52 +++++++++++++++++++++++++++++++++++++++++++++++ test/ctest | 1 + test/main_test.c | 7 +++++++ test/str/ft_strlen_test.c | 23 +++++++++++++++++++++ test/test_libft.h | 8 ++++++++ 5 files changed, 91 insertions(+) create mode 100644 test/Makefile create mode 160000 test/ctest create mode 100644 test/main_test.c create mode 100644 test/str/ft_strlen_test.c create mode 100644 test/test_libft.h (limited to 'test') 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 index 0000000..61963f1 --- /dev/null +++ b/test/ctest @@ -0,0 +1 @@ +Subproject commit 61963f169ff5ae4dc18c5e6e1c7c6972745d6cf2 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 +#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 -- cgit