From cb8c7647bf859513ec815221b054fbd77cd1aba3 Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 30 May 2024 21:43:14 +0200 Subject: [PATCH] fixed: failing tests due to changes --- CMakeLists.txt | 2 +- src/io/files.c | 11 +++++++++++ src/io/files.h | 2 ++ src/sys/log.h | 2 +- tests/ast/CMakeLists.txt | 17 +++++++++++++++++ tests/ast/build_tree.c | 16 ++++++++-------- tests/ast/gen_graph.c | 12 ++++++------ tests/ast/print_graphviz.c | 16 ++++++++-------- tests/ast/print_node.c | 2 +- tests/logging/CMakeLists.txt | 11 +++++++++++ tests/logging/level.c | 2 ++ tests/logging/output.c | 2 ++ 12 files changed, 70 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b304447..cab901a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,7 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} find_package(PkgConfig REQUIRED) pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) - + # ------------------------------------------------ # # Source # # ------------------------------------------------ # diff --git a/src/io/files.c b/src/io/files.c index 97daed1..2d4fda7 100644 --- a/src/io/files.c +++ b/src/io/files.c @@ -170,6 +170,17 @@ TokenLocation new_location(unsigned long int line_start, unsigned long int col_s 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) { if (file->statistics.info_count + file->statistics.warning_count + file->statistics.error_count < 1) { return; diff --git a/src/io/files.h b/src/io/files.h index 5441805..076b8d0 100644 --- a/src/io/files.h +++ b/src/io/files.h @@ -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, unsigned long int col_end); +TokenLocation empty_location(void); + [[gnu::nonnull(1), gnu::nonnull(2)]] void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message); diff --git a/src/sys/log.h b/src/sys/log.h index 50fded1..6b8991d 100644 --- a/src/sys/log.h +++ b/src/sys/log.h @@ -10,7 +10,7 @@ #define LOG_LEVEL_INFORMATION 1 #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_FATAL "Fatal" diff --git a/tests/ast/CMakeLists.txt b/tests/ast/CMakeLists.txt index 455130b..88007e4 100644 --- a/tests/ast/CMakeLists.txt +++ b/tests/ast/CMakeLists.txt @@ -2,6 +2,14 @@ include(CTest) 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 # test building the syntax tree @@ -9,11 +17,14 @@ include_directories(${PROJECT_SOURCE_DIR}/src) add_executable(ast_build_tree ${PROJECT_SOURCE_DIR}/src/ast/ast.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) set_target_properties(ast_build_tree PROPERTIES OUTPUT_NAME "build_tree" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast) +target_link_libraries(ast_build_tree PkgConfig::GLIB) add_test(NAME ast_build_tree WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 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 ${PROJECT_SOURCE_DIR}/src/ast/ast.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) set_target_properties(ast_print_node PROPERTIES OUTPUT_NAME "print_node" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast) +target_link_libraries(ast_print_node PkgConfig::GLIB) add_test(NAME ast_print_node WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 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 ${PROJECT_SOURCE_DIR}/src/ast/ast.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) set_target_properties(ast_graphviz PROPERTIES OUTPUT_NAME "print_graphviz" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/ast) +target_link_libraries(ast_graphviz PkgConfig::GLIB) add_test(NAME ast_graphviz WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/ast/test_ast.py check_print_graphviz) diff --git a/tests/ast/build_tree.c b/tests/ast/build_tree.c index dec7b85..2d2459b 100644 --- a/tests/ast/build_tree.c +++ b/tests/ast/build_tree.c @@ -6,22 +6,22 @@ #include 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(AST_Int, "6")); + AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3")); + AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6")); AST_push_node(stmt, add); } void generate_branch(const AST_NODE_PTR stmt) { - const AST_NODE_PTR branch = AST_new_node(AST_If, NULL); - const AST_NODE_PTR gt = AST_new_node(AST_Greater, NULL); + const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL); + const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL); AST_push_node(branch, gt); - AST_push_node(gt, AST_new_node(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, "2.3")); + AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79")); AST_push_node(stmt, branch); @@ -30,7 +30,7 @@ void generate_branch(const AST_NODE_PTR stmt) { 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); diff --git a/tests/ast/gen_graph.c b/tests/ast/gen_graph.c index 186d571..c4e2f92 100644 --- a/tests/ast/gen_graph.c +++ b/tests/ast/gen_graph.c @@ -7,15 +7,15 @@ 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); - AST_push_node(child, AST_new_node(AST_Int, "43")); - AST_push_node(child, AST_new_node(AST_Int, "9")); + struct AST_Node_t* child = AST_new_node(empty_location(), AST_Add, NULL); + AST_push_node(child, AST_new_node(empty_location(), AST_Int, "43")); + AST_push_node(child, AST_new_node(empty_location(), AST_Int, "9")); AST_push_node(node, child); - AST_push_node(node, AST_new_node(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)); + AST_push_node(node, AST_new_node(empty_location(), AST_Expr, NULL)); FILE* out = fopen("ast.gv", "w+"); // convert this file ^^^^^^ diff --git a/tests/ast/print_graphviz.c b/tests/ast/print_graphviz.c index 6df64b4..c0f69af 100644 --- a/tests/ast/print_graphviz.c +++ b/tests/ast/print_graphviz.c @@ -6,22 +6,22 @@ #include 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(AST_Int, "6")); + AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3")); + AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6")); AST_push_node(stmt, add); } void generate_branch(const AST_NODE_PTR stmt) { - const AST_NODE_PTR branch = AST_new_node(AST_If, NULL); - const AST_NODE_PTR gt = AST_new_node(AST_Greater, NULL); + const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL); + const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL); AST_push_node(branch, gt); - AST_push_node(gt, AST_new_node(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, "2.3")); + AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79")); AST_push_node(stmt, branch); @@ -32,7 +32,7 @@ int main(void) { 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); diff --git a/tests/ast/print_node.c b/tests/ast/print_node.c index 38e8a41..47db685 100644 --- a/tests/ast/print_node.c +++ b/tests/ast/print_node.c @@ -8,7 +8,7 @@ int main(void) { 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++) { // set kind diff --git a/tests/logging/CMakeLists.txt b/tests/logging/CMakeLists.txt index 0f14079..d5abada 100644 --- a/tests/logging/CMakeLists.txt +++ b/tests/logging/CMakeLists.txt @@ -2,12 +2,20 @@ include(CTest) 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 # test the default output of the logger add_executable(logging_output ${PROJECT_SOURCE_DIR}/src/sys/log.c + ${PROJECT_SOURCE_DIR}/src/sys/col.c output.c) set_target_properties(logging_output PROPERTIES @@ -23,6 +31,7 @@ add_test(NAME logging_output add_executable(logging_panic ${PROJECT_SOURCE_DIR}/src/sys/log.c + ${PROJECT_SOURCE_DIR}/src/sys/col.c panic.c) set_target_properties(logging_panic PROPERTIES @@ -38,6 +47,7 @@ add_test(NAME logging_panic add_executable(logging_streams ${PROJECT_SOURCE_DIR}/src/sys/log.c + ${PROJECT_SOURCE_DIR}/src/sys/col.c streams.c) set_target_properties(logging_streams PROPERTIES @@ -53,6 +63,7 @@ add_test(NAME logging_streams add_executable(logging_level ${PROJECT_SOURCE_DIR}/src/sys/log.c + ${PROJECT_SOURCE_DIR}/src/sys/col.c level.c) set_target_properties(logging_level PROPERTIES diff --git a/tests/logging/level.c b/tests/logging/level.c index 6a4f055..fd37cc7 100644 --- a/tests/logging/level.c +++ b/tests/logging/level.c @@ -3,11 +3,13 @@ // #include "sys/log.h" +#include #define LOG_LEVEL LOG_LEVEL_WARNING int main(void) { log_init(); + col_init(); DEBUG("logging some debug..."); INFO("logging some info..."); diff --git a/tests/logging/output.c b/tests/logging/output.c index 7accfc5..dde7d90 100644 --- a/tests/logging/output.c +++ b/tests/logging/output.c @@ -3,9 +3,11 @@ // #include "sys/log.h" +#include int main(void) { log_init(); + col_init(); DEBUG("logging some debug..."); INFO("logging some info...");