From b9d7dbce1f00abd5e144d36adb1b3fdf9e7ea7f0 Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 23 Jan 2026 20:31:49 +0100 Subject: [PATCH] feat: build system ready for testsuite using `make check` --- src/Makefile.am | 8 ++++- tests/unit/lexer/lexer_tests.c | 58 ++++++++++------------------------ 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 56c48b6..994f1ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,12 @@ bin_PROGRAMS = 42sh # ================ TESTS ================ +check-local: $(bin_PROGRAMS) # $(check_PROGRAMS) + ./../testsuite.sh +#./../tests/functional/testsuite.sh + +#./testsuite + # ------------- Unit tests -------------- check_PROGRAMS = testsuite @@ -36,7 +42,7 @@ testsuite_SOURCES = ../tests/unit/lexer/lexer_tests.c \ testsuite_CPPFLAGS = $(42sh_CPPFLAGS) -testsuite_LDADD = $(42sh_LDADD) $(CRITERION_LIBS) +testsuite_LDADD = $(42sh_LDADD) -lcriterion # ------------- asan debug -------------- diff --git a/tests/unit/lexer/lexer_tests.c b/tests/unit/lexer/lexer_tests.c index 7cb84a5..ecf662f 100644 --- a/tests/unit/lexer/lexer_tests.c +++ b/tests/unit/lexer/lexer_tests.c @@ -17,14 +17,20 @@ Test(peek_token, basic_empty) struct iob_context context = { IOB_MODE_CMD, command }; iob_init(&context); + struct lexer_context ctx = { .end_previous_token = NULL, + .remaining_chars = 0, + .only_digits = false, + .previous_token = NULL, + .current_token = NULL }; + // test - struct token *tok = peek_token(); + struct token *tok = peek_token(&ctx); // expected enum token_type type_expected = TOKEN_EOF; char *string_expected = NULL; - cr_assert(eq(str, string_expected, tok->data)); + cr_assert(tok->data == string_expected); cr_assert(type_expected == tok->type); free_token(&tok); @@ -37,8 +43,14 @@ Test(peek_token, basic_word) struct iob_context context = { IOB_MODE_CMD, command }; iob_init(&context); + struct lexer_context ctx = { .end_previous_token = NULL, + .remaining_chars = 0, + .only_digits = false, + .previous_token = NULL, + .current_token = NULL }; + // test - struct token *tok = peek_token(); + struct token *tok = peek_token(&ctx); // expected enum token_type type_expected = TOKEN_WORD; @@ -47,42 +59,4 @@ Test(peek_token, basic_word) cr_assert(eq(str, string_expected, tok->data)); cr_assert(type_expected == tok->type); free_token(&tok); -} -Test(peek_token, basic_words) -{ - // simulates input - char command[] = "echo hello there"; - struct iob_context context = { IOB_MODE_CMD, command }; - iob_init(&context); - - // ======= echo - - struct token *tok = peek_token(); - - enum token_type type_expected = TOKEN_WORD; - char string_expected[] = "echo"; - - cr_assert(eq(str, string_expected, tok->data)); - cr_assert(type_expected == tok->type); - free_token(&tok); - - // ======= hello - - tok = peek_token(); - - char string_expected2[] = "hello"; - - cr_assert(eq(str, string_expected2, tok->data)); - cr_assert(type_expected == tok->type); - free_token(&tok); - - // ======= there - - tok = peek_token(); - - char string_expected3[] = "there"; - - cr_assert(eq(str, string_expected3, tok->data)); - cr_assert(type_expected == tok->type); - free_token(&tok); -} +} \ No newline at end of file