diff --git a/sparta/.github/workflows/cmake.yml b/sparta/.github/workflows/cmake.yml new file mode 100644 index 0000000000..0737b547d7 --- /dev/null +++ b/sparta/.github/workflows/cmake.yml @@ -0,0 +1,27 @@ +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/sparta/CMakeLists.txt b/sparta/CMakeLists.txt index dd7e89fae7..2b13c51343 100644 --- a/sparta/CMakeLists.txt +++ b/sparta/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/sparta/README.md b/sparta/README.md index 81c439c930..795e8ee987 100644 --- a/sparta/README.md +++ b/sparta/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/sparta/run_all_tests.sh b/sparta/run_all_tests.sh deleted file mode 100755 index c2469e04e7..0000000000 --- a/sparta/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