From 34b7b54f2947ecc5b15d3dc60ee61aa60b8ef270 Mon Sep 17 00:00:00 2001 From: Andreas Bergmeier Date: Tue, 9 May 2017 15:01:22 +0200 Subject: [PATCH] Add tests for passing STL containers by pointer `nullptr` is not expected to work in this case. --- tests/test_stl.cpp | 2 ++ tests/test_stl.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index 528809768..9762fb9a7 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -160,4 +160,6 @@ TEST_SUBMODULE(stl, m) { }; }); + // test_stl_pass_by_pointer + m.def("stl_pass_by_pointer", [](std::vector* v) { return *v; }, "v"_a=nullptr); } diff --git a/tests/test_stl.py b/tests/test_stl.py index 1c982583b..fdbca0daf 100644 --- a/tests/test_stl.py +++ b/tests/test_stl.py @@ -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]