Skip to content

Commit f2a5001

Browse files
committed
refactor: rename tests to test_cross_module_rtti
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 896b3af commit f2a5001

File tree

11 files changed

+94
-90
lines changed

11 files changed

+94
-90
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ jobs:
231231
run: cmake --build . --target test_cmake_build
232232

233233
- name: Visibility test
234-
run: cmake --build . --target test_visibility
234+
run: cmake --build . --target test_cross_module_rtti
235235

236236

237237
manylinux:
@@ -332,7 +332,7 @@ jobs:
332332
run: cmake --build --preset default --target cpptest
333333

334334
- name: Visibility test
335-
run: cmake --build --preset default --target test_visibility
335+
run: cmake --build --preset default --target test_cross_module_rtti
336336

337337
- name: Run Valgrind on Python tests
338338
if: matrix.valgrind
@@ -393,7 +393,7 @@ jobs:
393393
run: cmake --build build --target test_cmake_build
394394

395395
- name: Visibility test
396-
run: cmake --build build --target test_visibility
396+
run: cmake --build build --target test_cross_module_rtti
397397

398398
# Testing NVCC; forces sources to behave like .cu files
399399
cuda:
@@ -514,7 +514,7 @@ jobs:
514514
run: cmake --build build --target test_cmake_build
515515

516516
- name: Visibility test
517-
run: cmake --build build --target test_visibility
517+
run: cmake --build build --target test_cross_module_rtti
518518

519519
# Testing on GCC using the GCC docker images (only recent images supported)
520520
gcc:
@@ -567,7 +567,7 @@ jobs:
567567
run: cmake --build build --target test_cmake_build
568568

569569
- name: Visibility test
570-
run: cmake --build build --target test_visibility
570+
run: cmake --build build --target test_cross_module_rtti
571571

572572
- name: Configure - Exercise cmake -DPYBIND11_TEST_OVERRIDE
573573
if: matrix.gcc == '12'
@@ -654,7 +654,7 @@ jobs:
654654
- name: Visibility test
655655
run: |
656656
set +e; source /opt/intel/oneapi/setvars.sh; set -e
657-
cmake --build build-11 --target test_visibility
657+
cmake --build build-11 --target test_cross_module_rtti
658658
659659
- name: Configure C++17
660660
run: |
@@ -691,7 +691,7 @@ jobs:
691691
- name: Visibility test
692692
run: |
693693
set +e; source /opt/intel/oneapi/setvars.sh; set -e
694-
cmake --build build-17 --target test_visibility
694+
cmake --build build-17 --target test_cross_module_rtti
695695
696696
# Testing on CentOS (manylinux uses a centos base).
697697
centos:
@@ -755,7 +755,7 @@ jobs:
755755
run: cmake --build build --target test_cmake_build
756756

757757
- name: Visibility test
758-
run: cmake --build build --target test_visibility
758+
run: cmake --build build --target test_cross_module_rtti
759759

760760

761761
# This tests an "install" with the CMake tools
@@ -987,7 +987,7 @@ jobs:
987987
run: cmake --build build --target test_cmake_build
988988

989989
- name: Visibility test
990-
run: cmake --build build --target test_visibility
990+
run: cmake --build build --target test_cross_module_rtti
991991

992992
- name: Configure C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE
993993
run: >
@@ -1063,7 +1063,7 @@ jobs:
10631063
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build --target test_cmake_build
10641064

10651065
- name: Visibility test
1066-
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build --target test_visibility
1066+
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build --target test_cross_module_rtti
10671067

10681068
- name: Clean directory
10691069
run: git clean -fdx
@@ -1087,7 +1087,7 @@ jobs:
10871087
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build2 --target test_cmake_build
10881088

10891089
- name: Visibility test
1090-
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build2 --target test_visibility
1090+
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build2 --target test_cross_module_rtti
10911091

10921092
- name: Clean directory
10931093
run: git clean -fdx
@@ -1111,7 +1111,7 @@ jobs:
11111111
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build3 --target test_cmake_build
11121112

11131113
- name: Visibility test
1114-
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build3 --target test_visibility
1114+
run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build3 --target test_cross_module_rtti
11151115

11161116
windows_clang:
11171117
if: github.event.pull_request.draft == false
@@ -1181,7 +1181,7 @@ jobs:
11811181
run: cmake --build . --target test_cmake_build -j 2
11821182

11831183
- name: Visibility test
1184-
run: cmake --build . --target test_visibility -j 2
1184+
run: cmake --build . --target test_cross_module_rtti -j 2
11851185

11861186
- name: Clean directory
11871187
run: git clean -fdx
@@ -1251,7 +1251,7 @@ jobs:
12511251
run: cmake --build . --target test_cmake_build -j 2
12521252

12531253
- name: Visibility test
1254-
run: cmake --build . --target test_visibility -j 2
1254+
run: cmake --build . --target test_cross_module_rtti -j 2
12551255

12561256
- name: CMake Configure - Exercise cmake -DPYBIND11_TEST_OVERRIDE
12571257
run: >

.github/workflows/reusable-standard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
run: cmake --build build --target test_cmake_build
7676

7777
- name: Visibility test
78-
run: cmake --build build --target test_visibility
78+
run: cmake --build build --target test_cross_module_rtti
7979

8080
- name: Setuptools helpers test
8181
run: |

CMakePresets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161
"name": "tests",
6262
"displayName": "Tests (for workflow)",
6363
"configurePreset": "default",
64-
"targets": ["pytest", "cpptest", "test_cmake_build"]
64+
"targets": ["pytest", "cpptest", "test_cmake_build", "test_cross_module_rtti"]
6565
},
6666
{
6767
"name": "testsvenv",
6868
"displayName": "Tests Venv (for workflow)",
6969
"configurePreset": "venv",
70-
"targets": ["pytest", "cpptest", "test_cmake_build"]
70+
"targets": ["pytest", "cpptest", "test_cmake_build", "test_cross_module_rtti"]
7171
}
7272
],
7373
"workflowPresets": [

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,5 +651,5 @@ if(NOT PYBIND11_CUDA_TESTS)
651651
add_subdirectory(test_cmake_build)
652652

653653
# Test visibility of common symbols across shared libraries
654-
add_subdirectory(test_visibility)
654+
add_subdirectory(test_cross_module_rtti)
655655
endif()
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)
2+
3+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
4+
5+
if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy"
6+
OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy"
7+
OR "${PYTHON_MODULE_EXTENSION}" MATCHES "graalpy")
8+
message(STATUS "Skipping visibility test on PyPy or GraalPy")
9+
add_custom_target(test_cross_module_rtti
10+
)# Dummy target on PyPy or GraalPy. Embedding is not supported.
11+
set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
12+
return()
13+
endif()
14+
15+
if(TARGET Python::Module AND NOT TARGET Python::Python)
16+
message(STATUS "Skipping visibility test since no embed libs found")
17+
add_custom_target(test_cross_module_rtti) # Dummy target since embedding is not supported.
18+
set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
19+
return()
20+
endif()
21+
22+
find_package(Catch 2.13.10)
23+
24+
if(CATCH_FOUND)
25+
message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")
26+
else()
27+
message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers"
28+
" manually or use `cmake -DDOWNLOAD_CATCH=ON` to fetch them automatically.")
29+
return()
30+
endif()
31+
32+
include(GenerateExportHeader)
33+
34+
add_library(test_cross_module_rtti_lib SHARED lib.h lib.cpp)
35+
add_library(test_cross_module_rtti_lib::test_cross_module_rtti_lib ALIAS
36+
test_cross_module_rtti_lib)
37+
target_include_directories(test_cross_module_rtti_lib PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
38+
target_include_directories(test_cross_module_rtti_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
39+
target_compile_features(test_cross_module_rtti_lib PUBLIC cxx_std_11)
40+
41+
generate_export_header(test_cross_module_rtti_lib)
42+
43+
pybind11_add_module(test_cross_module_rtti_bindings SHARED bindings.cpp)
44+
target_link_libraries(test_cross_module_rtti_bindings
45+
PUBLIC test_cross_module_rtti_lib::test_cross_module_rtti_lib)
46+
47+
add_executable(test_cross_module_rtti_main catch.cpp test_cross_module_rtti.cpp)
48+
target_link_libraries(
49+
test_cross_module_rtti_main PUBLIC test_cross_module_rtti_lib::test_cross_module_rtti_lib
50+
pybind11::embed Catch2::Catch2)
51+
52+
# Ensure that we have built the python bindings since we load them in main
53+
add_dependencies(test_cross_module_rtti_main test_cross_module_rtti_bindings)
54+
55+
pybind11_enable_warnings(test_cross_module_rtti_main)
56+
pybind11_enable_warnings(test_cross_module_rtti_bindings)
57+
pybind11_enable_warnings(test_cross_module_rtti_lib)
58+
59+
add_custom_target(
60+
test_cross_module_rtti
61+
COMMAND "$<TARGET_FILE:test_cross_module_rtti_main>"
62+
DEPENDS test_cross_module_rtti_main
63+
WORKING_DIRECTORY "$<TARGET_FILE_DIR:test_cross_module_rtti_main>")
64+
65+
set_target_properties(test_cross_module_rtti_bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY
66+
"${CMAKE_CURRENT_BINARY_DIR}")
67+
68+
add_dependencies(check test_cross_module_rtti)

tests/test_visibility/bindings.cpp renamed to tests/test_cross_module_rtti/bindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class BaseTrampoline : public lib::Base, public pybind11::trampoline_self_life_s
88
int get() const override { PYBIND11_OVERLOAD(int, lib::Base, get); }
99
};
1010

11-
PYBIND11_MODULE(test_visibility_bindings, m) {
11+
PYBIND11_MODULE(test_cross_module_rtti_bindings, m) {
1212
pybind11::classh<lib::Base, BaseTrampoline>(m, "Base")
1313
.def(pybind11::init<int, int>())
1414
.def_readwrite("a", &lib::Base::a)
File renamed without changes.

tests/test_visibility/lib.h renamed to tests/test_cross_module_rtti/lib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#pragma once
22

33
#include <memory>
4-
#include <test_visibility_lib_export.h>
4+
#include <test_cross_module_rtti_lib_export.h>
55

66
#if defined(_MSC_VER)
77
__pragma(warning(disable : 4251))
88
#endif
99

1010
namespace lib {
1111

12-
class TEST_VISIBILITY_LIB_EXPORT Base : public std::enable_shared_from_this<Base> {
12+
class TEST_CROSS_MODULE_RTTI_LIB_EXPORT Base : public std::enable_shared_from_this<Base> {
1313
public:
1414
Base(int a, int b);
1515
virtual ~Base() = default;
@@ -20,7 +20,7 @@ __pragma(warning(disable : 4251))
2020
int b;
2121
};
2222

23-
class TEST_VISIBILITY_LIB_EXPORT Foo : public Base {
23+
class TEST_CROSS_MODULE_RTTI_LIB_EXPORT Foo : public Base {
2424
public:
2525
Foo(int a, int b);
2626

tests/test_visibility/test_visibility.cpp renamed to tests/test_cross_module_rtti/test_cross_module_rtti.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include <lib.h>
77

88
static constexpr auto script = R"(
9-
import test_visibility_bindings
9+
import test_cross_module_rtti_bindings
1010
11-
class Bar(test_visibility_bindings.Base):
11+
class Bar(test_cross_module_rtti_bindings.Base):
1212
def __init__(self, a, b):
13-
test_visibility_bindings.Base.__init__(self, a, b)
13+
test_cross_module_rtti_bindings.Base.__init__(self, a, b)
1414
1515
def get(self):
1616
return 4 * self.a + self.b
@@ -23,7 +23,7 @@ def get_bar(a, b):
2323

2424
TEST_CASE("Simple case where without is_alias") {
2525
// "Simple" case this will not have `python_instance_is_alias` set in type_cast_base.h:771
26-
auto bindings = pybind11::module_::import("test_visibility_bindings");
26+
auto bindings = pybind11::module_::import("test_cross_module_rtti_bindings");
2727
auto holder = bindings.attr("get_foo")(1, 2);
2828
auto foo = holder.cast<std::shared_ptr<lib::Base>>();
2929
REQUIRE(foo->get() == 4); // 2 * 1 + 2 = 4

0 commit comments

Comments
 (0)