Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
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)

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(
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
all: build test

export CXX := clang++
export GTEST_COLOR := 1

BUILDDIR ?= build
SRCS := $(shell git ls-files *.cpp *.h)

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
17 changes: 17 additions & 0 deletions cmake/FetchGTest.cmake
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 4 additions & 6 deletions test_something.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include <string>

#include <gmock/gmock.h>

TEST(Something, SomethingPass)
TEST(SomethingTest, BasicAssertions)
{
std::string value{"foo"};
EXPECT_TRUE(true);
EXPECT_EQ(value, "foo");
}
EXPECT_STRNE("hello", "world");
EXPECT_EQ(7 * 6, 42);
}