Skip to content

Commit a7acc5c

Browse files
[3.11] gh-106368: Increase Argument Clinic test coverage for cpp.Monitor (GH-106833) (#106839)
(cherry picked from commit 22379c6) Co-authored-by: Erlend E. Aasland <erlend@python.org>
1 parent a782d51 commit a7acc5c

File tree

2 files changed

+180
-1
lines changed

2 files changed

+180
-1
lines changed

Lib/test/clinic.test.c

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3278,6 +3278,47 @@ test_preprocessor_guarded_else_impl(PyObject *module)
32783278
/*[clinic end generated code: output=13af7670aac51b12 input=6657ab31d74c29fc]*/
32793279
#endif
32803280

3281+
#ifndef CONDITION_C
3282+
/*[clinic input]
3283+
test_preprocessor_guarded_ifndef_condition_c
3284+
[clinic start generated code]*/
3285+
3286+
static PyObject *
3287+
test_preprocessor_guarded_ifndef_condition_c_impl(PyObject *module)
3288+
/*[clinic end generated code: output=ed422e8c895bb0a5 input=e9b50491cea2b668]*/
3289+
#else
3290+
/*[clinic input]
3291+
test_preprocessor_guarded_ifndef_not_condition_c
3292+
[clinic start generated code]*/
3293+
3294+
static PyObject *
3295+
test_preprocessor_guarded_ifndef_not_condition_c_impl(PyObject *module)
3296+
/*[clinic end generated code: output=de6f4c6a67f8c536 input=da74e30e01c6f2c5]*/
3297+
#endif
3298+
3299+
#if \
3300+
CONDITION_D
3301+
/*[clinic input]
3302+
test_preprocessor_guarded_if_with_continuation
3303+
[clinic start generated code]*/
3304+
3305+
static PyObject *
3306+
test_preprocessor_guarded_if_with_continuation_impl(PyObject *module)
3307+
/*[clinic end generated code: output=3d0712ca9e2d15b9 input=4a956fd91be30284]*/
3308+
#endif
3309+
3310+
#if CONDITION_E || CONDITION_F
3311+
#warning "different type of CPP directive"
3312+
/*[clinic input]
3313+
test_preprocessor_guarded_if_e_or_f
3314+
Makes sure cpp.Monitor handles other directives than preprocessor conditionals.
3315+
[clinic start generated code]*/
3316+
3317+
static PyObject *
3318+
test_preprocessor_guarded_if_e_or_f_impl(PyObject *module)
3319+
/*[clinic end generated code: output=e49d24ff64ad88bc input=57b9c37f938bc4f1]*/
3320+
#endif
3321+
32813322
/*[clinic input]
32823323
dump buffer
32833324
output pop
@@ -3337,6 +3378,79 @@ test_preprocessor_guarded_else(PyObject *module, PyObject *Py_UNUSED(ignored))
33373378

33383379
#endif /* !defined(CONDITION_A) && !(CONDITION_B) */
33393380

3381+
#if !defined(CONDITION_C)
3382+
3383+
PyDoc_STRVAR(test_preprocessor_guarded_ifndef_condition_c__doc__,
3384+
"test_preprocessor_guarded_ifndef_condition_c($module, /)\n"
3385+
"--\n"
3386+
"\n");
3387+
3388+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF \
3389+
{"test_preprocessor_guarded_ifndef_condition_c", (PyCFunction)test_preprocessor_guarded_ifndef_condition_c, METH_NOARGS, test_preprocessor_guarded_ifndef_condition_c__doc__},
3390+
3391+
static PyObject *
3392+
test_preprocessor_guarded_ifndef_condition_c(PyObject *module, PyObject *Py_UNUSED(ignored))
3393+
{
3394+
return test_preprocessor_guarded_ifndef_condition_c_impl(module);
3395+
}
3396+
3397+
#endif /* !defined(CONDITION_C) */
3398+
3399+
#if defined(CONDITION_C)
3400+
3401+
PyDoc_STRVAR(test_preprocessor_guarded_ifndef_not_condition_c__doc__,
3402+
"test_preprocessor_guarded_ifndef_not_condition_c($module, /)\n"
3403+
"--\n"
3404+
"\n");
3405+
3406+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF \
3407+
{"test_preprocessor_guarded_ifndef_not_condition_c", (PyCFunction)test_preprocessor_guarded_ifndef_not_condition_c, METH_NOARGS, test_preprocessor_guarded_ifndef_not_condition_c__doc__},
3408+
3409+
static PyObject *
3410+
test_preprocessor_guarded_ifndef_not_condition_c(PyObject *module, PyObject *Py_UNUSED(ignored))
3411+
{
3412+
return test_preprocessor_guarded_ifndef_not_condition_c_impl(module);
3413+
}
3414+
3415+
#endif /* defined(CONDITION_C) */
3416+
3417+
#if (CONDITION_D)
3418+
3419+
PyDoc_STRVAR(test_preprocessor_guarded_if_with_continuation__doc__,
3420+
"test_preprocessor_guarded_if_with_continuation($module, /)\n"
3421+
"--\n"
3422+
"\n");
3423+
3424+
#define TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF \
3425+
{"test_preprocessor_guarded_if_with_continuation", (PyCFunction)test_preprocessor_guarded_if_with_continuation, METH_NOARGS, test_preprocessor_guarded_if_with_continuation__doc__},
3426+
3427+
static PyObject *
3428+
test_preprocessor_guarded_if_with_continuation(PyObject *module, PyObject *Py_UNUSED(ignored))
3429+
{
3430+
return test_preprocessor_guarded_if_with_continuation_impl(module);
3431+
}
3432+
3433+
#endif /* (CONDITION_D) */
3434+
3435+
#if (CONDITION_E || CONDITION_F)
3436+
3437+
PyDoc_STRVAR(test_preprocessor_guarded_if_e_or_f__doc__,
3438+
"test_preprocessor_guarded_if_e_or_f($module, /)\n"
3439+
"--\n"
3440+
"\n"
3441+
"Makes sure cpp.Monitor handles other directives than preprocessor conditionals.");
3442+
3443+
#define TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF \
3444+
{"test_preprocessor_guarded_if_e_or_f", (PyCFunction)test_preprocessor_guarded_if_e_or_f, METH_NOARGS, test_preprocessor_guarded_if_e_or_f__doc__},
3445+
3446+
static PyObject *
3447+
test_preprocessor_guarded_if_e_or_f(PyObject *module, PyObject *Py_UNUSED(ignored))
3448+
{
3449+
return test_preprocessor_guarded_if_e_or_f_impl(module);
3450+
}
3451+
3452+
#endif /* (CONDITION_E || CONDITION_F) */
3453+
33403454
#ifndef TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF
33413455
#define TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF
33423456
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF) */
@@ -3348,7 +3462,23 @@ test_preprocessor_guarded_else(PyObject *module, PyObject *Py_UNUSED(ignored))
33483462
#ifndef TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF
33493463
#define TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF
33503464
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF) */
3351-
/*[clinic end generated code: output=3804bb18d454038c input=3fc80c9989d2f2e1]*/
3465+
3466+
#ifndef TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF
3467+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF
3468+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF) */
3469+
3470+
#ifndef TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF
3471+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF
3472+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF) */
3473+
3474+
#ifndef TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF
3475+
#define TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF
3476+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF) */
3477+
3478+
#ifndef TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF
3479+
#define TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF
3480+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF) */
3481+
/*[clinic end generated code: output=fcfae7cac7a99e62 input=3fc80c9989d2f2e1]*/
33523482

33533483
/*[clinic input]
33543484
test_vararg_and_posonly

Lib/test/test_clinic.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,55 @@ def test_parse_with_body_prefix(self):
200200
""").lstrip() # Note, lstrip() because of the newline
201201
self.assertEqual(out, expected)
202202

203+
def test_cpp_monitor_fail_nested_block_comment(self):
204+
raw = """
205+
/* start
206+
/* nested
207+
*/
208+
*/
209+
"""
210+
msg = (
211+
'Error in file "test.c" on line 2:\n'
212+
'Nested block comment!\n'
213+
)
214+
out = self.expect_failure(raw)
215+
self.assertEqual(out, msg)
216+
217+
def test_cpp_monitor_fail_invalid_format_noarg(self):
218+
raw = """
219+
#if
220+
a()
221+
#endif
222+
"""
223+
msg = (
224+
'Error in file "test.c" on line 1:\n'
225+
'Invalid format for #if line: no argument!\n'
226+
)
227+
out = self.expect_failure(raw)
228+
self.assertEqual(out, msg)
229+
230+
def test_cpp_monitor_fail_invalid_format_toomanyargs(self):
231+
raw = """
232+
#ifdef A B
233+
a()
234+
#endif
235+
"""
236+
msg = (
237+
'Error in file "test.c" on line 1:\n'
238+
'Invalid format for #ifdef line: should be exactly one argument!\n'
239+
)
240+
out = self.expect_failure(raw)
241+
self.assertEqual(out, msg)
242+
243+
def test_cpp_monitor_fail_no_matching_if(self):
244+
raw = '#else'
245+
msg = (
246+
'Error in file "test.c" on line 1:\n'
247+
'#else without matching #if / #ifdef / #ifndef!\n'
248+
)
249+
out = self.expect_failure(raw)
250+
self.assertEqual(out, msg)
251+
203252

204253
class ClinicGroupPermuterTest(TestCase):
205254
def _test(self, l, m, r, output):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy