feat: build system ready for testsuite using make check

This commit is contained in:
matteo 2026-01-23 20:31:49 +01:00
parent e853249fbf
commit b9d7dbce1f
2 changed files with 23 additions and 43 deletions

View file

@ -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);
}
}