Skip to content

Commit 0b64f39

Browse files
authored
Merge pull request #152 from steve-downey/installtest
Test install
2 parents 8420b95 + 466c5fd commit 0b64f39

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ compile-headers: $(_build_path)/CMakeCache.txt ## Compile the headers
7878
install: $(_build_path)/CMakeCache.txt compile ## Install the project
7979
cmake --install $(_build_path) --config $(CONFIG) --component beman.optional --verbose
8080

81+
.PHONY: clean-install
82+
clean-install:
83+
-rm -rf .install
84+
85+
realclean: clean-install
86+
8187
ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build
8288
cd $(_build_path) && ctest --output-on-failure -C $(CONFIG)
8389

@@ -195,6 +201,18 @@ mrdocs: ## Build the docs with Doxygen
195201
cd docs && NO_COLOR=1 mrdocs mrdocs.yml 2>&1 | sed 's/\x1b\[[0-9;]*m//g'
196202
find docs/adoc -name '*.adoc' | xargs asciidoctor
197203

204+
.PHONY: testinstall
205+
testinstall: install
206+
testinstall: ## Test the installed package
207+
cmake -S installtest -B installtest/.build
208+
cmake --build installtest/.build --target test
209+
210+
.PHONY: clean-testinstall
211+
clean-testinstall:
212+
-rm -rf installtest/.build
213+
214+
realclean: clean-testinstall
215+
198216
# Help target
199217
.PHONY: help
200218
help: ## Show this help.

installtest/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.30)
2+
project(ConsumerBemanOptional)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
6+
# Enable testing in this separate project
7+
enable_testing()
8+
9+
# Find the installed package
10+
set(OPTIONAL_INSTALL_DIR "../.install/lib/cmake/beman.optional")
11+
find_package(
12+
beman.optional
13+
REQUIRED
14+
PATHS ${OPTIONAL_INSTALL_DIR}
15+
NO_DEFAULT_PATH
16+
)
17+
18+
# Add your test executable
19+
add_executable(TestInstalledOptional test.cpp)
20+
21+
# Link against the imported target
22+
target_link_libraries(TestInstalledOptional beman::optional)
23+
24+
# Register the test with CTest
25+
add_test(NAME RunInstalledTest COMMAND TestInstalledOptional)
26+
27+
# Ensure 'make test' first builds the 'all' target
28+
set(CMAKE_SKIP_TEST_ALL_DEPENDENCY FALSE)

installtest/test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// testinstall/test.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/optional/optional.hpp>
5+
#include <iostream>
6+
7+
int main() {
8+
beman::optional::optional<int> empty_opt{};
9+
if (!empty_opt) {
10+
std::cout << "empty_opt is empty!\n";
11+
}
12+
13+
beman::optional::optional<int> opt{26};
14+
if (opt) {
15+
std::cout << "opt = " << *opt << "\n";
16+
}
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)