From 3c5b9b7fe33c4db92752acc521693548711afa77 Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 3 Jun 2024 12:35:55 +0200 Subject: [PATCH] added build project test and fixed segfault --- src/cfg/opt.c | 4 ++++ tests/CMakeLists.txt | 3 ++- tests/project/CMakeLists.txt | 9 +++++++++ tests/project/build.toml | 15 +++++++++++++++ tests/project/src/main.txt | 4 ++++ tests/project/test_project.py | 15 +++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/project/CMakeLists.txt create mode 100644 tests/project/build.toml create mode 100644 tests/project/src/main.txt create mode 100644 tests/project/test_project.py diff --git a/src/cfg/opt.c b/src/cfg/opt.c index f58c93e..6de694e 100644 --- a/src/cfg/opt.c +++ b/src/cfg/opt.c @@ -258,6 +258,10 @@ static int parse_project_table(ProjectConfig *config, const toml_table_t *projec } static int get_mode_from_str(TargetCompilationMode* mode, const char* name) { + if (mode == NULL) { + return PROJECT_SEMANTIC_ERR; + } + if (strcmp(name, "application") == 0) { *mode = Application; return PROJECT_OK; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1228d2b..761b32c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,4 +9,5 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests) add_subdirectory(logging) add_subdirectory(input_file) add_subdirectory(ast) -add_subdirectory(glib) \ No newline at end of file +add_subdirectory(glib) +add_subdirectory(project) \ No newline at end of file diff --git a/tests/project/CMakeLists.txt b/tests/project/CMakeLists.txt new file mode 100644 index 0000000..2a8d3d6 --- /dev/null +++ b/tests/project/CMakeLists.txt @@ -0,0 +1,9 @@ +include(CTest) + +# ------------------------------------------------------- # +# CTEST 1 +# test if the program successfully reads the project config + +add_test(NAME project_build + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/project + COMMAND python ${GEMSTONE_TEST_DIR}/project/test_project.py) diff --git a/tests/project/build.toml b/tests/project/build.toml new file mode 100644 index 0000000..772f9a5 --- /dev/null +++ b/tests/project/build.toml @@ -0,0 +1,15 @@ +[project] +authors = [ "Sven Vogel" ] +license = "GPL-2.0" +version = "0.1.0" +description = "This is a test project" + +[target.debug] +root = "src/main.txt" +output = "bin" +archive = "archive" +opt = 1 +print_ast = true +print_asm = true +print_ir = true +mode = "application" diff --git a/tests/project/src/main.txt b/tests/project/src/main.txt new file mode 100644 index 0000000..3e3c969 --- /dev/null +++ b/tests/project/src/main.txt @@ -0,0 +1,4 @@ + +fun main(out int: e) { + e = 0 +} \ No newline at end of file diff --git a/tests/project/test_project.py b/tests/project/test_project.py new file mode 100644 index 0000000..1815c1c --- /dev/null +++ b/tests/project/test_project.py @@ -0,0 +1,15 @@ +import subprocess +import logging +from logging import info, error + +if __name__ == "__main__": + info("started check output...") + + p = subprocess.run([ "../../bin/debug/gsc", "build", "all" ], capture_output=True, text=True) + + info("checking exit code...") + + print(p.stdout) + + # check exit code + assert p.returncode == 0