Skip to content

Commit

Permalink
Proper integration tests (#35)
Browse files Browse the repository at this point in the history
Inspired from @justend29 work on EVE
  • Loading branch information
jfalcou committed Oct 18, 2022
1 parent a522537 commit 2b2f71d
Show file tree
Hide file tree
Showing 14 changed files with 1,422 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .github/actions/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Container image that runs your code
FROM jfalcou/compilers:v6

# Copies your code file from your action repository to the filesystem path `/` of the container
COPY entrypoint.sh /entrypoint.sh

# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/entrypoint.sh"]
18 changes: 18 additions & 0 deletions .github/actions/integration/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# action.yml
name: "Checks installation process"
description: "Checks installation process"
inputs:
branch: # Current branch
description: "Current branch"
required: false
default: "main"
mode: # Mode
description: "Current test"
required: false
default: 0
runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.branch }}
- ${{ inputs.mode }}
46 changes: 46 additions & 0 deletions .github/actions/integration/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh -l
set -e

# Setup github/worspace as safe
git config --global --add safe.directory /github/workspace

# ID for various tests
INSTALL_TEST=0
FETCH_TEST=1
CPM_TEST=2

configure_and_ctest() {
test_regex=$1

cmake -B build -S . -G Ninja \
-DKUMI_BUILD_INTEGRATION=ON \
-DKUMI_BUILD_TEST=OFF \
-DKUMI_BUILD_DOCUMENTATION=OFF

# kumi build not required: cmake --build build
ctest --test-dir build --output-on-failure -R $test_regex
}

if [ $2 -eq $INSTALL_TEST ]; then
echo "::group::Prepare KUMI repository for branch " $1
configure_and_ctest integration.install-kumi.exe
echo "::endgroup::"

echo "::group::Test KUMI via the install target"
ctest --test-dir build --output-on-failure -R integration.install.exe
echo "::endgroup::"
fi

if [ $2 -eq $FETCH_TEST ]; then
echo "::group::Test KUMI via FetchContent"
configure_and_ctest integration.fetch.exe
echo "::endgroup::"
fi

if [ $2 -eq $CPM_TEST ]; then
echo "::group::Test KUMI via CPM"
configure_and_ctest integration.cpm.exe
echo "::endgroup::"
fi

return 0;
22 changes: 20 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch current branch
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Testing KUMI with g++
uses: ./.github/actions/run_tests
with:
Expand All @@ -22,8 +22,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch current branch
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Testing KUMI with clang
uses: ./.github/actions/run_tests
with:
compiler: 'clang++'

install:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cfg:
- {test: Installation , mode: 0 }
- {test: FetchContents , mode: 1 }
- {test: CPM , mode: 2 }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
- name: Check KUMI works with ${{ matrix.cfg.test }}
uses: ./.github/actions/integration
with:
branch: '${{ github.head_ref }}'
mode: '${{ matrix.cfg.mode }}'
34 changes: 20 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
## Copyright : KUMI Project Contributors
## SPDX-License-Identifier: BSL-1.0
##==================================================================================================
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.18)
enable_testing()

##==================================================================================================
## Setup project
##==================================================================================================
project(kumi LANGUAGES CXX)
set(PROJECT_VERSION 0.1.0)

set(KUMI_MAJOR_VERSION 2)
set(KUMI_MINOR_VERSION 1)
set(KUMI_PATCH_VERSION 0)
set(KUMI_VERSION ${KUMI_MAJOR_VERSION}.${KUMI_MINOR_VERSION}.${KUMI_PATCH_VERSION})

set(PROJECT_VERSION ${KUMI_VERSION})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake )

##==================================================================================================
## No in-source build
Expand All @@ -26,21 +34,14 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/kumi TYPE INCLUDE)
## =================================================================================================
## Exporting target for external use
## =================================================================================================
add_library(kumi_lib INTERFACE)
target_include_directories(kumi_lib INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options( kumi_lib INTERFACE -Wno-gnu-string-literal-operator-template)
endif()

target_compile_features(kumi_lib INTERFACE cxx_std_20)
add_library(kumi::kumi ALIAS kumi_lib)
include(kumi-install)

##==================================================================================================
## Options
##==================================================================================================
option( KUMI_BUILD_TEST "Build tests for kumi" ON )
option( KUMI_BUILD_DOCS "Build docs for kumi" OFF )
option( KUMI_BUILD_TEST "Build tests for kumi" ON )
option( KUMI_BUILD_DOCUMENTATION "Build docs for kumi" OFF )
option( KUMI_BUILD_INTEGRATION "Build integration tests for kumi" OFF )

##==================================================================================================
## Test target
Expand All @@ -50,10 +51,15 @@ if( KUMI_BUILD_TEST )
add_subdirectory(${PROJECT_SOURCE_DIR}/test/)
endif()

if( KUMI_BUILD_INTEGRATION )
include(CTest)
add_subdirectory(${PROJECT_SOURCE_DIR}/test/integration)
endif()

##==================================================================================================
## Add Doxygen building target
##==================================================================================================
if( KUMI_BUILD_DOCS )
if( KUMI_BUILD_DOCUMENTATION )
find_package(Doxygen QUIET)

if (DOXYGEN_FOUND)
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions cmake/kumi-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##==================================================================================================
## KUMI - Compact C++20 Tuple Toolbox
## Copyright : KUMI Project Contributors
## SPDX-License-Identifier: BSL-1.0
##==================================================================================================

##==================================================================================================
## Reuse install.cmake to preapre package properly
##==================================================================================================
include("${CMAKE_CURRENT_LIST_DIR}/kumi-targets.cmake")
set(KUMI_LIBRARIES kumi::kumi)
30 changes: 30 additions & 0 deletions cmake/kumi-install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
##==================================================================================================
## KUMI - Compact C++20 Tuple Toolbox
## Copyright : KUMI Project Contributors
## SPDX-License-Identifier: BSL-1.0
##==================================================================================================
include(GNUInstallDirs)
set(MAIN_DEST "${CMAKE_INSTALL_LIBDIR}/kumi-${PROJECT_VERSION}")
set(INSTALL_DEST "${CMAKE_INSTALL_INCLUDEDIR}/kumi-${PROJECT_VERSION}")
set(DOC_DEST "${CMAKE_INSTALL_DOCDIR}-${PROJECT_VERSION}")

## =================================================================================================
## Exporting target for external use
## =================================================================================================
add_library(kumi_lib INTERFACE)
target_include_directories( kumi_lib INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INSTALL_DEST}>
)
target_compile_features(kumi_lib INTERFACE cxx_std_20)
set_target_properties(kumi_lib PROPERTIES EXPORT_NAME kumi)
add_library(kumi::kumi ALIAS kumi_lib)

## =================================================================================================
## Install target with versioned folder
## =================================================================================================
install(TARGETS kumi_lib EXPORT kumi-targets DESTINATION "${MAIN_DEST}")
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/kumi DESTINATION "${INSTALL_DEST}" )
install(FILES ${PROJECT_SOURCE_DIR}/cmake/kumi-config.cmake DESTINATION "${MAIN_DEST}" )
install(FILES ${PROJECT_SOURCE_DIR}/LICENSE.md DESTINATION "${DOC_DEST}" )
install(EXPORT kumi-targets NAMESPACE "kumi::" DESTINATION "${MAIN_DEST}")
81 changes: 81 additions & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
##==================================================================================================
## KUMI - Compact C++20 Tuple Toolbox
## Copyright : KUMI Project Contributors
## SPDX-License-Identifier: BSL-1.0
##==================================================================================================

# Extract HEAD from git
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE kumi_git_head
RESULT_VARIABLE _git_error
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(NOT _git_error STREQUAL "0")
message(SEND_ERROR
"Failed to extract KUMI's current git commit for integration tests: ${_git_error}")
return()
endif()


# Builds and tests a separate project as an KUMI test
function(kumi_build_and_ctest project_name)
string(REPLACE "-test" "" test_name "integration.${project_name}.exe")

add_test(
NAME ${test_name}
COMMAND
"${CMAKE_CTEST_COMMAND}"
--verbose
--output-on-failure
--build-generator "${CMAKE_GENERATOR}"
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/${project_name}"
"${CMAKE_CURRENT_BINARY_DIR}/${project_name}"
--build-options ${ARGN}
--test-command "${CMAKE_CTEST_COMMAND}")
endfunction()


##==================================================================================================
## Create Integration Tests
##==================================================================================================

## ===== CPM =====
kumi_build_and_ctest(cpm-test
"-Dkumi_git_head=${kumi_git_head}"
"-Dkumi_SOURCE_DIR=${kumi_SOURCE_DIR}"
# cpm-test internally sets KUMI_* configure options
)

## ===== Fetch =====
kumi_build_and_ctest(fetch-test
"-Dkumi_git_head=${kumi_git_head}"
"-Dkumi_SOURCE_DIR=${kumi_SOURCE_DIR}"
"-DKUMI_BUILD_TEST=OFF"
"-DKUMI_BUILD_DOCUMENTATION=OFF"
)

## ===== Install =====
# install kumi as its own test and for 'install-test' to find
set(kumi_ROOT "${PROJECT_BINARY_DIR}/test/integration/install")
add_test(
NAME integration.install-kumi.exe
COMMAND
"${CMAKE_COMMAND}"
--install "${PROJECT_BINARY_DIR}"
--verbose
--prefix "${kumi_ROOT}")

kumi_build_and_ctest(install-test "-Dkumi_ROOT=${kumi_ROOT}")
set_tests_properties(integration.install.exe PROPERTIES DEPENDS integration.install-kumi.exe)

## ==== Aggregated ====
add_custom_target(integration
COMMAND
"${CMAKE_CTEST_COMMAND}"
--test-dir "${PROJECT_BINARY_DIR}"
--output-on-failure
-R integration\.[a-z-]+\.exe)
27 changes: 27 additions & 0 deletions test/integration/cpm-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
##==================================================================================================
## KUMI - Compact C++20 Tuple Toolbox
## Copyright : KUMI Project Contributors
## SPDX-License-Identifier: BSL-1.0
##==================================================================================================
cmake_minimum_required(VERSION 3.18)
project(kumi-cpm-test LANGUAGES CXX)
enable_testing()

message(STATUS "Testing CPM for commit ${kumi_git_head}")

# Setup CPM
include(cpm.cmake)

# Add dependencies
CPMAddPackage ( NAME kumi
GIT_REPOSITORY "${kumi_SOURCE_DIR}"
GIT_TAG "${kumi_git_head}"
OPTIONS "KUMI_BUILD_INTEGRATION=OFF"
"KUMI_BUILD_TEST=OFF"
"KUMI_BUILD_DOCUMENTATION=OFF"
)

# Use KUMI
add_executable(test_kumi ../main.cpp)
target_link_libraries(test_kumi PUBLIC kumi::kumi)
add_test(NAME test_kumi COMMAND test_kumi)
Loading

0 comments on commit 2b2f71d

Please sign in to comment.