Skip to content

Commit ede6e69

Browse files
committed
Add library usage test
1 parent 7cc9433 commit ede6e69

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

.github/workflows/cmake.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ jobs:
176176
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
177177
-DCMAKE_CXX_STANDARD=${{ matrix.config.cxxver }} \
178178
-DBUILD_TESTING=ON \
179+
-DCPPCORO_USAGE_TEST_DIR="${{runner.workspace}}/use_cppcoro" \
179180
-DCMAKE_CXX_FLAGS=${{ matrix.config.cxx_flags }} \
180181
-DCMAKE_EXE_LINKER_FLAGS=${{ matrix.config.exe_linker_flags }} \
181182
-DCMAKE_VERBOSE_MAKEFILE=ON

test/CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,72 @@ foreach(test ${tests})
6060
endif()
6161
doctest_discover_tests(${test_name} TEST_PREFIX ${test_prefix}- PROPERTIES TIMEOUT ${${test_name}_TIMEOUT})
6262
endforeach()
63+
64+
function(add_usage_test variant_name cppcoro_ROOT)
65+
set(APP_BINARY_DIR ${CPPCORO_USAGE_TEST_DIR}/app_build/${variant_name})
66+
add_test(
67+
NAME app_configure_${variant_name}
68+
COMMAND
69+
${CMAKE_COMMAND}
70+
-S ${CMAKE_CURRENT_LIST_DIR}/use_cppcoro
71+
-B ${APP_BINARY_DIR}
72+
-G ${CMAKE_GENERATOR}
73+
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
74+
-D CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
75+
-D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
76+
-D cppcoro_ROOT=${cppcoro_ROOT}
77+
)
78+
add_test(
79+
NAME app_build_${variant_name}
80+
COMMAND
81+
${CMAKE_COMMAND}
82+
--build ${APP_BINARY_DIR}
83+
--config ${CMAKE_BUILD_TYPE}
84+
)
85+
set_tests_properties(
86+
app_configure_${variant_name}
87+
PROPERTIES
88+
FIXTURES_SETUP app_build_${variant_name}_requires
89+
TIMEOUT 30
90+
)
91+
set_tests_properties(
92+
app_build_${variant_name}
93+
PROPERTIES
94+
FIXTURES_REQUIRED app_build_${variant_name}_requires
95+
TIMEOUT 30
96+
)
97+
endfunction()
98+
99+
if(CPPCORO_USAGE_TEST_DIR)
100+
if(NOT IS_ABSOLUTE ${CPPCORO_USAGE_TEST_DIR})
101+
set(CPPCORO_USAGE_TEST_DIR ${PROJECT_BINARY_DIR}/${CPPCORO_USAGE_TEST_DIR})
102+
endif()
103+
104+
add_usage_test(with_cppcoro_build_tree ${PROJECT_BINARY_DIR})
105+
106+
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
107+
set(CPPCORO_USAGE_TEST_INSTALL_DIR ${CPPCORO_USAGE_TEST_DIR}/cppcoro_install)
108+
109+
add_usage_test(with_cppcoro_install_dir ${CPPCORO_USAGE_TEST_INSTALL_DIR})
110+
111+
add_test(
112+
NAME cppcoro_usage_test_install
113+
COMMAND
114+
${CMAKE_COMMAND}
115+
--install ${PROJECT_BINARY_DIR}
116+
--config ${CMAKE_BUILD_TYPE}
117+
--prefix ${CPPCORO_USAGE_TEST_INSTALL_DIR}
118+
)
119+
set_tests_properties(
120+
cppcoro_usage_test_install
121+
PROPERTIES
122+
FIXTURES_SETUP app_configure_with_cppcoro_install_dir_requires
123+
TIMEOUT 30
124+
)
125+
set_tests_properties(
126+
app_configure_with_cppcoro_install_dir
127+
PROPERTIES
128+
FIXTURES_REQUIRED app_configure_with_cppcoro_install_dir_requires
129+
)
130+
endif()
131+
endif()

test/use_cppcoro/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(use_cppcoro LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
find_package(cppcoro REQUIRED)
6+
7+
add_executable(use_cppcoro use_cppcoro.cpp)
8+
target_link_libraries(use_cppcoro PRIVATE cppcoro::cppcoro)

test/use_cppcoro/use_cppcoro.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <iostream>
2+
#include <cppcoro/generator.hpp>
3+
4+
cppcoro::generator<int> sequence()
5+
{
6+
co_yield 1;
7+
co_yield 22;
8+
co_yield 333;
9+
}
10+
11+
int main()
12+
{
13+
for (auto i : sequence())
14+
{
15+
std::cout << i << std::endl;
16+
}
17+
}

0 commit comments

Comments
 (0)