diff --git a/.github/workflows/linux_check.yml b/.github/workflows/linux_check.yml index efd0549..841beac 100644 --- a/.github/workflows/linux_check.yml +++ b/.github/workflows/linux_check.yml @@ -10,6 +10,7 @@ jobs: - uses: actions/checkout@v2 - name: build run: | + sudo apt install -y valgrind mkdir build && cd build cmake ../src make diff --git a/docs/build.md b/docs/build.md index 42da8ac..bd38465 100644 --- a/docs/build.md +++ b/docs/build.md @@ -1,6 +1,14 @@ # Overview of the build system `datalog-cpp` uses the [CMake](www.cmake.org) build tool to generate build files for other build systems. Currently, building using clang and gcc with Makefiles are supported. +You `valgrind` installed to run memory checks: `sudo apt install valgrind` + +To run all regression tests: +``` +cd tests +./run_tests.sh +``` + # Building with Makefiles From the command line inside a git clone, run the following: ``` diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3bbdeb5..5ded485 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,9 @@ project("datalog-cpp") # specify the C++ standard set(CMAKE_CXX_STANDARD 17) +# cpp memory checker +include (CTest) + # unit-test library add_library(tests_main STATIC ../tests/tests_main.cpp) @@ -29,15 +32,18 @@ add_executable(types_test ../tests/types_test.cpp) target_include_directories(types_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(types_test tests_main) target_compile_definitions(types_test PUBLIC UNIX) +add_test(types_test_memory types_test) # variable_test target add_executable(variable_test ../tests/variable_test.cpp) target_include_directories(variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(variable_test tests_main) target_compile_definitions(variable_test PUBLIC UNIX) +add_test(variable_test_memory variable_test) # tuple_binding_test target add_executable(tuple_binding_test ../tests/tuple_binding_test.cpp) target_include_directories(tuple_binding_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(tuple_binding_test tests_main) target_compile_definitions(tuple_binding_test PUBLIC UNIX) +add_test(tuple_binding_test_memory tuple_binding_test) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 2aead19..f333093 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1,5 +1,8 @@ #!/bin/bash set -e +echo "Running tests" ../build/types_test ../build/variable_test -../build/tuple_binding_test \ No newline at end of file +../build/tuple_binding_test +echo "Checking for memory leaks" +cd ../build; ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=1" -T memcheck \ No newline at end of file diff --git a/tests/tuple_binding_test.cpp b/tests/tuple_binding_test.cpp index 5a76daa..6cb56c0 100644 --- a/tests/tuple_binding_test.cpp +++ b/tests/tuple_binding_test.cpp @@ -15,7 +15,15 @@ bool unbindTest() return returnVal; } +bool leakTest() { + double* leak = new double[10]; + std::cout << "Hello!" << std::endl; + delete[] leak; + return true; +} + TEST_CASE("tuple binding test", "[tuple-binding]") { REQUIRE(unbindTest()); + REQUIRE(leakTest()); }