mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 07:10:30 +00:00
Add tests for passing STL containers by pointer
`nullptr` is not expected to work in this case.
This commit is contained in:
parent
c67033a926
commit
34b7b54f29
@ -160,4 +160,6 @@ TEST_SUBMODULE(stl, m) {
|
||||
};
|
||||
});
|
||||
|
||||
// test_stl_pass_by_pointer
|
||||
m.def("stl_pass_by_pointer", [](std::vector<int>* v) { return *v; }, "v"_a=nullptr);
|
||||
}
|
||||
|
@ -131,3 +131,26 @@ def test_vec_of_reference_wrapper():
|
||||
"""#171: Can't return reference wrappers (or STL structures containing them)"""
|
||||
assert str(m.return_vec_of_reference_wrapper(UserType(4))) == \
|
||||
"[UserType(1), UserType(2), UserType(3), UserType(4)]"
|
||||
|
||||
|
||||
def test_stl_pass_by_pointer(msg):
|
||||
"""Passing nullptr or None to an STL container pointer is not expected to work"""
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.stl_pass_by_pointer() # default value is `nullptr`
|
||||
assert msg(excinfo.value) == """
|
||||
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
|
||||
1. (v: List[int]=None) -> List[int]
|
||||
|
||||
Invoked with:
|
||||
""" # noqa: E501 line too long
|
||||
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.stl_pass_by_pointer(None)
|
||||
assert msg(excinfo.value) == """
|
||||
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
|
||||
1. (v: List[int]=None) -> List[int]
|
||||
|
||||
Invoked with: None
|
||||
""" # noqa: E501 line too long
|
||||
|
||||
assert m.stl_pass_by_pointer([1, 2, 3]) == [1, 2, 3]
|
||||
|
Loading…
Reference in New Issue
Block a user