feat(testsuite): autotools working, testsuite and debug implemented and working
This commit is contained in:
parent
acbcb860a4
commit
e8d10523ae
4 changed files with 125 additions and 63 deletions
26
README.md
26
README.md
|
|
@ -7,22 +7,26 @@
|
|||
TODO
|
||||
|
||||
### Build
|
||||
run this command:
|
||||
`autoreconf --force --verbose --install`
|
||||
|
||||
### Test
|
||||
run this command:
|
||||
`./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla'`
|
||||
then:
|
||||
run theses commands:
|
||||
`autoreconf --force --verbose --install && ./configure`
|
||||
`make`
|
||||
`./src/42sh --help`
|
||||
|
||||
### Testing
|
||||
|
||||
#### asan
|
||||
run this command:
|
||||
`./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla -g -fsanitize=address'`
|
||||
|
||||
then:
|
||||
`make check`
|
||||
|
||||
#### debug (asan)
|
||||
|
||||
run this command:
|
||||
`./src/debug`
|
||||
|
||||
#### testsuite
|
||||
|
||||
run this command:
|
||||
`./src/testsuite`
|
||||
|
||||
## Authors
|
||||
|
||||
- Matteo Flebus
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
# define the subdirectories
|
||||
SUBDIRS = \
|
||||
parser \
|
||||
lexer \
|
||||
|
|
@ -9,6 +8,8 @@ SUBDIRS = \
|
|||
|
||||
bin_PROGRAMS = 42sh
|
||||
|
||||
42sh_CFLAGS = -std=c99 -Werror -Wall -Wextra -Wvla
|
||||
|
||||
42sh_SOURCES = main.c
|
||||
|
||||
42sh_CPPFLAGS = -I%D%
|
||||
|
|
@ -21,18 +22,31 @@ bin_PROGRAMS = 42sh
|
|||
execution/libexecution.a \
|
||||
utils/libutils.a
|
||||
|
||||
# ================ TESTS ================
|
||||
|
||||
################################################# Test
|
||||
#
|
||||
#42sh_asan_SOURCES = main.c
|
||||
#
|
||||
#42sh_asan_CPPFLAGS = -I%D%
|
||||
#
|
||||
#42sh_asan_LDADD = \
|
||||
# ast/lib_asan_ast.a \
|
||||
# parser/lib_asan_parser.a \
|
||||
# lexer/lib_asan_lexer.a \
|
||||
# io_backend/lib_asan_io_backend.a \
|
||||
# expansion/lib_asan_expansion.a \
|
||||
# execution/lib_asan_execution.a \
|
||||
# utils/lib_asan_utils.a
|
||||
# ------------- Unit tests --------------
|
||||
|
||||
check_PROGRAMS = testsuite
|
||||
|
||||
testsuite_CFLAGS = $(42sh_CFLAGS)
|
||||
testsuite_CFLAGS += $(CRITERION_CFLAGS)
|
||||
|
||||
testsuite_SOURCES = ../tests/unit/lexer/lexer_tests.c \
|
||||
../tests/unit/utils/utils_tests.c
|
||||
|
||||
testsuite_CPPFLAGS = $(42sh_CPPFLAGS)
|
||||
|
||||
testsuite_LDADD = $(42sh_LDADD) $(CRITERION_LIBS)
|
||||
|
||||
# ------------- 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)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// === Includes
|
||||
#include <cstddef>
|
||||
//#include <cstddef>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue