|
| 1 | +# Copyright 2014-2017 Insight Software Consortium. |
| 2 | +# Copyright 2004-2009 Roman Yakovenko. |
| 3 | +# Distributed under the Boost Software License, Version 1.0. |
| 4 | +# See http://www.boost.org/LICENSE_1_0.txt |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +import warnings |
| 9 | + |
| 10 | +from . import autoconfig |
| 11 | + |
| 12 | +from pygccxml import parser |
| 13 | +from pygccxml import declarations |
| 14 | + |
| 15 | + |
| 16 | +TEST_FILES = [ |
| 17 | + "test_dynamic_exception.hpp", |
| 18 | +] |
| 19 | + |
| 20 | + |
| 21 | +@pytest.fixture |
| 22 | +def global_ns(): |
| 23 | + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE |
| 24 | + config = autoconfig.cxx_parsers_cfg.config.clone() |
| 25 | + # This test does not work with c++17 and above |
| 26 | + # See https://developers.redhat.com/articles/2021/08/06/porting-your-code-c17-gcc-11#exception_specification_changes # noqa |
| 27 | + # This test is thus excpected to use -std=c++14 forever |
| 28 | + config.cflags = "-std=c++14" |
| 29 | + decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) |
| 30 | + global_ns = declarations.get_global_namespace(decls) |
| 31 | + global_ns.init_optimizer() |
| 32 | + return global_ns |
| 33 | + |
| 34 | + |
| 35 | +def test_calldef_with_throw(global_ns, helpers): |
| 36 | + calldef_with_throw = global_ns.free_function("calldef_with_throw") |
| 37 | + assert calldef_with_throw is not None |
| 38 | + helpers._test_calldef_exceptions( |
| 39 | + global_ns, calldef_with_throw, |
| 40 | + ["some_exception_t", "other_exception_t"] |
| 41 | + ) |
| 42 | + |
| 43 | + calldef_with_throw = global_ns.calldef('calldef_with_throw') |
| 44 | + some_exception = global_ns.class_('some_exception_t') |
| 45 | + other_exception = global_ns.class_('other_exception_t') |
| 46 | + |
| 47 | + # Legacy way of fetching dependencies. Is still valid but deprecated |
| 48 | + warnings.simplefilter("ignore", Warning) |
| 49 | + dependencies_old = calldef_with_throw.i_depend_on_them() |
| 50 | + warnings.simplefilter("error", Warning) |
| 51 | + assert len(dependencies_old) == 3 |
| 52 | + dependencies_old = [ |
| 53 | + dependency for dependency in dependencies_old if |
| 54 | + dependency.depend_on_it in (some_exception, other_exception)] |
| 55 | + assert len(dependencies_old) == 2 |
| 56 | + |
| 57 | + dependencies_new = declarations.get_dependencies_from_decl( |
| 58 | + calldef_with_throw) |
| 59 | + assert len(dependencies_new) == 3 |
| 60 | + dependencies_new = [ |
| 61 | + dependency for dependency in dependencies_new if |
| 62 | + dependency.depend_on_it in (some_exception, other_exception)] |
| 63 | + assert len(dependencies_new) == 2 |
0 commit comments