feat(testsuite): autotools working, testsuite and debug implemented and working

This commit is contained in:
matteo 2026-01-17 17:53:37 +01:00
parent e80058a765
commit e7b24d0ed6
4 changed files with 125 additions and 63 deletions

View file

@ -6,51 +6,95 @@
#include <sys/types.h>
#include "lexer/lexer.h"
#include "io_backend/io_backend.h"
TestSuite(token_creation);
TestSuite(peek_token);
Test(token_creation, basic)
Test(peek_token, basic_empty)
{
char input[] = "Hello World";
// simulates input
char command[] = "";
struct iob_context context =
{
IOB_MODE_CMD,
command
};
iob_init(&context);
char actual[] = new_token(input, 5);
char expected[] = "Hello";
cr_expect(eq(str, actual, expected));
free(actual);
// test
struct token *tok = peek_token();
// expected
enum token_type type_expected = TOKEN_EOF;
char *string_expected = NULL;
cr_assert(eq(str, string_expected, tok->data));
cr_assert(type_expected == tok->type);
free_token(&tok);
}
Test(token_creation, nul)
Test(peek_token, basic_word)
{
char input[] = NULL;
// simulates input
char command[] = "hello";
struct iob_context context =
{
IOB_MODE_CMD,
command
};
iob_init(&context);
char actual[] = new_token(input, 5);
cr_expect(actual == NULL);
// test
struct token *tok = peek_token();
// expected
enum token_type type_expected = TOKEN_WORD;
char string_expected[] = "hello";
cr_assert(eq(str, string_expected, tok->data));
cr_assert(type_expected == tok->type);
free_token(&tok);
}
Test(token_creation, too_large)
Test(peek_token, basic_words)
{
char input[] = "Hel";
// simulates input
char command[] = "echo hello there";
struct iob_context context =
{
IOB_MODE_CMD,
command
};
iob_init(&context);
char actual[] = new_token(input, 5);
cr_expect(actual == NULL);
}
Test(token_creation, empty)
{
char input[] = "";
char actual[] = new_token(input, 5);
cr_expect(actual == NULL);
}
Test(token_creation, basic_long)
{
char input[] = "Hello World! This project is a mini shell, I love BIG G.";
char actual[] = new_token(input, 42);
char expected[] = calloc(42 + 1, sizeof(char));
strncpy(input, expected, 42);
cr_expect(eq(str, actual, expected));
free(actual);
free(expected);
// ======= 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);
}