added build project test and fixed segfault

This commit is contained in:
Sven Vogel 2024-06-03 12:35:55 +02:00
parent 4703486daf
commit 3c5b9b7fe3
6 changed files with 49 additions and 1 deletions

View File

@ -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) { static int get_mode_from_str(TargetCompilationMode* mode, const char* name) {
if (mode == NULL) {
return PROJECT_SEMANTIC_ERR;
}
if (strcmp(name, "application") == 0) { if (strcmp(name, "application") == 0) {
*mode = Application; *mode = Application;
return PROJECT_OK; return PROJECT_OK;

View File

@ -9,4 +9,5 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
add_subdirectory(logging) add_subdirectory(logging)
add_subdirectory(input_file) add_subdirectory(input_file)
add_subdirectory(ast) add_subdirectory(ast)
add_subdirectory(glib) add_subdirectory(glib)
add_subdirectory(project)

View File

@ -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)

15
tests/project/build.toml Normal file
View File

@ -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"

View File

@ -0,0 +1,4 @@
fun main(out int: e) {
e = 0
}

View File

@ -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