diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea7177c..f84ced3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,8 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Check formatting run: make format-check @@ -21,17 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install \ - google-mock \ - googletest \ - libgmock-dev \ - libgtest-dev + - uses: actions/checkout@v4 - name: Build run: make build diff --git a/CMakeLists.txt b/CMakeLists.txt index 6168952..b22e500 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,19 @@ cmake_minimum_required(VERSION 3.19) project(bootstrap-cpp-kata CXX) -enable_testing() set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -find_package(GTest REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +include(FetchGTest) +fetch_gtest() + +include(GoogleTest) + +enable_testing() add_executable(main main.cpp) @@ -14,8 +21,9 @@ file(GLOB tests test_*.cpp) foreach(test ${tests}) get_filename_component(name ${test} NAME_WE) add_executable(${name} ${test}) - add_test(${name} ${name}) target_link_libraries(${name} PRIVATE GTest::gmock_main) + + gtest_discover_tests(${name}) endforeach() add_custom_target( diff --git a/Makefile b/Makefile index f453ac0..575eeae 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,5 @@ all: build test -export CXX := clang++ -export GTEST_COLOR := 1 - BUILDDIR ?= build SRCS := $(shell git ls-files *.cpp *.h) diff --git a/README.md b/README.md index 7cd4259..3d846d8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Bootstrap for C++ katas +# Bootstrap for C++ coding kata [![CI](https://github.com/Coding-Cuddles/bootstrap-cpp-kata/actions/workflows/main.yml/badge.svg)](https://github.com/Coding-Cuddles/bootstrap-cpp-kata/actions/workflows/main.yml) [![Replit](https://img.shields.io/badge/Try%20with%20Replit-black?logo=replit)](https://replit.com/new/github/Coding-Cuddles/bootstrap-cpp-kata) @@ -14,8 +14,9 @@ handle all dependencies automatically. ### Prerequisites -* [CMake 3.19+](https://cmake.org) -* [GTest](https://github.com/google/googletest) +- A compatible C++ compiler that supports at least C++17 +- [CMake](https://cmake.org) +- [GoogleTest](https://github.com/google/googletest) ### Build diff --git a/cmake/FetchGTest.cmake b/cmake/FetchGTest.cmake new file mode 100644 index 0000000..7ad7e90 --- /dev/null +++ b/cmake/FetchGTest.cmake @@ -0,0 +1,17 @@ +include(FetchContent) + +function(fetch_gtest) + find_package(GTest QUIET) + + if(NOT GTest_FOUND) + message(STATUS "GTest not found locally. Downloading from GitHub...") + + FetchContent_Declare( + googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.16.0 + ) + + # Prevent overriding parent project's compiler/linker settings on Windows + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + endif() +endfunction() diff --git a/test_something.cpp b/test_something.cpp index 784b873..3f80d3b 100644 --- a/test_something.cpp +++ b/test_something.cpp @@ -1,10 +1,8 @@ -#include - #include -TEST(Something, SomethingPass) +TEST(SomethingTest, BasicAssertions) { - std::string value{"foo"}; EXPECT_TRUE(true); - EXPECT_EQ(value, "foo"); -} \ No newline at end of file + EXPECT_STRNE("hello", "world"); + EXPECT_EQ(7 * 6, 42); +}