-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bf1a424
Showing
8 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} |