fixed: failing tests due to changes

This commit is contained in:
Sven Vogel 2024-05-30 21:43:14 +02:00
parent 472a4a623c
commit cb8c7647bf
12 changed files with 70 additions and 25 deletions

View File

@ -170,6 +170,17 @@ TokenLocation new_location(unsigned long int line_start, unsigned long int col_s
return location; return location;
} }
TokenLocation empty_location(void) {
TokenLocation location;
location.line_start = 0;
location.line_end = 0;
location.col_start = 0;
location.col_end = 0;
return location;
}
void print_file_statistics(ModuleFile *file) { void print_file_statistics(ModuleFile *file) {
if (file->statistics.info_count + file->statistics.warning_count + file->statistics.error_count < 1) { if (file->statistics.info_count + file->statistics.warning_count + file->statistics.error_count < 1) {
return; return;

View File

@ -65,6 +65,8 @@ void delete_files(ModuleFileStack *stack);
TokenLocation new_location(unsigned long int line_start, unsigned long int col_start, unsigned long int line_end, TokenLocation new_location(unsigned long int line_start, unsigned long int col_start, unsigned long int line_end,
unsigned long int col_end); unsigned long int col_end);
TokenLocation empty_location(void);
[[gnu::nonnull(1), gnu::nonnull(2)]] [[gnu::nonnull(1), gnu::nonnull(2)]]
void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message); void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message);

View File

@ -10,7 +10,7 @@
#define LOG_LEVEL_INFORMATION 1 #define LOG_LEVEL_INFORMATION 1
#define LOG_LEVEL_DEBUG 0 #define LOG_LEVEL_DEBUG 0
#define LOG_LEVEL LOG_LEVEL_ERROR #define LOG_LEVEL LOG_LEVEL_DEBUG
#define LOG_STRING_PANIC "Critical" #define LOG_STRING_PANIC "Critical"
#define LOG_STRING_FATAL "Fatal" #define LOG_STRING_FATAL "Fatal"

View File

@ -2,6 +2,14 @@ include(CTest)
include_directories(${PROJECT_SOURCE_DIR}/src) include_directories(${PROJECT_SOURCE_DIR}/src)
# ------------------------------------------------ #
# Setup Glib 2.0 #
# ------------------------------------------------ #
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
# ------------------------------------------------------- # # ------------------------------------------------------- #
# CTEST 1 # CTEST 1
# test building the syntax tree # test building the syntax tree
@ -9,11 +17,14 @@ include_directories(${PROJECT_SOURCE_DIR}/src)
add_executable(ast_build_tree add_executable(ast_build_tree
${PROJECT_SOURCE_DIR}/src/ast/ast.c ${PROJECT_SOURCE_DIR}/src/ast/ast.c
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/io/files.c
${PROJECT_SOURCE_DIR}/src/sys/col.c
build_tree.c) build_tree.c)
set_target_properties(ast_build_tree set_target_properties(ast_build_tree
PROPERTIES PROPERTIES
OUTPUT_NAME "build_tree" OUTPUT_NAME "build_tree"
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast) RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast)
target_link_libraries(ast_build_tree PkgConfig::GLIB)
add_test(NAME ast_build_tree add_test(NAME ast_build_tree
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND python ${GEMSTONE_TEST_DIR}/ast/test_ast.py check_build_tree) COMMAND python ${GEMSTONE_TEST_DIR}/ast/test_ast.py check_build_tree)
@ -25,11 +36,14 @@ add_test(NAME ast_build_tree
add_executable(ast_print_node add_executable(ast_print_node
${PROJECT_SOURCE_DIR}/src/ast/ast.c ${PROJECT_SOURCE_DIR}/src/ast/ast.c
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/io/files.c
${PROJECT_SOURCE_DIR}/src/sys/col.c
print_node.c) print_node.c)
set_target_properties(ast_print_node set_target_properties(ast_print_node
PROPERTIES PROPERTIES
OUTPUT_NAME "print_node" OUTPUT_NAME "print_node"
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast) RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast)
target_link_libraries(ast_print_node PkgConfig::GLIB)
add_test(NAME ast_print_node add_test(NAME ast_print_node
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND python ${GEMSTONE_TEST_DIR}/ast/test_ast.py check_print_node) COMMAND python ${GEMSTONE_TEST_DIR}/ast/test_ast.py check_print_node)
@ -41,11 +55,14 @@ add_test(NAME ast_print_node
add_executable(ast_graphviz add_executable(ast_graphviz
${PROJECT_SOURCE_DIR}/src/ast/ast.c ${PROJECT_SOURCE_DIR}/src/ast/ast.c
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/io/files.c
${PROJECT_SOURCE_DIR}/src/sys/col.c
print_graphviz.c) print_graphviz.c)
set_target_properties(ast_graphviz set_target_properties(ast_graphviz
PROPERTIES PROPERTIES
OUTPUT_NAME "print_graphviz" OUTPUT_NAME "print_graphviz"
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast) RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast)
target_link_libraries(ast_graphviz PkgConfig::GLIB)
add_test(NAME ast_graphviz add_test(NAME ast_graphviz
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND python ${GEMSTONE_TEST_DIR}/ast/test_ast.py check_print_graphviz) COMMAND python ${GEMSTONE_TEST_DIR}/ast/test_ast.py check_print_graphviz)

View File

@ -6,22 +6,22 @@
#include <sys/log.h> #include <sys/log.h>
void generate_statement(const AST_NODE_PTR stmt) { void generate_statement(const AST_NODE_PTR stmt) {
const AST_NODE_PTR add = AST_new_node(AST_Add, NULL); const AST_NODE_PTR add = AST_new_node(empty_location(), AST_Add, NULL);
AST_push_node(add, AST_new_node(AST_Int, "3")); AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3"));
AST_push_node(add, AST_new_node(AST_Int, "6")); AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6"));
AST_push_node(stmt, add); AST_push_node(stmt, add);
} }
void generate_branch(const AST_NODE_PTR stmt) { void generate_branch(const AST_NODE_PTR stmt) {
const AST_NODE_PTR branch = AST_new_node(AST_If, NULL); const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL);
const AST_NODE_PTR gt = AST_new_node(AST_Greater, NULL); const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL);
AST_push_node(branch, gt); AST_push_node(branch, gt);
AST_push_node(gt, AST_new_node(AST_Float, "2.3")); AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "2.3"));
AST_push_node(gt, AST_new_node(AST_Float, "0.79")); AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79"));
AST_push_node(stmt, branch); AST_push_node(stmt, branch);
@ -30,7 +30,7 @@ void generate_branch(const AST_NODE_PTR stmt) {
int main(void) { int main(void) {
const AST_NODE_PTR root = AST_new_node(AST_Stmt, NULL); const AST_NODE_PTR root = AST_new_node(empty_location(), AST_Stmt, NULL);
generate_branch(root); generate_branch(root);

View File

@ -7,15 +7,15 @@
int main(void) { int main(void) {
struct AST_Node_t* node = AST_new_node(AST_If, NULL); struct AST_Node_t* node = AST_new_node(empty_location(), AST_If, NULL);
struct AST_Node_t* child = AST_new_node(AST_Add, NULL); struct AST_Node_t* child = AST_new_node(empty_location(), AST_Add, NULL);
AST_push_node(child, AST_new_node(AST_Int, "43")); AST_push_node(child, AST_new_node(empty_location(), AST_Int, "43"));
AST_push_node(child, AST_new_node(AST_Int, "9")); AST_push_node(child, AST_new_node(empty_location(), AST_Int, "9"));
AST_push_node(node, child); AST_push_node(node, child);
AST_push_node(node, AST_new_node(AST_Expr, NULL)); AST_push_node(node, AST_new_node(empty_location(), AST_Expr, NULL));
AST_push_node(node, AST_new_node(AST_Expr, NULL)); AST_push_node(node, AST_new_node(empty_location(), AST_Expr, NULL));
FILE* out = fopen("ast.gv", "w+"); FILE* out = fopen("ast.gv", "w+");
// convert this file ^^^^^^ // convert this file ^^^^^^

View File

@ -6,22 +6,22 @@
#include <sys/log.h> #include <sys/log.h>
void generate_statement(const AST_NODE_PTR stmt) { void generate_statement(const AST_NODE_PTR stmt) {
const AST_NODE_PTR add = AST_new_node(AST_Add, NULL); const AST_NODE_PTR add = AST_new_node(empty_location(), AST_Add, NULL);
AST_push_node(add, AST_new_node(AST_Int, "3")); AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3"));
AST_push_node(add, AST_new_node(AST_Int, "6")); AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6"));
AST_push_node(stmt, add); AST_push_node(stmt, add);
} }
void generate_branch(const AST_NODE_PTR stmt) { void generate_branch(const AST_NODE_PTR stmt) {
const AST_NODE_PTR branch = AST_new_node(AST_If, NULL); const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL);
const AST_NODE_PTR gt = AST_new_node(AST_Greater, NULL); const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL);
AST_push_node(branch, gt); AST_push_node(branch, gt);
AST_push_node(gt, AST_new_node(AST_Float, "2.3")); AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "2.3"));
AST_push_node(gt, AST_new_node(AST_Float, "0.79")); AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79"));
AST_push_node(stmt, branch); AST_push_node(stmt, branch);
@ -32,7 +32,7 @@ int main(void) {
AST_init(); AST_init();
const AST_NODE_PTR root = AST_new_node(AST_Stmt, NULL); const AST_NODE_PTR root = AST_new_node(empty_location(), AST_Stmt, NULL);
generate_branch(root); generate_branch(root);

View File

@ -8,7 +8,7 @@ int main(void) {
AST_init(); AST_init();
const AST_NODE_PTR node = AST_new_node(0, "value"); const AST_NODE_PTR node = AST_new_node(empty_location(), 0, "value");
for (size_t i = 0; i < AST_ELEMENT_COUNT; i++) { for (size_t i = 0; i < AST_ELEMENT_COUNT; i++) {
// set kind // set kind

View File

@ -2,12 +2,20 @@ include(CTest)
include_directories(${PROJECT_SOURCE_DIR}/src) include_directories(${PROJECT_SOURCE_DIR}/src)
# ------------------------------------------------ #
# Setup Glib 2.0 #
# ------------------------------------------------ #
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
# ------------------------------------------------------- # # ------------------------------------------------------- #
# CTEST 1 # CTEST 1
# test the default output of the logger # test the default output of the logger
add_executable(logging_output add_executable(logging_output
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/sys/col.c
output.c) output.c)
set_target_properties(logging_output set_target_properties(logging_output
PROPERTIES PROPERTIES
@ -23,6 +31,7 @@ add_test(NAME logging_output
add_executable(logging_panic add_executable(logging_panic
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/sys/col.c
panic.c) panic.c)
set_target_properties(logging_panic set_target_properties(logging_panic
PROPERTIES PROPERTIES
@ -38,6 +47,7 @@ add_test(NAME logging_panic
add_executable(logging_streams add_executable(logging_streams
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/sys/col.c
streams.c) streams.c)
set_target_properties(logging_streams set_target_properties(logging_streams
PROPERTIES PROPERTIES
@ -53,6 +63,7 @@ add_test(NAME logging_streams
add_executable(logging_level add_executable(logging_level
${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/log.c
${PROJECT_SOURCE_DIR}/src/sys/col.c
level.c) level.c)
set_target_properties(logging_level set_target_properties(logging_level
PROPERTIES PROPERTIES

View File

@ -3,11 +3,13 @@
// //
#include "sys/log.h" #include "sys/log.h"
#include <sys/col.h>
#define LOG_LEVEL LOG_LEVEL_WARNING #define LOG_LEVEL LOG_LEVEL_WARNING
int main(void) { int main(void) {
log_init(); log_init();
col_init();
DEBUG("logging some debug..."); DEBUG("logging some debug...");
INFO("logging some info..."); INFO("logging some info...");

View File

@ -3,9 +3,11 @@
// //
#include "sys/log.h" #include "sys/log.h"
#include <sys/col.h>
int main(void) { int main(void) {
log_init(); log_init();
col_init();
DEBUG("logging some debug..."); DEBUG("logging some debug...");
INFO("logging some info..."); INFO("logging some info...");