diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 0000000..a025153 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,28 @@ +name: CMake + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + BUILD_TYPE: Release + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Install boost + run: sudo apt update && sudo apt install libboost-all-dev + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Build + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Test + working-directory: ${{github.workspace}}/build + run: ctest -C ${{env.BUILD_TYPE}} + + diff --git a/CMakeLists.txt b/CMakeLists.txt index dd7e89f..2b13c51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ file(GLOB test "test/*.cpp" ) +include(CTest) # ${test} contains all paths to the test cpps foreach(testfile ${test}) # ${testfile} is in the format of test/SomeTest.cpp @@ -67,7 +68,6 @@ foreach(testfile ${test}) # ${test_bin} is in the format of SomeTest_test add_executable(${test_bin} ${testfile}) target_link_libraries(${test_bin} PRIVATE sparta gmock_main) + add_test(NAME ${testfile} COMMAND ${test_bin}) endforeach() -# Copy the script that runs all tests under the build directory -configure_file(run_all_tests.sh run_all_tests.sh COPYONLY) diff --git a/README.md b/README.md index 81c439c..795e8ee 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ cmake --build . To run the unit tests, please type: ``` -./run_all_tests.sh +make test ``` To copy the header files into `/usr/local/include/sparta` and set up a cmake library for SPARTA, you can use the following command: diff --git a/run_all_tests.sh b/run_all_tests.sh deleted file mode 100755 index c2469e0..0000000 --- a/run_all_tests.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -N_TEST_FAILED=0 -FAILED_TESTS=$"" - -failed_test() { - ((N_TEST_FAILED++)) - FAILED_TESTS=$(printf "%s\n%s" "$FAILED_TESTS" "$1") -} - -for test in *_test; do - if [[ -f "$test" ]]; then - ./"$test" || failed_test "$test" - else - # Wildcard did not expand into any file (i.e. files don't exist) - echo "Tests not found. Please make sure you are in the build directory." - exit 2 - fi -done - -if [[ $N_TEST_FAILED -ne 0 ]]; then - printf "%s test(s) failed.%s\n" "$N_TEST_FAILED" "$FAILED_TESTS" - exit 1 -fi