Skip to content

Commit

Permalink
feat(tests): add test for actual namespace passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
leha-bot committed Sep 23, 2023
1 parent 463cff2 commit e5f2a53
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@ include(doctest)
add_executable(lbstd_version_tests test.cpp)
target_link_libraries(lbstd_version_tests doctest::doctest lbstd_version)

add_executable(lbstd_version_print_ns print_ns.cpp)
target_link_libraries(lbstd_version_print_ns lbstd_version)

# The manual test for namespace passthrough.
set(LBSTD_VERSION_CMAKE_NS_PASSTHROUGH "CMake custom library namespace (\"${LBSTD_VERSION_NS}::\") passthrough in C++ code")
add_test(NAME "${LBSTD_VERSION_CMAKE_NS_PASSTHROUGH}" COMMAND lbstd_version_print_ns)
set_tests_properties("${LBSTD_VERSION_CMAKE_NS_PASSTHROUGH}" PROPERTIES
PASS_REGULAR_EXPRESSION "${LBSTD_VERSION_NS}"
LABELS "buildsystem"
)

# Auto-discoverable doctest unit tests
doctest_discover_tests(lbstd_version_tests ADD_LABELS ON)

16 changes: 16 additions & 0 deletions tests/print_ns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This executable is a smoke test for checking the proper namespace customizing via CMake's
// -DLBSTD_VERSION_NS="namespace_name" configure parameter. The main() function just prints the
// actual namespace which will be used in CMake's test check.
#include <iostream>

#include <version/version.hpp>

#define MAKE_STRING(q) #q
#define UNPACK_MACRO(q) q
#define MAKE_STRING_FROM_MACRO(q) MAKE_STRING(q)

int main()
{
std::cout << MAKE_STRING_FROM_MACRO(LB_STD_VERSION_NS);
return 0;
}

0 comments on commit e5f2a53

Please sign in to comment.