Add tests for passing STL containers by pointer

`nullptr` is not expected to work in this case.
This commit is contained in:
Andreas Bergmeier 2017-05-09 15:01:22 +02:00 committed by Dean Moldovan
parent c67033a926
commit 34b7b54f29
2 changed files with 25 additions and 0 deletions

View File

@ -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);
}

View File

@ -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]