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

This commit is contained in:
matteo 2026-01-17 17:53:37 +01:00 committed by william.valenduc
parent acbcb860a4
commit e8d10523ae
4 changed files with 125 additions and 63 deletions

View file

@ -7,22 +7,26 @@
TODO TODO
### Build ### Build
run this command: run theses commands:
`autoreconf --force --verbose --install` `autoreconf --force --verbose --install && ./configure`
### Test
run this command:
`./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla'`
then:
`make` `make`
`./src/42sh --help`
### Testing
#### asan
run this command: run this command:
`./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla -g -fsanitize=address'`
then:
`make check` `make check`
#### debug (asan)
run this command:
`./src/debug`
#### testsuite
run this command:
`./src/testsuite`
## Authors ## Authors
- Matteo Flebus - Matteo Flebus

View file

@ -1,4 +1,3 @@
# define the subdirectories
SUBDIRS = \ SUBDIRS = \
parser \ parser \
lexer \ lexer \
@ -9,6 +8,8 @@ SUBDIRS = \
bin_PROGRAMS = 42sh bin_PROGRAMS = 42sh
42sh_CFLAGS = -std=c99 -Werror -Wall -Wextra -Wvla
42sh_SOURCES = main.c 42sh_SOURCES = main.c
42sh_CPPFLAGS = -I%D% 42sh_CPPFLAGS = -I%D%
@ -21,18 +22,31 @@ bin_PROGRAMS = 42sh
execution/libexecution.a \ execution/libexecution.a \
utils/libutils.a utils/libutils.a
# ================ TESTS ================
################################################# Test # ------------- Unit tests --------------
#
#42sh_asan_SOURCES = main.c check_PROGRAMS = testsuite
#
#42sh_asan_CPPFLAGS = -I%D% testsuite_CFLAGS = $(42sh_CFLAGS)
# testsuite_CFLAGS += $(CRITERION_CFLAGS)
#42sh_asan_LDADD = \
# ast/lib_asan_ast.a \ testsuite_SOURCES = ../tests/unit/lexer/lexer_tests.c \
# parser/lib_asan_parser.a \ ../tests/unit/utils/utils_tests.c
# lexer/lib_asan_lexer.a \
# io_backend/lib_asan_io_backend.a \ testsuite_CPPFLAGS = $(42sh_CPPFLAGS)
# expansion/lib_asan_expansion.a \
# execution/lib_asan_execution.a \ testsuite_LDADD = $(42sh_LDADD) $(CRITERION_LIBS)
# utils/lib_asan_utils.a
# ------------- asan debug --------------
check_PROGRAMS += debug
debug_CFLAGS = $(42sh_CFLAGS)
debug_CFLAGS += -fsanitize=address -g
debug_SOURCES = $(42sh_SOURCES)
debug_CPPFLAGS = $(42sh_CPPFLAGS)
debug_LDADD = $(42sh_LDADD)

View file

@ -1,5 +1,5 @@
// === Includes // === Includes
#include <cstddef> //#include <cstddef>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View file

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