From bf1a4247ac273a8f32ed3961d3216399b286c341 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 17 Jan 2024 08:43:36 +0300 Subject: [PATCH] Initial commit --- .github/workflows/ci_tests.yml | 69 ++++++++++++++++++++++++++++++++++ .gitignore | 56 +++++++++++++++++++++++++++ CMakeLists.txt | 18 +++++++++ bin/CMakeLists.txt | 3 ++ bin/main.cpp | 6 +++ lib/CMakeLists.txt | 15 ++++++++ tests/CMakeLists.txt | 29 ++++++++++++++ tests/main_test.cpp | 15 ++++++++ 8 files changed, 211 insertions(+) create mode 100644 .github/workflows/ci_tests.yml create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 bin/CMakeLists.txt create mode 100644 bin/main.cpp create mode 100644 lib/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/main_test.cpp diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml new file mode 100644 index 0000000..7711aeb --- /dev/null +++ b/.github/workflows/ci_tests.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50c98fc --- /dev/null +++ b/.gitignore @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..508dff6 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt new file mode 100644 index 0000000..d66b144 --- /dev/null +++ b/bin/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(${PROJECT_NAME} main.cpp) + +target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) \ No newline at end of file diff --git a/bin/main.cpp b/bin/main.cpp new file mode 100644 index 0000000..0ab7f9b --- /dev/null +++ b/bin/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello, World!" << std::endl; + return 0; +} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..40bcb59 --- /dev/null +++ b/lib/CMakeLists.txt @@ -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}") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..7353d0c --- /dev/null +++ b/tests/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/tests/main_test.cpp b/tests/main_test.cpp new file mode 100644 index 0000000..8996e02 --- /dev/null +++ b/tests/main_test.cpp @@ -0,0 +1,15 @@ +#include + +#include // include your library here + +std::vector SplitString(const std::string& str) { + std::istringstream iss(str); + + return {std::istream_iterator(iss), std::istream_iterator()}; +} + +TEST(BasicTestSuite, BasicTest1) { + std::ostringstream out; + out << "Hello, World!"; + ASSERT_EQ(out.str(), "Hello, World!"); +} \ No newline at end of file