From be1f0d54ac73f9e21fcf59d5c6ccba8292a14bab Mon Sep 17 00:00:00 2001 From: Louis Rubet Date: Wed, 23 Feb 2022 11:31:05 +0100 Subject: [PATCH] github action for tests --- .github/workflows/cmake.yml | 35 +++++++++++++++++++++++++++++++++++ .gitmodules | 5 +---- linenoise-ng | 2 +- src/constant.h | 2 +- src/main.cpp | 6 ++++-- src/program.cpp | 9 ++++++--- src/rpn-test-framework.cpp | 14 +++++++++----- test/100-complex.md | 4 ++-- test/mem_test.sh | 8 +++++++- 9 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/cmake.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 0000000..5359907 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,35 @@ +name: CMake + +on: + pull_request: + branches: [ v2.4.0-devel ] + +env: + BUILD_TYPE: Release + +jobs: + functional_and_mem_tests: + # runs-on: ubuntu:21.10 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + submodules: 'true' + + - name: Install needed libs + run: sudo apt update && sudo apt install -y cmake build-essential libmpfr-dev valgrind + + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build + run: make -C ${{github.workspace}}/build -j + + - name: Functional tests + working-directory: ${{github.workspace}}/test + run: ${{github.workspace}}/build/rpn \"all.md\" test + + - name: Memory tests + working-directory: ${{github.workspace}}/test + run: ./mem_test.sh ${{github.workspace}}/build/rpn diff --git a/.gitmodules b/.gitmodules index da98e6b..f283762 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ -[submodule "build/linenoise-ng"] - path = build/linenoise-ng - url = git@github.com:louisrubet/linenoise-ng.git [submodule "linenoise-ng"] path = linenoise-ng - url = git@github.com:louisrubet/linenoise-ng.git + url = https://github.com/louisrubet/linenoise-ng.git [submodule "mpreal"] path = mpreal url = https://github.com/advanpix/mpreal diff --git a/linenoise-ng b/linenoise-ng index 6a37ee0..3d3d594 160000 --- a/linenoise-ng +++ b/linenoise-ng @@ -1 +1 @@ -Subproject commit 6a37ee0e9f117bb9950159545ecdbdbba41799bf +Subproject commit 3d3d594caf15b75517d9baea1f1860978cad771a diff --git a/src/constant.h b/src/constant.h index 8ee2408..084c96f 100644 --- a/src/constant.h +++ b/src/constant.h @@ -41,7 +41,7 @@ typedef enum { ret_abort_current_entry, ret_out_of_memory, ret_bad_value, - ret_max + ret_test_failed } ret_value; // base min and max diff --git a/src/main.cpp b/src/main.cpp index 72ed68d..3db8aeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include -#include +#include +#include #include #include using namespace std; @@ -162,5 +163,6 @@ int main(int argc, char* argv[]) { mpfr_free_cache(); - return ret; + if (ret != ret_ok) return EXIT_FAILURE; + return EXIT_SUCCESS; } diff --git a/src/program.cpp b/src/program.cpp index 02ae9cf..01e176f 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -263,11 +263,14 @@ ret_value program::run() { // error: abort prog go_out = true; + // test error: make rpn return EXIT_FAILURE + if (_err == ret_test_failed) + ret = ret_test_failed; + // error: show it - if (show_error(_err, _err_context) == ret_deadly) { + if (show_error(_err, _err_context) == ret_deadly) // pb showing error -> go out software ret = ret_good_bye; - } break; } i++; @@ -633,7 +636,7 @@ ret_value program::show_error() { vector errorStrings {"ok", "unknown command", "missing operand", "bad operand type", "out of range", "unknown variable", "internal error, aborting", "deadly", "goodbye", "not implemented", "no operation", "syntax error", "division by zero", "runtime error", "aborted current entry", "out of memory", - "bad value"}; + "bad value", "test failed"}; // clang-format on // show last recorded error if ((size_t)_err < errorStrings.size()) diff --git a/src/rpn-test-framework.cpp b/src/rpn-test-framework.cpp index 1b4dd5b..fecaf7a 100644 --- a/src/rpn-test-framework.cpp +++ b/src/rpn-test-framework.cpp @@ -1,9 +1,9 @@ #include using namespace std; -#include "version.h" #include "escape.h" #include "program.hpp" +#include "version.h" /// @brief write stack in a string, each entry separated between commas /// @@ -34,10 +34,8 @@ void program::test_get_stack(string& stack_is, rpnstack& stk) { /// @param steps_failed failed steps nb /// void program::test_show_result(string title, int tests, int tests_failed, int steps, int steps_failed) { - //cout << title << ": run " << tests << " tests: " << tests - tests_failed << " passed, "; - if (!title.empty()) - cout << title << ": "; - cout <<"run " << tests << " tests: " << tests - tests_failed << " passed, "; + if (!title.empty()) cout << title << ": "; + cout << "run " << tests << " tests: " << tests - tests_failed << " passed, "; if (tests_failed > 0) cout << FG_RED; cout << tests_failed << " failed"; if (tests_failed > 0) cout << COLOR_OFF; @@ -65,6 +63,12 @@ void program::rpn_test() { cout << endl << "rpn version is " << RPN_VERSION << endl; test(test_filename, total_tests, total_tests_failed, total_steps, total_steps_failed); test_show_result("\nTotal", total_tests, total_tests_failed, total_steps, total_steps_failed); + + // notify to caller that test succeeded or not + if (total_tests_failed > 0) { + _err = ret_test_failed; + _err_context = string("rpn version ") + RPN_VERSION + ", test file " + test_filename; + } } /// @brief load a test file and run its tests diff --git a/test/100-complex.md b/test/100-complex.md index 5a92b22..f1b07d6 100644 --- a/test/100-complex.md +++ b/test/100-complex.md @@ -36,9 +36,9 @@ ## entry (5) -`(0x1234,0x10.10)` +`(0x1234,0x1010)` --> stack should be (0x1.234p+12,0x1.01p+4) +-> stack should be (0x1234,0x1010) `del` diff --git a/test/mem_test.sh b/test/mem_test.sh index 4fc101d..bde629f 100755 --- a/test/mem_test.sh +++ b/test/mem_test.sh @@ -1,6 +1,12 @@ #!/bin/bash -rpn=../debug/rpn +if [ -z "${1}" ] + then + echo "Syntax: ${0} " + exit 1 +fi + +rpn=${1} FG_RED="\033[0;31m" FG_GREEN="\033[0;32m"