Skip to content

Commit e0c6339

Browse files
authored
Merge pull request #162 from eseiler/infra/test_binary
[INFRA] Add NEEDLE_TEST_BINARY_DIR
2 parents 626dbcb + 449afb8 commit e0c6339

File tree

5 files changed

+61
-34
lines changed

5 files changed

+61
-34
lines changed

.github/workflows/ci_documentation.yml

-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ jobs:
5151
run: |
5252
mkdir build && cd build
5353
cmake .. -DCMAKE_BUILD_TYPE=Release \
54-
-Dneedle_TEST=OFF \
55-
-Dneedle_DOCS=ON \
5654
-DNEEDLE_TEST=OFF \
5755
-DNEEDLE_DOCS=ON
5856

.github/workflows/ci_install.yml

+40-14
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,59 @@ jobs:
4444
with:
4545
path: needle
4646

47+
- name: Remove ccache
48+
run: apt-get purge --yes ccache
49+
4750
- name: Create source package
4851
run: |
49-
mkdir package && cd package
52+
mkdir create_source_package && cd create_source_package
5053
cmake ../needle -DCMAKE_BUILD_TYPE=Release \
51-
-Dneedle_PACKAGE=ON \
52-
-Dneedle_TEST=OFF
54+
-DNEEDLE_PACKAGE=ON \
55+
-DNEEDLE_TEST=OFF
5356
make package_source
54-
mkdir ../unpacked
55-
tar xf needle-*.tar.xz -C ../unpacked --strip-components=1
57+
mkdir ../source_package
58+
tar xf needle-*.tar.xz -C ../source_package --strip-components=1
5659
5760
- name: Install from source package
61+
run: |
62+
mkdir build_from_source_package install && cd build_from_source_package
63+
unshare -r -n cmake ../source_package -DCMAKE_BUILD_TYPE=Release \
64+
-DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/install \
65+
-DNEEDLE_TEST=OFF
66+
unshare -r -n make install
67+
68+
- name: Check installed executable
69+
run: ${GITHUB_WORKSPACE}/install/bin/needle --help
70+
71+
# Clang builds with libc++, but GTest is built with libstdc++
72+
- name: Install GTest
73+
if: contains(matrix.compiler, 'gcc')
74+
run: apt-get update && apt-get install --yes libgtest-dev
75+
76+
- name: Build tests
77+
if: contains(matrix.compiler, 'gcc')
5878
run: |
5979
mkdir build && cd build
60-
unshare -r -n cmake ../unpacked -DCMAKE_BUILD_TYPE=Release \
61-
-DCMAKE_INSTALL_PREFIX=$(pwd)/install \
62-
-Dneedle_TEST=OFF
63-
make install
80+
unshare -r -n cmake ../source_package -DCMAKE_BUILD_TYPE=Release \
81+
-DCPM_USE_LOCAL_PACKAGES=ON \
82+
-DNEEDLE_TEST_BINARY_DIR=${GITHUB_WORKSPACE}/install/bin \
83+
-DNEEDLE_TEST=ON
84+
unshare -r -n make -k tests
85+
test -n $(find . -type f -executable -name "needle") # needle binary should exist
86+
rm bin/needle
87+
test -z $(find . -type f -executable -name "needle") # needle binary should not exist
6488
6589
- name: Run tests
90+
if: contains(matrix.compiler, 'gcc')
6691
working-directory: build
67-
run: ./install/bin/needle --help
92+
run: |
93+
unshare -r -n ctest -j --output-on-failure --test-dir test
94+
test -z $(find . -type f -executable -name "needle") # needle binary should not exist
6895
6996
- name: Upload source package
70-
if: matrix.compiler == 'gcc-14'
97+
if: contains(matrix.compiler, 'gcc')
7198
uses: actions/upload-artifact@v4
7299
with:
73-
name: source-package
74-
path: package/needle-*.tar.xz*
100+
name: needle-source-package
101+
path: create_source_package/needle-*.tar.xz*
75102
retention-days: 1
76-

CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ include (output_directories)
2222
# It can be used when calling CMake: `cmake .. -Dapp-template_TEST=OFF`.
2323
# It is good practice to allow disabling tests. If another project includes your application,
2424
# it might not want to build your tests.
25-
option (${PROJECT_NAME}_TEST "Enable testing for ${PROJECT_NAME}." ON)
26-
option (${PROJECT_NAME}_DOCS "Enable documentation for ${PROJECT_NAME}." OFF)
27-
option (${PROJECT_NAME}_PACKAGE "Enable packaging for ${PROJECT_NAME}." OFF)
25+
option (NEEDLE_TEST "Enable testing for NEEDLE." ON)
26+
option (NEEDLE_DOCS "Enable documentation for NEEDLE." OFF)
27+
option (NEEDLE_PACKAGE "Enable packaging for NEEDLE." OFF)
2828

29-
if (${PROJECT_NAME}_PACKAGE)
29+
if (NEEDLE_PACKAGE)
3030
set (CPM_SOURCE_CACHE "${CMAKE_CURRENT_BINARY_DIR}/vendor")
3131
set (CPM_USE_LOCAL_PACKAGES OFF)
3232
include (package)
@@ -48,11 +48,11 @@ CPMGetPackage (robin-hood)
4848
# Add the application. This will include `src/CMakeLists.txt`.
4949
add_subdirectory (src)
5050

51-
if (${PROJECT_NAME}_TEST)
51+
if (NEEDLE_TEST)
5252
# Add the tests. This will include `test/CMakeLists.txt`.
5353
add_subdirectory (test EXCLUDE_FROM_ALL)
5454
endif ()
5555

56-
if (${PROJECT_NAME}_DOCS)
56+
if (NEEDLE_DOCS)
5757
add_subdirectory (doc EXCLUDE_FROM_ALL)
5858
endif ()

cmake/test/config.cmake

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@ enable_testing ()
1313
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output)
1414
add_definitions (-DOUTPUTDIR=\"${CMAKE_CURRENT_BINARY_DIR}/output/\")
1515
add_definitions (-DDATADIR=\"${CMAKE_CURRENT_BINARY_DIR}/data/\")
16-
add_definitions (-DBINDIR=\"${CMAKE_BINARY_DIR}/bin/\")
1716
add_definitions (-DAPPNAME=\"${PROJECT_NAME}\")
1817

18+
if (NEEDLE_TEST_BINARY_DIR)
19+
if (NOT EXISTS "${NEEDLE_TEST_BINARY_DIR}")
20+
message (FATAL_ERROR "The directory \"${NEEDLE_TEST_BINARY_DIR}\" (NEEDLE_TEST_BINARY_DIR) does not exist.")
21+
endif ()
22+
if (NOT EXISTS "${NEEDLE_TEST_BINARY_DIR}/${PROJECT_NAME}")
23+
message (FATAL_ERROR "Executable \"${PROJECT_NAME}\" not found in \"${NEEDLE_TEST_BINARY_DIR}\" (NEEDLE_TEST_BINARY_DIR)."
24+
)
25+
endif ()
26+
else ()
27+
set (NEEDLE_TEST_BINARY_DIR "${CMAKE_BINARY_DIR}/bin")
28+
endif ()
29+
add_definitions (-DBINDIR=\"${NEEDLE_TEST_BINARY_DIR}/\")
30+
1931
# Add the test interface library.
2032
if (NOT TARGET ${PROJECT_NAME}_test)
2133
add_library (${PROJECT_NAME}_test INTERFACE)

src/CMakeLists.txt

+2-11
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@ set_target_properties ("${PROJECT_NAME}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${
1818
include (GNUInstallDirs)
1919
install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
2020

21-
# https://cmake.org/cmake/help/latest/module/CMakeDependentOption.html
22-
# We usually want "-Werror" in the CI, but not when developing locally.
23-
# Virtually all CI providers set the environment variable `CI` to some value.
24-
# If `CI` is defined in the environment, we use `-Werror`, otherwise not.
25-
# Caveat: If `CI` is not set, `-Dneedle_WITH_WERROR=ON` has no effect.
26-
# The other way around works. If `CI` is set, `-Dneedle_WITH_WERROR=OFF` is honored.
27-
# Solutions: * `export CI=1` (any value after `=` works, the variable only needs to be not empty)
28-
# * `-DCMAKE_CXX_FLAGS="-Werror"`
29-
include (CMakeDependentOption)
30-
cmake_dependent_option (${PROJECT_NAME}_WITH_WERROR "Report compiler warnings as errors." ON "DEFINED ENV{CI}" OFF)
21+
option (NEEDLE_WITH_WERROR "Report compiler warnings as errors." ON)
3122

32-
if (${PROJECT_NAME}_WITH_WERROR)
23+
if (NEEDLE_WITH_WERROR)
3324
target_compile_options (${PROJECT_NAME}_lib PUBLIC "-Werror")
3425
endif ()

0 commit comments

Comments
 (0)