From ada892fbcacb374102adbe27093c0bf395129855 Mon Sep 17 00:00:00 2001 From: Anthony Tarbinian Date: Wed, 11 Oct 2023 23:50:41 -0700 Subject: [PATCH 1/4] overhaul tests cmake place tests cmake setup in tests folder auto-detect new test files added a test target to run tests on "make test". running this target will recompile the tests if out of date. --- CMakeLists.txt | 25 ++----------------------- tests/CMakeLists.txt | 21 +++++++++++++++++++++ tests/hello_test.cpp | 2 +- tests/hello_test2.cpp | 3 +-- 4 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ff16ad0..0a760c24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,27 +38,6 @@ target_link_libraries(obcpp # ============================= # Unit tests +add_subdirectory(tests) add_subdirectory(deps/google-test) - -# enable CTest testing -enable_testing() - -# Add a testing executable -add_executable(hello_test tests/hello_test.cpp) -add_executable(hello_test2 tests/hello_test2.cpp) - -target_link_libraries( - hello_test - GTest::GTest - GTest::Main -) - -target_link_libraries( - hello_test2 - GTest::GTest - GTest::Main -) - -add_test(test_all ./bin/hello_test) -add_test(test_all ./bin/hello_test2) -# ============================= \ No newline at end of file +# ============================= diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..f6cf405d --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,21 @@ +set(BINARY ${CMAKE_PROJECT_NAME}_tests) + +file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false *.h *.cpp) + +set(SOURCES ${TEST_SOURCES}) + +add_executable(${BINARY} ${TEST_SOURCES}) + +target_link_libraries(${BINARY} PUBLIC gtest_main) + +add_test(NAME ${BINARY} COMMAND ${BINARY}) + +# setup make target (make test) +add_custom_target(test) +add_custom_command( + TARGET test + COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${BINARY}" + ARGS "--output-on-failure" +) +add_dependencies(test ${BINARY}) + diff --git a/tests/hello_test.cpp b/tests/hello_test.cpp index 9432d547..a6dc1e9a 100644 --- a/tests/hello_test.cpp +++ b/tests/hello_test.cpp @@ -1,7 +1,7 @@ #include // Demonstrate some basic assertions. -TEST(HelloTest, BasicAssertions) { +TEST(HelloTest, HelloTest1) { // Expect two strings not to be equal. EXPECT_STRNE("hello", "world"); // Expect equality. diff --git a/tests/hello_test2.cpp b/tests/hello_test2.cpp index 5909e7e2..2d9ccc71 100644 --- a/tests/hello_test2.cpp +++ b/tests/hello_test2.cpp @@ -1,11 +1,10 @@ #include // Demonstrate some basic assertions. -TEST(HelloTest, BasicAssertions) { +TEST(HelloTest, HelloTest2) { // Expect two strings not to be equal. EXPECT_STRNE("hello", "world"); // Expect equality. EXPECT_EQ(7 * 6, 42); - EXPECT_LT(3, 8); } From 7abfda30a54e5d5d746fbb5560771fd3f97d523e Mon Sep 17 00:00:00 2001 From: Anthony Tarbinian Date: Wed, 11 Oct 2023 23:53:04 -0700 Subject: [PATCH 2/4] github action tests --- .github/workflows/test.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..7b2930c1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + name: C++ Tests + runs-on: ubuntu-latest + + steps: + - name: Install Cmake + run: sudo apt install cmake + + - name: Checkout Repo + uses: actions/checkout@v2 + with: + submodules: true + token: ${{ secrets.SSH_TOKEN }} + + - name: Set up Cmake + run: cmake . + + - name: Run tests + run: make test + + + From 2fd8b50d3d279ce8b8bd7e4e72890b9ffe90cdd4 Mon Sep 17 00:00:00 2001 From: Anthony Tarbinian Date: Thu, 12 Oct 2023 00:07:28 -0700 Subject: [PATCH 3/4] update local testing command change to "make test" in README to use the new target added in tests/CMakeLists.txt --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dd683d03..cab8182a 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Now that everything is installed, here is the process to build and run the appli 11. Verify that the testing framework is set up correctly ```sh - ctest . + make test ``` If you receive output about certain tests passing/failing, then you are good. Ideally the main branch (which should be what @@ -130,4 +130,4 @@ Each module has its own folder in `include/` and `src/`. Currently all of the he ## Style -We are still deciding on a linting/style pipeline. When this is decided, this section should be updated. \ No newline at end of file +We are still deciding on a linting/style pipeline. When this is decided, this section should be updated. From 91676ad14c5d2d703f2ccaf89f38fabbff3f0b5a Mon Sep 17 00:00:00 2001 From: Anthony Tarbinian Date: Thu, 12 Oct 2023 00:09:23 -0700 Subject: [PATCH 4/4] tests run on pushes to main --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7b2930c1..a5f5b785 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Tests on: push: branches: - - master + - main pull_request: jobs: