Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bialger committed Jan 17, 2024
0 parents commit bf1a424
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "CI tests"

on: [ push ]

jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: "Windows Latest MSVC", artifact: "Windows-MSVC.tar.xz",
os: windows-latest,
build_type: "Release", cc: "cl", cxx: "cl",
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
}
- {
name: "Windows Latest MinGW", artifact: "Windows-MinGW.tar.xz",
os: windows-latest,
build_type: "Release", cc: "gcc", cxx: "g++"
}
- {
name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz",
os: ubuntu-latest,
build_type: "Release", cc: "gcc", cxx: "g++"
}
- {
name: "macOS Latest Clang", artifact: "macOS.tar.xz",
os: macos-latest,
build_type: "Release", cc: "clang", cxx: "clang++"
}

steps:
- uses: actions/checkout@v3
- name: Create CMake cash
run: |
cmake -S . -B cmake-build
- name: Build main target
run: |
cmake --build cmake-build --target cpp_tests
- name: Build tests target
run: |
cmake --build cmake-build --target cpp_tests_tests
- name: Run program
shell: bash
working-directory: ./cmake-build/bin
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
cd Debug
./cpp_tests.exe
else
./cpp_tests
fi
- name: Run tests
shell: bash
working-directory: ./cmake-build/tests
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
cd Debug
./cpp_tests_tests.exe
else
./cpp_tests_tests
fi
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# CMake
**cmake-build*/

# All idea files
**.idea*/

# File-based project format
*.iws

# IntelliJ
**out/

# mpeltonen/sbt-idea plugin
**.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.12)

project(
cpp_tests # Rename the project here and in ci_tests.yml
VERSION 0.1
DESCRIPTION "C++ Project with Google tests"
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 20)


add_subdirectory(lib)
add_subdirectory(bin)


enable_testing()
add_subdirectory(tests)
3 changes: 3 additions & 0 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(${PROJECT_NAME} main.cpp)

target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR})
6 changes: 6 additions & 0 deletions bin/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
15 changes: 15 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.12)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) # Change to Release when ready
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_DEBUG "/MDd")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
else ()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif()

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
29 changes: 29 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

add_executable(
${PROJECT_NAME}_tests
main_test.cpp
)

target_link_libraries(
${PROJECT_NAME}_tests # link used libraries from lib directory
GTest::gtest_main
)

target_include_directories(${PROJECT_NAME}_tests PUBLIC ${PROJECT_SOURCE_DIR})

include(GoogleTest)

gtest_discover_tests(${PROJECT_NAME}_tests)
15 changes: 15 additions & 0 deletions tests/main_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <sstream>

#include <gtest/gtest.h> // include your library here

std::vector<std::string> SplitString(const std::string& str) {
std::istringstream iss(str);

return {std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>()};
}

TEST(BasicTestSuite, BasicTest1) {
std::ostringstream out;
out << "Hello, World!";
ASSERT_EQ(out.str(), "Hello, World!");
}

0 comments on commit bf1a424

Please sign in to comment.