From e90cd80fbef33e87337c61de8e09ca754bf42b9b Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Sun, 21 Apr 2024 22:48:29 +0200 Subject: [PATCH 01/29] added prototype for File-reading to main.c --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index 8bb8127..3c1edd2 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,10 @@ void setup(void) int main(void) { setup(); + + FILE* input = fopen("program.gem", "r"); + + yyin = input; yyparse(); return 0; From 1cfe9485e9fb0a65fee9f39f1851ad18b9452094 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 11:51:27 +0200 Subject: [PATCH 02/29] added case for missing input of file to main.c --- src/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.c b/src/main.c index 3c1edd2..a152df0 100644 --- a/src/main.c +++ b/src/main.c @@ -38,8 +38,16 @@ int main(void) { FILE* input = fopen("program.gem", "r"); + if (input == NULL) + { + printf("Error opening file!\n"); + return 1; // Error when opening file + } + yyin = input; + fclose(input); + yyparse(); return 0; } From 6fca12df390908837f93b190764ed97be5ed4540 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:53:48 +0200 Subject: [PATCH 03/29] modified main.c -added Error-message from Logging API. -changed exit and moved after yyparse() -added extern for file name todo: make file name user input variable. --- src/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index a152df0..89c214f 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,8 @@ #define LOG_LEVEL LOG_LEVEL_DEBUG +extern FILE* yyin; + /** * @brief Log a debug message to inform about beginning exit procedures * @@ -38,10 +40,10 @@ int main(void) { FILE* input = fopen("program.gem", "r"); - if (input == NULL) + if (NULL == Input) { - printf("Error opening file!\n"); - return 1; // Error when opening file + ERROR("File couldn't be opened!"); + atexit(); } yyin = input; @@ -49,5 +51,7 @@ int main(void) { fclose(input); yyparse(); + + atexit(); return 0; } From 6d249dd9ea1ff742acd2a59153d18854f64eb3c5 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:54:20 +0200 Subject: [PATCH 04/29] Update main.c deleted fclose() --- src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.c b/src/main.c index 89c214f..a24eb7a 100644 --- a/src/main.c +++ b/src/main.c @@ -48,8 +48,6 @@ int main(void) { yyin = input; - fclose(input); - yyparse(); atexit(); From 4976aeb22f19ed0effd87bcbe5f34dafe5107c43 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:57:49 +0200 Subject: [PATCH 05/29] Update main.c fixed typo --- src/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index a24eb7a..f5d242a 100644 --- a/src/main.c +++ b/src/main.c @@ -40,16 +40,15 @@ int main(void) { FILE* input = fopen("program.gem", "r"); - if (NULL == Input) + if (NULL == input) { ERROR("File couldn't be opened!"); - atexit(); } yyin = input; yyparse(); - atexit(); + atexit(input); return 0; } From aa7c62f0215b51a3c22a66dc59fb60000b86c7b1 Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 22 Apr 2024 13:15:33 +0200 Subject: [PATCH 06/29] Devkit now pulls source from main branch of the repository Added git to SDK Bumped version from 0.2.0 to 0.2.1 --- Dockerfile | 9 ++++----- sdk/Dockerfile | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1d5ce4b..ce2db20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ -FROM servostar/gemstone:sdk-0.2.0-alpine-3.19.1 +FROM servostar/gemstone:sdk-0.2.1-alpine-3.19.1 LABEL authors="servostar" -LABEL version="0.2.0" +LABEL version="0.2.1" LABEL description="docker image for setting up the build pipeline on SDK" LABEL website="https://github.com/Servostar/gemstone" -COPY --chown=lorang src /home/lorang/src -COPY --chown=lorang CMakeLists.txt /home/lorang/ +RUN git clone https://github.com/Servostar/gemstone.git /home/lorang -RUN cmake . \ No newline at end of file +RUN cmake . diff --git a/sdk/Dockerfile b/sdk/Dockerfile index 098f659..4dbeb1f 100644 --- a/sdk/Dockerfile +++ b/sdk/Dockerfile @@ -1,13 +1,13 @@ FROM alpine:3.19.1 LABEL authors="servostar" -LABEL version="0.2.0" +LABEL version="0.2.1" LABEL description="base image for building the gemstone programming language compiler" LABEL website="https://github.com/Servostar/gemstone" # install dependencies -RUN apk add build-base gcc make cmake bison flex +RUN apk add build-base gcc make cmake bison flex git # create user for build RUN adduser --disabled-password lorang WORKDIR /home/lorang -USER lorang \ No newline at end of file +USER lorang From ebb29807c85533d73f076a76b00171c289df02c7 Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 22 Apr 2024 13:31:20 +0200 Subject: [PATCH 07/29] bumped SDK version to 0.2.1 --- .github/workflows/build-check-sdk.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index aed27d4..5b8f2aa 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -2,7 +2,7 @@ name: "Build check gemstone in SDK" run-name: SDK build check to ${{ inputs.deploy_target }} by @${{ github.actor }} on: [push, pull_request] env: - SDK: 0.1.0-alma-9.3 + SDK: 0.2.1-alpine-3.19.1 jobs: build-check-sdk: runs-on: ubuntu-latest From 05d603f7ac3b48fc267ab8f9d06931750f3be7e2 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:41:37 +0200 Subject: [PATCH 08/29] Update main.c added Function for file closing --- src/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index f5d242a..6617ed8 100644 --- a/src/main.c +++ b/src/main.c @@ -31,12 +31,23 @@ void setup(void) #endif // actual setup - + DEBUG("finished starting up gemstone..."); } +/** + * @brief Closes File after compiling. + * + */ + +void close_file(void) +{ + fclose(input); +} + int main(void) { setup(); + atexit(close_file); FILE* input = fopen("program.gem", "r"); @@ -49,6 +60,5 @@ int main(void) { yyparse(); - atexit(input); return 0; } From a85558e118cda0bdec393a16a1898179c443cafe Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:01:18 +0200 Subject: [PATCH 09/29] Update main.c changed close_file Function changed ERROR to PANIC --- src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 6617ed8..f96edf3 100644 --- a/src/main.c +++ b/src/main.c @@ -42,7 +42,7 @@ void setup(void) void close_file(void) { - fclose(input); + fclose(yyin); } int main(void) { @@ -53,7 +53,7 @@ int main(void) { if (NULL == input) { - ERROR("File couldn't be opened!"); + PANIC("File couldn't be opened!"); } yyin = input; From 7797595fef71fa52efbbad7566f9a9666926da4e Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:25:49 +0200 Subject: [PATCH 10/29] Update main.c added File Insertion through arguments --- src/main.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index f96edf3..d96e0fd 100644 --- a/src/main.c +++ b/src/main.c @@ -4,8 +4,6 @@ #define LOG_LEVEL LOG_LEVEL_DEBUG -extern FILE* yyin; - /** * @brief Log a debug message to inform about beginning exit procedures * @@ -42,16 +40,27 @@ void setup(void) void close_file(void) { - fclose(yyin); + fclose(argv[1]); } -int main(void) { +int main(int argc, char *argv[]) { + setup(); atexit(close_file); - - FILE* input = fopen("program.gem", "r"); - if (NULL == input) + // Check for file input as argument + if (2 != argc) + { + printf("Usage: %s \n", argv[0]); + PANIC("No File could be found"); + } + + // filename as first argument + char *filename = argv[1]; + + FILE *file = fopen(filename, "r"); + + if (NULL == file) { PANIC("File couldn't be opened!"); } From dad9cbb93a3966d2a91d4d4dae4efb0a81fea435 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:32:00 +0200 Subject: [PATCH 11/29] Update main.c fixed typo --- src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.c b/src/main.c index d96e0fd..bbcf14b 100644 --- a/src/main.c +++ b/src/main.c @@ -64,8 +64,6 @@ int main(int argc, char *argv[]) { { PANIC("File couldn't be opened!"); } - - yyin = input; yyparse(); From fafcb942e02c8967c47cd7f88c9114463701e2d9 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:38:30 +0200 Subject: [PATCH 12/29] Update main.c fixed typo, and changed close_file function --- src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index bbcf14b..dd9dde2 100644 --- a/src/main.c +++ b/src/main.c @@ -38,15 +38,15 @@ void setup(void) * */ -void close_file(void) +void close_file(char file_to_close) { - fclose(argv[1]); + fclose(file_to_close); } int main(int argc, char *argv[]) { setup(); - atexit(close_file); + atexit(close_file(filename); // Check for file input as argument if (2 != argc) From 520520e576b052645226c1ed3f5c1ea836c68be5 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:27:11 +0200 Subject: [PATCH 13/29] Update main.c moved atexit() to setup --- src/main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index dd9dde2..db22990 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,16 @@ void notify_exit(void) DEBUG("Exiting gemstone..."); } +/** + * @brief Closes File after compiling. + * + */ + +void close_file(char file_to_close) +{ + fclose(file_to_close); +} + /** * @brief Run compiler setup here * @@ -31,27 +41,17 @@ void setup(void) // actual setup DEBUG("finished starting up gemstone..."); -} - -/** - * @brief Closes File after compiling. - * - */ - -void close_file(char file_to_close) -{ - fclose(file_to_close); + atexit(close_file(filename)); } int main(int argc, char *argv[]) { setup(); - atexit(close_file(filename); // Check for file input as argument if (2 != argc) { - printf("Usage: %s \n", argv[0]); + INFO("Usage: %s \n", argv[0]); PANIC("No File could be found"); } From 501f6f1602f03cc876a2dc95db680ef011c85102 Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 24 Apr 2024 22:31:35 +0200 Subject: [PATCH 14/29] file name macro searches for last char instead of last string --- src/sys/log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/log.h b/src/sys/log.h index 691a38e..aa18c88 100644 --- a/src/sys/log.h +++ b/src/sys/log.h @@ -24,7 +24,7 @@ // generally not defined by GCC < 11.3 and MSVC #ifndef __FILE_NAME__ #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) -#define __FILE_NAME__ (strrstr(__FILE__, "\\") ? strrstr(__FILE__, "\\") + 1 : __FILE__) +#define __FILE_NAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #else #define __FILE_NAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) #endif From d673d1de0a6bf53b0b85c45e50a3bf852e574781 Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 24 Apr 2024 22:36:58 +0200 Subject: [PATCH 15/29] removed dependency of unistd.h from lexer --- src/lex/lexer.l | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index 8823195..c1efd4f 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -12,6 +12,9 @@ %option nounput %option noinput +/* prevent depency of unistd.h */ +%option nounistd + %% "\n" yyLineNumber++; From 8cd1f2fb0d5ef0c010f941ec33d082b21d3bf92c Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 24 Apr 2024 22:37:21 +0200 Subject: [PATCH 16/29] added compile flags which differ for MSVC and other compiler (GCC/Clang) --- CMakeLists.txt | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31b5c87..7f27873 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,11 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} file(GLOB_RECURSE SOURCE_FILES src/*.c) # define default compile flags -set(FLAGS -Wall -Wextra -Wconversion -Wpedantic) +if (MSVC) + set(FLAGS /Wall /W3 /permissive) +else() + set(FLAGS -Wall -Wextra -Wconversion -Wpedantic) +endif() # ------------------------------------------------ # # Target RELEASE # @@ -72,13 +76,20 @@ set_target_properties(release OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY "bin/release") +# FIXME: cannot compile with /O2 because of /RTC1 flag +if (MSVC) + set(RELEASE_FLAGS) +else() + set(RELEASE_FLAGS -m64 -O3 -fprefetch-loop-arrays -mrecip) +endif() + # compiler flags targeting a 64-bit GCC release environment # flags: # - m64: build for 64-bit # - O3: optimization level 3 # - fprefetch-loop-arrays: pre load arrays used in loops by using prefetch instruction # - mrecip: make use RCPSS and RSQRTSS instructions -target_compile_options(release PUBLIC ${FLAGS} -m64 -O3 -fprefetch-loop-arrays -mrecip) +target_compile_options(release PUBLIC ${FLAGS} ${RELEASE_FLAGS}) # add src directory as include path target_include_directories(release PUBLIC src) @@ -97,8 +108,14 @@ set_target_properties(debug OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY "bin/debug") +if (MSVC) + set(DEBUG_FLAGS /DEBUG) +else() + set(DEBUG_FLAGS -g) +endif() + # compiler flags targeting a GCC debug environment -target_compile_options(debug PUBLIC ${FLAGS} -g) +target_compile_options(debug PUBLIC ${FLAGS} ${DEBUG_FLAGS}) # add src directory as include path target_include_directories(debug PUBLIC src) @@ -120,9 +137,15 @@ set_target_properties(check OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY "bin/check") +if (MSVC) + set(CHECK_FLAGS /DEBUG /WX) +else() + set(DEBUG_FLAGS -g /Werror) +endif() + # compiler flags targeting a GCC debug environment # extra -Werror flag to treat warnings as error to make github action fail on warning -target_compile_options(check PUBLIC ${FLAGS} -g -Werror) +target_compile_options(check PUBLIC ${FLAGS} ${DEBUG_FLAGS}) # add src directory as include path target_include_directories(check PUBLIC src) From df927cf7d62fdb6f1ee3ce37575b32044270e4ea Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 24 Apr 2024 22:47:59 +0200 Subject: [PATCH 17/29] fixed flag error and made option nounistd in lexer depend on compiler used --- CMakeLists.txt | 7 ++++++- src/lex/lexer.l | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f27873..1cfeefc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,11 @@ add_custom_command(OUTPUT ${LEX_GENERATED_SOURCE_FILE} COMMENT "generate C source file for lexer" VERBATIM) +# remove dependency when compiling with MSVC on windows +if (MSVC) + add_compile_definitions(YY_NO_UNISTD_H) +endif() + # ------------------------------------------------ # # Yacc # # ------------------------------------------------ # @@ -140,7 +145,7 @@ set_target_properties(check if (MSVC) set(CHECK_FLAGS /DEBUG /WX) else() - set(DEBUG_FLAGS -g /Werror) + set(DEBUG_FLAGS -g -Werror) endif() # compiler flags targeting a GCC debug environment diff --git a/src/lex/lexer.l b/src/lex/lexer.l index c1efd4f..8823195 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -12,9 +12,6 @@ %option nounput %option noinput -/* prevent depency of unistd.h */ -%option nounistd - %% "\n" yyLineNumber++; From 6f30be17e9d9f2c94f96ceca5578753a737b81c1 Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 24 Apr 2024 23:58:15 +0200 Subject: [PATCH 18/29] added dependency section in README --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 854f2f2..a1e442b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,25 @@ Gemstone is a programming language compiler written in C with lex and yacc. +## Dependencies (build) + +### Windows 11 + +For setup instruction see issue #30 + +Requires: +- Microsoft Build Tools 2022 (includes: CMake, MSVC) +- WinFlexBison [find it here](https://github.com/lexxmark/winflexbison) (needs to be in PATH) + +### GNU/Linux + +Requires: +- GCC +- CMake +- Make +- bison +- flex + ## Development with VSCode/Codium Recommended extensions for getting a decent experience are the following: @@ -55,4 +74,4 @@ Currently, the SDK is based on Almalinux 9.3, an open source distro binary compa The following images can be found in the offical repository at [Docker Hub](https://hub.docker.com/r/servostar/gemstone): - SDK -- Devkit \ No newline at end of file +- Devkit From 5f53d1dce46555d9ffc403078d24a7197735deb9 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:02:12 +0200 Subject: [PATCH 19/29] Update main.c changed indendation and declared and initialized yyin after file opening --- src/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index db22990..04ab464 100644 --- a/src/main.c +++ b/src/main.c @@ -41,13 +41,13 @@ void setup(void) // actual setup DEBUG("finished starting up gemstone..."); - atexit(close_file(filename)); } int main(int argc, char *argv[]) { setup(); - + atexit(close_file(filename)); + // Check for file input as argument if (2 != argc) { @@ -58,13 +58,14 @@ int main(int argc, char *argv[]) { // filename as first argument char *filename = argv[1]; - FILE *file = fopen(filename, "r"); - if (NULL == file) { PANIC("File couldn't be opened!"); } + FILE *file = fopen(filename, "r"); + *file = yyin; + yyparse(); return 0; From 72bba3278aaa4860bedc0369afc15182a72eaacd Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Fri, 26 Apr 2024 16:21:54 +0200 Subject: [PATCH 20/29] updated main.c --- src/main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 04ab464..38cf9c9 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,8 @@ #define LOG_LEVEL LOG_LEVEL_DEBUG +extern FILE* yyin; + /** * @brief Log a debug message to inform about beginning exit procedures * @@ -18,9 +20,12 @@ void notify_exit(void) * */ -void close_file(char file_to_close) +void close_file(void) { - fclose(file_to_close); + if (NULL != yyin) + { + fclose(yyin); + } } /** @@ -46,7 +51,7 @@ void setup(void) int main(int argc, char *argv[]) { setup(); - atexit(close_file(filename)); + atexit(close_file); // Check for file input as argument if (2 != argc) @@ -58,13 +63,13 @@ int main(int argc, char *argv[]) { // filename as first argument char *filename = argv[1]; + FILE *file = fopen(filename, "r"); + if (NULL == file) { PANIC("File couldn't be opened!"); } - - FILE *file = fopen(filename, "r"); - *file = yyin; + yyin = file; yyparse(); From b386c1104388961fb168a38736a02f66c65adbfb Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 08:26:18 +0200 Subject: [PATCH 21/29] added first test --- .gitignore | 3 ++- CMakeLists.txt | 15 ++++++++++++--- tests/CMakeLists.txt | 9 +++++++++ tests/logging/CMakeLists.txt | 9 +++++++++ tests/logging/check_output.py | 22 ++++++++++++++++++++++ tests/logging/main.c | 16 ++++++++++++++++ 6 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/logging/CMakeLists.txt create mode 100644 tests/logging/check_output.py create mode 100644 tests/logging/main.c diff --git a/.gitignore b/.gitignore index eee6202..bb676ce 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ Makefile lexer.ll.c parser.tab.c parser.tab.h -build \ No newline at end of file +build +/Testing/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cfeefc..079fc47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,15 @@ project(gemstone DESCRIPTION "programming language compiler" LANGUAGES C) +set(GEMSTONE_TEST_DIR ${PROJECT_SOURCE_DIR}/tests) +set(GEMSTONE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin) + +include(CTest) + +if(BUILD_TESTING) + add_subdirectory(tests) +endif() + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # ------------------------------------------------ # @@ -79,7 +88,7 @@ add_executable(release set_target_properties(release PROPERTIES OUTPUT_NAME "gsc" - RUNTIME_OUTPUT_DIRECTORY "bin/release") + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release) # FIXME: cannot compile with /O2 because of /RTC1 flag if (MSVC) @@ -111,7 +120,7 @@ add_executable(debug set_target_properties(debug PROPERTIES OUTPUT_NAME "gsc" - RUNTIME_OUTPUT_DIRECTORY "bin/debug") + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug) if (MSVC) set(DEBUG_FLAGS /DEBUG) @@ -140,7 +149,7 @@ add_executable(check set_target_properties(check PROPERTIES OUTPUT_NAME "gsc" - RUNTIME_OUTPUT_DIRECTORY "bin/check") + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check) if (MSVC) set(CHECK_FLAGS /DEBUG /WX) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..2602430 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,9 @@ +include(CTest) + +set(PROJECT_BINARY_DIR bin) +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/tests) +set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests) + +# Provide test to run here or include another CMakeLists.txt + +add_subdirectory(logging) \ No newline at end of file diff --git a/tests/logging/CMakeLists.txt b/tests/logging/CMakeLists.txt new file mode 100644 index 0000000..ebc9962 --- /dev/null +++ b/tests/logging/CMakeLists.txt @@ -0,0 +1,9 @@ +include(CTest) + +add_executable(logging ${PROJECT_SOURCE_DIR}/src/sys/log.c main.c) +target_include_directories(logging PUBLIC ${PROJECT_SOURCE_DIR}/src) +set_target_properties(logging + PROPERTIES + OUTPUT_NAME "output" + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging) +add_test(NAME logging WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/check_output.py) diff --git a/tests/logging/check_output.py b/tests/logging/check_output.py new file mode 100644 index 0000000..b908cda --- /dev/null +++ b/tests/logging/check_output.py @@ -0,0 +1,22 @@ +import subprocess + + +def run_logger_test(): + p = subprocess.run("bin/tests/logging/output", capture_output=True, text=True) + + # check exit code + if p.returncode != 0: + exit(p.returncode) + + output = p.stderr + + # check if logs appear in default log output (stderr) + + assert "logging some debug..." in output + assert "logging some info..." in output + assert "logging some warning..." in output + assert "logging some error..." in output + + +if __name__ == "__main__": + run_logger_test() diff --git a/tests/logging/main.c b/tests/logging/main.c new file mode 100644 index 0000000..7accfc5 --- /dev/null +++ b/tests/logging/main.c @@ -0,0 +1,16 @@ +// +// Created by servostar on 5/1/24. +// + +#include "sys/log.h" + +int main(void) { + log_init(); + + DEBUG("logging some debug..."); + INFO("logging some info..."); + WARN("logging some warning..."); + ERROR("logging some error..."); + + return 0; +} From 4b24e0645cd9da75c3e42b2b6d5a167fba1cbb84 Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 09:49:14 +0200 Subject: [PATCH 22/29] added test for logger panic --- tests/logging/CMakeLists.txt | 24 +++++++++-- tests/logging/check_output.py | 22 ---------- tests/logging/{main.c => output.c} | 0 tests/logging/panic.c | 20 ++++++++++ tests/logging/test_logging.py | 64 ++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 26 deletions(-) delete mode 100644 tests/logging/check_output.py rename tests/logging/{main.c => output.c} (100%) create mode 100644 tests/logging/panic.c create mode 100644 tests/logging/test_logging.py diff --git a/tests/logging/CMakeLists.txt b/tests/logging/CMakeLists.txt index ebc9962..9c90431 100644 --- a/tests/logging/CMakeLists.txt +++ b/tests/logging/CMakeLists.txt @@ -1,9 +1,25 @@ include(CTest) -add_executable(logging ${PROJECT_SOURCE_DIR}/src/sys/log.c main.c) -target_include_directories(logging PUBLIC ${PROJECT_SOURCE_DIR}/src) -set_target_properties(logging +# ------------------------------------------------------- # +# CTEST 1 +# test the default output of the logger + +add_executable(logging_output ${PROJECT_SOURCE_DIR}/src/sys/log.c output.c) +target_include_directories(logging_output PUBLIC ${PROJECT_SOURCE_DIR}/src) +set_target_properties(logging_output PROPERTIES OUTPUT_NAME "output" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging) -add_test(NAME logging WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/check_output.py) +add_test(NAME logging_output WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_output) + +# ------------------------------------------------------- # +# CTEST 1 +# test the panic functionality of the logger + +add_executable(logging_panic ${PROJECT_SOURCE_DIR}/src/sys/log.c panic.c) +target_include_directories(logging_panic PUBLIC ${PROJECT_SOURCE_DIR}/src) +set_target_properties(logging_panic + PROPERTIES + OUTPUT_NAME "panic" + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging) +add_test(NAME logging_panic WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_panic) diff --git a/tests/logging/check_output.py b/tests/logging/check_output.py deleted file mode 100644 index b908cda..0000000 --- a/tests/logging/check_output.py +++ /dev/null @@ -1,22 +0,0 @@ -import subprocess - - -def run_logger_test(): - p = subprocess.run("bin/tests/logging/output", capture_output=True, text=True) - - # check exit code - if p.returncode != 0: - exit(p.returncode) - - output = p.stderr - - # check if logs appear in default log output (stderr) - - assert "logging some debug..." in output - assert "logging some info..." in output - assert "logging some warning..." in output - assert "logging some error..." in output - - -if __name__ == "__main__": - run_logger_test() diff --git a/tests/logging/main.c b/tests/logging/output.c similarity index 100% rename from tests/logging/main.c rename to tests/logging/output.c diff --git a/tests/logging/panic.c b/tests/logging/panic.c new file mode 100644 index 0000000..ecd8815 --- /dev/null +++ b/tests/logging/panic.c @@ -0,0 +1,20 @@ +// +// Created by servostar on 5/2/24. +// + +#include "sys/log.h" + +int main(void) { + log_init(); + + // this should appear in stderr + INFO("before exit"); + + PANIC("oooops something happened"); + + // this should NOT appear in stderr + // ^^^ + ERROR("after exit"); + + return 0; +} diff --git a/tests/logging/test_logging.py b/tests/logging/test_logging.py new file mode 100644 index 0000000..da88b19 --- /dev/null +++ b/tests/logging/test_logging.py @@ -0,0 +1,64 @@ +import subprocess +import sys +import logging +from logging import info, error + +BIN_DIR = "bin/tests/logging/" + + +def run_logger_test(): + info("started check output...") + + p = subprocess.run(BIN_DIR + "output", capture_output=True, text=True) + + info("checking exit code...") + + # check exit code + assert p.returncode == 0 + + output = p.stderr + + # check if logs appear in default log output (stderr) + info("checking stderr...") + + assert "logging some debug..." in output + assert "logging some info..." in output + assert "logging some warning..." in output + assert "logging some error..." in output + + +def run_check_panic(): + info("started check panic...") + + p = subprocess.run(BIN_DIR + "panic", capture_output=True, text=True) + + info("checking exit code...") + + # check exit code + assert p.returncode == 1 + + output = p.stderr + + # check if logs appear (not) in default log output (stderr) + info("checking stderr...") + + assert "before exit" in output + assert "oooops something happened" in output + assert "after exit" not in output + + +if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) + + target = sys.argv[1] + + info(f"starting logging test suite with target: {target}") + + match target: + case "check_output": + run_logger_test() + case "check_panic": + run_check_panic() + case _: + error(f"unknown target: {target}") + exit(1) From 7bfe49c8eda7c12b49a63132f77748bbc3651536 Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 09:49:50 +0200 Subject: [PATCH 23/29] renamed python test function for logger output --- tests/logging/test_logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/logging/test_logging.py b/tests/logging/test_logging.py index da88b19..54f5d75 100644 --- a/tests/logging/test_logging.py +++ b/tests/logging/test_logging.py @@ -6,7 +6,7 @@ from logging import info, error BIN_DIR = "bin/tests/logging/" -def run_logger_test(): +def run_check_output(): info("started check output...") p = subprocess.run(BIN_DIR + "output", capture_output=True, text=True) From dc240acb9dc84cee1f290ae3af3597f2c6c5c919 Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 09:59:42 +0200 Subject: [PATCH 24/29] added section about writing tests to README --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index a1e442b..faca249 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,28 @@ Requires: - bison - flex +## Writing Tests + +Since the project is build and configured through CMake it makes sense to rely for tests +on CTest. All tests are located in the subfolder `tests`. In this directory is a CMakeLists.txt which specifies which tests +are to be run. Actual tests are located in folders within tests and contain a final CMakeLists.txt which specifies what to run +for a single test. + +``` +tests + └─ test_group1 + └─ CMakeLists.txt # specify tests in this group + └─ ... # test files of group 1 + + └─ test_group2 + └─ CMakeLists.txt # specify tests in this group + └─ ... # test files of group 2 + + └─ CMakeLists.txt # specify test groups to run + +CMakeLists.txt # build configuration +``` + ## Development with VSCode/Codium Recommended extensions for getting a decent experience are the following: From 138937af57af8ca4d26e002d2881ed29e73e3e96 Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 10:04:00 +0200 Subject: [PATCH 25/29] fixed output test and reformatted CMake --- tests/logging/CMakeLists.txt | 20 ++++++++++++++------ tests/logging/test_logging.py | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/logging/CMakeLists.txt b/tests/logging/CMakeLists.txt index 9c90431..0db2412 100644 --- a/tests/logging/CMakeLists.txt +++ b/tests/logging/CMakeLists.txt @@ -1,25 +1,33 @@ include(CTest) +include_directories(${PROJECT_SOURCE_DIR}/src) + # ------------------------------------------------------- # # CTEST 1 # test the default output of the logger -add_executable(logging_output ${PROJECT_SOURCE_DIR}/src/sys/log.c output.c) -target_include_directories(logging_output PUBLIC ${PROJECT_SOURCE_DIR}/src) +add_executable(logging_output + ${PROJECT_SOURCE_DIR}/src/sys/log.c + output.c) set_target_properties(logging_output PROPERTIES OUTPUT_NAME "output" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging) -add_test(NAME logging_output WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_output) +add_test(NAME logging_output + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_output) # ------------------------------------------------------- # # CTEST 1 # test the panic functionality of the logger -add_executable(logging_panic ${PROJECT_SOURCE_DIR}/src/sys/log.c panic.c) -target_include_directories(logging_panic PUBLIC ${PROJECT_SOURCE_DIR}/src) +add_executable(logging_panic + ${PROJECT_SOURCE_DIR}/src/sys/log.c + panic.c) set_target_properties(logging_panic PROPERTIES OUTPUT_NAME "panic" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging) -add_test(NAME logging_panic WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_panic) +add_test(NAME logging_panic + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_panic) diff --git a/tests/logging/test_logging.py b/tests/logging/test_logging.py index 54f5d75..86816fd 100644 --- a/tests/logging/test_logging.py +++ b/tests/logging/test_logging.py @@ -56,7 +56,7 @@ if __name__ == "__main__": match target: case "check_output": - run_logger_test() + run_check_output() case "check_panic": run_check_panic() case _: From ebf526d6dac1b37171cda151cd2d8ac7e75d2dba Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 10:32:27 +0200 Subject: [PATCH 26/29] added test for multiple output logger streams --- tests/logging/CMakeLists.txt | 17 +++++++++++++++- tests/logging/streams.c | 33 +++++++++++++++++++++++++++++++ tests/logging/test_logging.py | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/logging/streams.c diff --git a/tests/logging/CMakeLists.txt b/tests/logging/CMakeLists.txt index 0db2412..dee6ddf 100644 --- a/tests/logging/CMakeLists.txt +++ b/tests/logging/CMakeLists.txt @@ -18,7 +18,7 @@ add_test(NAME logging_output COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_output) # ------------------------------------------------------- # -# CTEST 1 +# CTEST 2 # test the panic functionality of the logger add_executable(logging_panic @@ -31,3 +31,18 @@ set_target_properties(logging_panic add_test(NAME logging_panic WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_panic) + +# ------------------------------------------------------- # +# CTEST 3 +# test the ability to write to multiple output streams + +add_executable(logging_streams + ${PROJECT_SOURCE_DIR}/src/sys/log.c + streams.c) +set_target_properties(logging_streams + PROPERTIES + OUTPUT_NAME "stream" + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging) +add_test(NAME logging_streams + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_stream) diff --git a/tests/logging/streams.c b/tests/logging/streams.c new file mode 100644 index 0000000..97599da --- /dev/null +++ b/tests/logging/streams.c @@ -0,0 +1,33 @@ +// +// Created by servostar on 5/2/24. +// + +#include "sys/log.h" +#include + +static FILE* file; + +void close_file(void) { + if (file != NULL) { + fclose(file); + } +} + +int main(void) { + log_init(); + + // this should appear in stderr + INFO("should only be in stderr"); + + file = fopen("tmp/test.log", "w"); + if (file == NULL) { + PANIC("could not open file"); + } + atexit(close_file); + + log_register_stream(file); + + INFO("should be in both"); + + return 0; +} diff --git a/tests/logging/test_logging.py b/tests/logging/test_logging.py index 86816fd..0d32d48 100644 --- a/tests/logging/test_logging.py +++ b/tests/logging/test_logging.py @@ -2,6 +2,7 @@ import subprocess import sys import logging from logging import info, error +import os BIN_DIR = "bin/tests/logging/" @@ -47,6 +48,40 @@ def run_check_panic(): assert "after exit" not in output +def run_check_stream(): + info("started check panic...") + + info("creating temporary folder...") + + if not os.path.exists("tmp"): + os.mkdir("tmp") + + info("cleaning temporary folder...") + + if os.path.exists("tmp/test.log"): + os.remove("tmp/test.log") + + info("launching test binary...") + + p = subprocess.run(BIN_DIR + "stream", capture_output=True, text=True) + + info("checking exit code...") + + # check exit code + assert p.returncode == 0 + + with open("tmp/test.log", "r") as file: + assert "should be in both" in "".join(file.readlines()) + + output = p.stderr + + # check if logs appear (not) in default log output (stderr) + info("checking stderr...") + + assert "should only be in stderr" in output + assert "should be in both" in output + + if __name__ == "__main__": logging.basicConfig(level=logging.INFO) @@ -59,6 +94,8 @@ if __name__ == "__main__": run_check_output() case "check_panic": run_check_panic() + case "check_stream": + run_check_stream() case _: error(f"unknown target: {target}") exit(1) From c099a60ecf649cd76da74a50b5d83297f9918fde Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 10:50:24 +0200 Subject: [PATCH 27/29] added test for compile time log level filter --- tests/logging/CMakeLists.txt | 15 +++++++++++++++ tests/logging/level.c | 18 ++++++++++++++++++ tests/logging/test_logging.py | 23 +++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tests/logging/level.c diff --git a/tests/logging/CMakeLists.txt b/tests/logging/CMakeLists.txt index dee6ddf..0f14079 100644 --- a/tests/logging/CMakeLists.txt +++ b/tests/logging/CMakeLists.txt @@ -46,3 +46,18 @@ set_target_properties(logging_streams add_test(NAME logging_streams WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_stream) + +# ------------------------------------------------------- # +# CTEST 4 +# test compile time log level switch + +add_executable(logging_level + ${PROJECT_SOURCE_DIR}/src/sys/log.c + level.c) +set_target_properties(logging_level + PROPERTIES + OUTPUT_NAME "level" + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging) +add_test(NAME logging_level + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_level) diff --git a/tests/logging/level.c b/tests/logging/level.c new file mode 100644 index 0000000..6a4f055 --- /dev/null +++ b/tests/logging/level.c @@ -0,0 +1,18 @@ +// +// Created by servostar on 5/2/24. +// + +#include "sys/log.h" + +#define LOG_LEVEL LOG_LEVEL_WARNING + +int main(void) { + log_init(); + + DEBUG("logging some debug..."); + INFO("logging some info..."); + WARN("logging some warning..."); + ERROR("logging some error..."); + + return 0; +} diff --git a/tests/logging/test_logging.py b/tests/logging/test_logging.py index 0d32d48..246a9d5 100644 --- a/tests/logging/test_logging.py +++ b/tests/logging/test_logging.py @@ -28,6 +28,27 @@ def run_check_output(): assert "logging some error..." in output +def run_check_level(): + info("started check level...") + + p = subprocess.run(BIN_DIR + "level", capture_output=True, text=True) + + info("checking exit code...") + + # check exit code + assert p.returncode == 0 + + output = p.stderr + + # check if logs appear in default log output (stderr) + info("checking stderr...") + + assert "logging some debug..." not in output + assert "logging some info..." not in output + assert "logging some warning..." in output + assert "logging some error..." in output + + def run_check_panic(): info("started check panic...") @@ -96,6 +117,8 @@ if __name__ == "__main__": run_check_panic() case "check_stream": run_check_stream() + case "check_level": + run_check_level() case _: error(f"unknown target: {target}") exit(1) From 01cf8345a0ace0624fece387388971922653259a Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 2 May 2024 12:14:59 +0200 Subject: [PATCH 28/29] reverted change of #aa7c62f0 in devkit added script to run checks and tests in container --- .github/workflows/build-check-sdk.yaml | 4 +-- Dockerfile | 9 ++++-- run-check-test.sh | 40 ++++++++++++++++++++++++++ sdk/Dockerfile | 4 +-- 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 run-check-test.sh diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index 5b8f2aa..10a4811 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -2,7 +2,7 @@ name: "Build check gemstone in SDK" run-name: SDK build check to ${{ inputs.deploy_target }} by @${{ github.actor }} on: [push, pull_request] env: - SDK: 0.2.1-alpine-3.19.1 + SDK: 0.2.2-alpine-3.19.1 jobs: build-check-sdk: runs-on: ubuntu-latest @@ -11,4 +11,4 @@ jobs: - name: Setup SDK run: docker pull servostar/gemstone:sdk-"$SDK" && docker build --tag gemstone:devkit-"$SDK" . - name: Compile - run: docker run gemstone:devkit-"$SDK" make check + run: docker run gemstone:devkit-"$SDK" sh run-check-test.sh diff --git a/Dockerfile b/Dockerfile index ce2db20..09e34b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,12 @@ -FROM servostar/gemstone:sdk-0.2.1-alpine-3.19.1 +FROM servostar/gemstone:sdk-0.2.2-alpine-3.19.1 LABEL authors="servostar" -LABEL version="0.2.1" +LABEL version="0.2.2" LABEL description="docker image for setting up the build pipeline on SDK" LABEL website="https://github.com/Servostar/gemstone" -RUN git clone https://github.com/Servostar/gemstone.git /home/lorang +COPY --chown=lorang src /home/lorang/src +COPY --chown=lorang tests /home/lorang/tests +COPY --chown=lorang CMakeLists.txt /home/lorang/ +COPY --chown=lorang run-check-test.sh /home/lorang/ RUN cmake . diff --git a/run-check-test.sh b/run-check-test.sh new file mode 100644 index 0000000..a2a3ab4 --- /dev/null +++ b/run-check-test.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +# Author: Sven Vogel +# Created: 02.05.2024 +# Description: Builds the project and runs tests +# Returns 0 on success and 1 when something went wrong + +echo "+--------------------------------------+" +echo "| BUILDING all TARGETS |" +echo "+--------------------------------------+" + +make -B +if [ ! $? -eq 0 ]; then + echo "===> failed to build targets" + exit 1 +fi + +echo "+--------------------------------------+" +echo "| RUNNING CODE CHECK |" +echo "+--------------------------------------+" + +make check +if [ ! $? -eq 0 ]; then + echo "===> failed code check..." + exit 1 +fi + +echo "+--------------------------------------+" +echo "| RUNNING TESTS |" +echo "+--------------------------------------+" + +ctest -VV --output-on-failure --schedule-random -j 4 +if [ ! $? -eq 0 ]; then + echo "===> failed tests..." + exit 1 +fi + +echo "+--------------------------------------+" +echo "| COMPLETED CHECK + TESTS SUCCESSFULLY |" +echo "+--------------------------------------+" \ No newline at end of file diff --git a/sdk/Dockerfile b/sdk/Dockerfile index 4dbeb1f..1a6a677 100644 --- a/sdk/Dockerfile +++ b/sdk/Dockerfile @@ -1,11 +1,11 @@ FROM alpine:3.19.1 LABEL authors="servostar" -LABEL version="0.2.1" +LABEL version="0.2.2" LABEL description="base image for building the gemstone programming language compiler" LABEL website="https://github.com/Servostar/gemstone" # install dependencies -RUN apk add build-base gcc make cmake bison flex git +RUN apk add build-base gcc make cmake bison flex git python3 # create user for build RUN adduser --disabled-password lorang From f7a3faad2ea8e25f7bac95cebb34bc9ef1efb39c Mon Sep 17 00:00:00 2001 From: servostar Date: Sat, 4 May 2024 15:33:20 +0200 Subject: [PATCH 29/29] added test for accepting a file as input --- tests/CMakeLists.txt | 3 ++- tests/input_file/CMakeLists.txt | 9 ++++++++ tests/input_file/test.gem | 6 +++++ tests/input_file/test_input_file.py | 36 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/input_file/CMakeLists.txt create mode 100644 tests/input_file/test.gem create mode 100644 tests/input_file/test_input_file.py diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2602430..ab8afdc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,4 +6,5 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests) # Provide test to run here or include another CMakeLists.txt -add_subdirectory(logging) \ No newline at end of file +add_subdirectory(logging) +add_subdirectory(input_file) \ No newline at end of file diff --git a/tests/input_file/CMakeLists.txt b/tests/input_file/CMakeLists.txt new file mode 100644 index 0000000..263e769 --- /dev/null +++ b/tests/input_file/CMakeLists.txt @@ -0,0 +1,9 @@ +include(CTest) + +# ------------------------------------------------------- # +# CTEST 1 +# test if the program accepts a file as input + +add_test(NAME input_file_check + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/check + COMMAND python ${GEMSTONE_TEST_DIR}/input_file/test_input_file.py ${GEMSTONE_TEST_DIR}/input_file/test.gem) diff --git a/tests/input_file/test.gem b/tests/input_file/test.gem new file mode 100644 index 0000000..991288d --- /dev/null +++ b/tests/input_file/test.gem @@ -0,0 +1,6 @@ + +import "std.io" + +fun main { + print("Hello, World!!!") +} \ No newline at end of file diff --git a/tests/input_file/test_input_file.py b/tests/input_file/test_input_file.py new file mode 100644 index 0000000..3721dc0 --- /dev/null +++ b/tests/input_file/test_input_file.py @@ -0,0 +1,36 @@ +import os.path +import subprocess +import sys +import logging +from logging import info + + +def check_accept(): + info("testing handling of input file...") + + logging.basicConfig(level=logging.INFO) + + test_file_name = sys.argv[1] + + p = subprocess.run(["./gsc", test_file_name], capture_output=True, text=True) + + assert p.returncode == 0 + + +def check_abort(): + info("testing handling of missing input file...") + + logging.basicConfig(level=logging.INFO) + + p = subprocess.run("./gsc", capture_output=True, text=True) + + assert p.returncode == 1 + + +if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) + info("check if binary exists...") + assert os.path.exists("./gsc") + + check_accept() + check_abort()