feat(testsuite): autotools working, testsuite and debug implemented and working
This commit is contained in:
parent
e80058a765
commit
e7b24d0ed6
4 changed files with 125 additions and 63 deletions
26
README.md
26
README.md
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// === Includes
|
// === Includes
|
||||||
#include <cstddef>
|
//#include <cstddef>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
|
struct iob_context context =
|
||||||
|
{
|
||||||
|
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, too_large)
|
|
||||||
{
|
{
|
||||||
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);
|
// ======= echo
|
||||||
cr_expect(actual == NULL);
|
|
||||||
}
|
struct token *tok = peek_token();
|
||||||
|
|
||||||
Test(token_creation, empty)
|
enum token_type type_expected = TOKEN_WORD;
|
||||||
{
|
char string_expected[] = "echo";
|
||||||
char input[] = "";
|
|
||||||
|
cr_assert(eq(str, string_expected, tok->data));
|
||||||
char actual[] = new_token(input, 5);
|
cr_assert(type_expected == tok->type);
|
||||||
cr_expect(actual == NULL);
|
free_token(&tok);
|
||||||
}
|
|
||||||
|
// ======= hello
|
||||||
Test(token_creation, basic_long)
|
|
||||||
{
|
tok = peek_token();
|
||||||
char input[] = "Hello World! This project is a mini shell, I love BIG G.";
|
|
||||||
|
char string_expected2[] = "hello";
|
||||||
char actual[] = new_token(input, 42);
|
|
||||||
char expected[] = calloc(42 + 1, sizeof(char));
|
cr_assert(eq(str, string_expected2, tok->data));
|
||||||
strncpy(input, expected, 42);
|
cr_assert(type_expected == tok->type);
|
||||||
cr_expect(eq(str, actual, expected));
|
free_token(&tok);
|
||||||
free(actual);
|
|
||||||
free(expected);
|
// ======= 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