summaryrefslogtreecommitdiff
path: root/tests/run/legacy_implicit_noexcept.pyx
blob: b6799df468cb9b0ed6f947f359349c995e990775 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# cython: legacy_implicit_noexcept=True
# mode: run
# tag: warnings
import sys
import functools
import cython
try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

cdef int func_implicit(int a, int b):
    raise RuntimeError

cdef int func_noexcept(int a, int b) noexcept:
    raise RuntimeError

cdef int func_star(int a, int b) except *:
    raise RuntimeError

cdef int func_value(int a, int b) except -1:
    raise RuntimeError

cdef func_return_obj_implicit(int a, int b):
    raise RuntimeError

cdef int(*ptr_func_implicit)(int, int)
ptr_func_implicit = func_implicit

cdef int(*ptr_func_noexcept)(int, int) noexcept
ptr_func_noexcept = func_noexcept

@cython.cfunc
def func_pure_implicit() -> cython.int:
    raise RuntimeError

@cython.excetval(check=False)
@cython.cfunc
def func_pure_noexcept() -> cython.int:
    raise RuntimeError

def return_stderr(func):
    @functools.wraps(func)
    def testfunc():
        old_stderr = sys.stderr
        stderr = sys.stderr = StringIO()
        try:
            func()
        finally:
            sys.stderr = old_stderr
        return stderr.getvalue().strip()

    return testfunc

@return_stderr
def test_noexcept():
    """
    >>> print(test_noexcept())  # doctest: +ELLIPSIS
    RuntimeError
    Exception...ignored...
    """
    func_noexcept(3, 5)

@return_stderr
def test_ptr_noexcept():
    """
    >>> print(test_ptr_noexcept())  # doctest: +ELLIPSIS
    RuntimeError
    Exception...ignored...
    """
    ptr_func_noexcept(3, 5)

@return_stderr
def test_implicit():
    """
    >>> print(test_implicit())  # doctest: +ELLIPSIS
    RuntimeError
    Exception...ignored...
    """
    func_implicit(1, 2)

@return_stderr
def test_ptr_implicit():
    """
    >>> print(test_ptr_implicit())  # doctest: +ELLIPSIS
    RuntimeError
    Exception...ignored...
    """
    ptr_func_implicit(1, 2)

def test_star():
    """
    >>> test_star()
    Traceback (most recent call last):
    ...
    RuntimeError
    """
    func_star(1, 2)

def test_value():
    """
    >>> test_value()
    Traceback (most recent call last):
    ...
    RuntimeError
    """
    func_value(1, 2)


def test_return_obj_implicit():
    """
    >>> test_return_obj_implicit()
    Traceback (most recent call last):
    ...
    RuntimeError
    """
    func_return_obj_implicit(1, 2)

def test_pure_implicit():
    """
    >>> test_pure_implicit()
    Traceback (most recent call last):
    ...
    RuntimeError
    """
    func_pure_implicit()

def test_pure_noexcept():
    """
    >>> test_pure_noexcept()
    Traceback (most recent call last):
    ...
    RuntimeError
    """
    func_pure_noexcept()

_WARNINGS = """
12:5: Unraisable exception in function 'legacy_implicit_noexcept.func_implicit'.
12:36: Implicit noexcept declaration is deprecated. Function declaration should contain 'noexcept' keyword.
15:5: Unraisable exception in function 'legacy_implicit_noexcept.func_noexcept'.
24:43: Implicit noexcept declaration is deprecated. Function declaration should contain 'noexcept' keyword.
27:38: Implicit noexcept declaration is deprecated. Function declaration should contain 'noexcept' keyword.
"""