From e8bed57ffe4013eb1b9d4b4fb88b0a046ea2f070 Mon Sep 17 00:00:00 2001 From: mrdcvlsc Date: Thu, 30 May 2024 11:46:07 +0800 Subject: [PATCH] add cmake ctest in CI --- .github/workflows/ctests.yml | 39 ++++++++++++++++++++++++++++++++ README.md | 1 + tests/CMakeLists.txt | 43 +++++++++++++++--------------------- 3 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/ctests.yml diff --git a/.github/workflows/ctests.yml b/.github/workflows/ctests.yml new file mode 100644 index 0000000..2a6a935 --- /dev/null +++ b/.github/workflows/ctests.yml @@ -0,0 +1,39 @@ +name: ctests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build-others: + name: ${{ matrix.platform.name }}-C++${{matrix.config.cxx_version}} + runs-on: ${{ matrix.platform.os }} + + strategy: + fail-fast: false + matrix: + platform: + - { name: Windows VS2019, os: windows-2019} + - { name: Windows VS2022, os: windows-2022} + - { name: Windows Clang, os: windows-2022, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++} + - { name: Windows GCC, os: windows-2022, flags: -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++} + - { name: Linux Clang, os: ubuntu-latest, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ } + - { name: Linux, os: ubuntu-latest} + - { name: MacOS XCode, os: macos-latest} + config: + - { cxx_version: 20 } + - { cxx_version: 23 } + + steps: + - uses: actions/checkout@v3 + + - name: System Info + run: cmake -S tests -B tests ${{matrix.platform.flags}} -DCMAKE_CXX_STANDARD=${{matrix.config.cxx_version}} + + - name: Build + run: cmake --build tests --config Debug -j2 + + - name: Tests + run: ctest --test-dir tests \ No newline at end of file diff --git a/README.md b/README.md index 3074472..0dbd008 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) ![tests](https://github.com/mrdcvlsc/extended-precision-integers/actions/workflows/tests.yml/badge.svg) +![ctests](https://github.com/mrdcvlsc/extended-precision-integers/actions/workflows/ctests.yml/badge.svg) This is a C++ header-only library that offers extended precision data types, which are number types with **fixed sizes** capable of holding larger values than traditional **Plain Old Data** types (PODs) like `int`, `uint8_t`, `unsigned long`, etc. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ed5c6ea..1dce557 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,29 +1,22 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) -project(extended_precision_integers VERSION 1.0.0) +file(GLOB SOURCES "*.cpp") -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_VERBOSE_MAKEFILE OFF) set(CMAKE_CXX_STANDARD_REQUIRED True) -add_executable("addition" "addition.cpp") -add_executable("bitwise-and" "bitwise-and.cpp") -add_executable("bitwise-not" "bitwise-not.cpp") -add_executable("bitwise-or" "bitwise-or.cpp") -add_executable("bitwise-xor" "bitwise-xor.cpp") -add_executable("boolean" "boolean.cpp") -add_executable("constructor-initializer-list" "constructor-initializer-list.cpp") -add_executable("constructor-integral" "constructor-integral.cpp") -add_executable("constructor-string-view" "constructor-string-view.cpp") -add_executable("decrement" "decrement.cpp") -add_executable("division" "division.cpp") -add_executable("increment" "increment.cpp") -add_executable("modulo" "modulo.cpp") -add_executable("multiplication" "multiplication.cpp") -add_executable("relational" "relational.cpp") -add_executable("shifts" "shifts.cpp") -add_executable("subtraction" "subtraction.cpp") -add_executable("template" "template.cpp") -add_executable("to-string-base10" "to-string-base10.cpp") -add_executable("to-string-base16" "to-string-base16.cpp") -add_executable("to-string-base2" "to-string-base2.cpp") -add_executable("to-string-base8" "to-string-base8.cpp") \ No newline at end of file +# add_compile_definitions(USER_DEFINITION) + +enable_testing() + +foreach(test_src_code ${SOURCES}) + get_filename_component(test_exec_name ${test_src_code} NAME_WE) + add_executable(${test_exec_name} ${test_src_code}) + # target_compile_features(${test_exec_name} PRIVATE cxx_std_11) + target_compile_options(${test_exec_name} PRIVATE -fsanitize=address) + target_link_options(${test_exec_name} PRIVATE -fsanitize=address) + add_test( + NAME ${test_exec_name} + COMMAND $ + ) +endforeach(test_src_code ${SOURCES}) \ No newline at end of file