diff --git a/.gitignore b/.gitignore index 1493ffef..b729ab8d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ ft_ssl ft_ssl_test *.o *.a +.vscode diff --git a/Makefile b/Makefile index a44a575b..4c3f3656 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,8 @@ OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o)) TEST_BIN = ft_ssl_test -TEST_SRC = test_test.c +TEST_SRC = main_test.c \ + test_tests.c TEST_SRC += munit.c @@ -83,7 +84,8 @@ LINK_FLAGS = "" # header flags -HEADER_FLAGS = $(MUINUT_INC) +HEADER_FLAGS = -I $(INC_DIR) \ + $(MUINUT_INC) # compiler @@ -97,6 +99,7 @@ $(NAME): check $(LIBFT) $(OBJ) $(CC) $(OBJ) $(LINK_FLAGS) -o $(NAME) check: $(TEST_BIN) + clear ./$(TEST_BIN) $(TEST_BIN): $(LIBFT) $(TEST_OBJ) @@ -120,7 +123,6 @@ clean: fclean: clean rm -f $(NAME) - rm -rf $(OBJ_DIR) $(MAKE) -C $(LIBFT_DIR) fclean re: fclean all diff --git a/inc/tests.h b/inc/tests.h new file mode 100644 index 00000000..8eb40f1a --- /dev/null +++ b/inc/tests.h @@ -0,0 +1,13 @@ +#ifndef TESTS +# define TESTS + +#define MUNIT_ENABLE_ASSERT_ALIASES +#include "munit.h" +#include "tests_macros.h" + +// test tests +CASE(should_pass); +CASE(should_skip); +CASE(should_fail); + +#endif \ No newline at end of file diff --git a/inc/tests_macros.h b/inc/tests_macros.h new file mode 100644 index 00000000..17763793 --- /dev/null +++ b/inc/tests_macros.h @@ -0,0 +1,22 @@ +#ifndef TESTS_MACROS +# define TESTS_MACROS + +#include "munit.h" + +#define UNUSED(x) (void)(x) + +#define TEST_RESULT MunitResult +#define TEST_PARAMS const MunitParameter test_params[] +#define TEST_DATA void *test_data +#define CASE(f) TEST_RESULT f(TEST_PARAMS, TEST_DATA) + +#define N(name) (char *)name +#define T(test_function) test_function +#define S(setup_function) setup_function +#define TD(tear_down_function) tear_down_function +#define O(options) options +#define P(paramenters) paramenters +#define IT(n, t, s, td, o, p) { N(n), T(t), S(s), TD(td), O(o), P(p) } +#define END_IT IT(NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL) + +#endif \ No newline at end of file diff --git a/t/main_test.c b/t/main_test.c new file mode 100644 index 00000000..c4289b43 --- /dev/null +++ b/t/main_test.c @@ -0,0 +1,21 @@ +#include "tests.h" + +MunitTest test_tests[] = { + IT("/should_pass", should_pass, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL), + IT("/should_fail", should_fail, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL), + IT("/should_skip", should_skip, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL), + END_IT +}; + +static const MunitSuite suite = { + (char *)"/test_tests_suite", /* name */ + test_tests, /* tests */ + NULL, /* suites */ + 1, /* iterations */ + MUNIT_SUITE_OPTION_NONE /* options */ +}; + +int main(int argc, char** argv) +{ + return munit_suite_main(&suite, NULL, argc, argv); +} diff --git a/t/test_test.c b/t/test_test.c deleted file mode 100644 index a774dcee..00000000 --- a/t/test_test.c +++ /dev/null @@ -1,8 +0,0 @@ -#define MUNIT_ENABLE_ASSERT_ALIASES -#include "munit.h" - -int main(int argc, char** argv) { - (void)argc; - (void)argv; - assert_int(argc, ==, 1); -} diff --git a/t/test_tests.c b/t/test_tests.c new file mode 100644 index 00000000..f1a3b833 --- /dev/null +++ b/t/test_tests.c @@ -0,0 +1,23 @@ +#include "tests.h" + +TEST_RESULT should_pass(TEST_PARAMS, TEST_DATA) +{ + UNUSED(test_params); + UNUSED(test_data); + return MUNIT_OK; +} + +TEST_RESULT should_fail(TEST_PARAMS, TEST_DATA) +{ + UNUSED(test_params); + UNUSED(test_data); + return MUNIT_SKIP; + return MUNIT_FAIL; +} + +TEST_RESULT should_skip(TEST_PARAMS, TEST_DATA) +{ + UNUSED(test_params); + UNUSED(test_data); + return MUNIT_SKIP; +} \ No newline at end of file