8000 gh-106368: Increase Argument Clinic test coverage for cpp.Monitor (#1… · python/cpython@22379c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22379c6

Browse files
gh-106368: Increase Argument Clinic test coverage for cpp.Monitor (#106833)
1 parent ebf2c56 commit 22379c6

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
@@ -3726,6 +3726,47 @@ test_preprocessor_guarded_else_impl(PyObject *module)
37263726
/*[clinic end generated code: output=13af7670aac51b12 input=6657ab31d74c29fc]*/
37273727
#endif
37283728

3729+
#ifndef CONDITION_C
3730+
/*[clinic input]
3731+
test_preprocessor_guarded_ifndef_condition_c
3732+
[clinic start generated code]*/
3733+
3734+
static PyObject *
3735+
test_preprocessor_guarded_ifndef_condition_c_impl(PyObject *module)
3736+
/*[clinic end generated code: output=ed422e8c895bb0a5 input=e9b50491cea2b668]*/
3737+
#else
3738+
/*[clinic input]
3739+
test_preprocessor_guarded_ifndef_not_condition_c
3740+
[clinic start generated code]*/
3741+
3742+
static PyObject *
3743+
test_preprocessor_guarded_ifndef_not_condition_c_impl(PyObject *module)
3744+
/*[clinic end generated code: output=de6f4c6a67f8c536 input=da74e30e01c6f2c5]*/
3745+
#endif
3746+
3747+
#if \
3748+
CONDITION_D
3749+
/*[clinic input]
3750+
test_preprocessor_guarded_if_with_continuation
3751+
[clinic start generated code]*/
3752+
3753+
static PyObject *
3754+
test_preprocessor_guarded_if_with_continuation_impl(PyObject *module)
3755+
/*[clinic end generated code: output=3d0712ca9e2d15b9 input=4a956fd91be30284]*/
3756+
#endif
3757+
3758+
#if CONDITION_E || CONDITION_F
3759+
#warning "different type of CPP directive"
3760+
/*[clinic input]
3761+
test_preprocessor_guarded_if_e_or_f
3762+
Makes sure cpp.Monitor handles other directives than preprocessor conditionals.
3763+
[clinic start generated code]*/
3764+
3765+
static PyObject *
3766+
test_preprocessor_guarded_if_e_or_f_impl(PyObject *module)
3767+
/*[clinic end generated code: output=e49d24ff64ad88bc input=57b9c37f938bc4f1]*/
3768+
#endif
3769+
37293770
/*[clinic input]
37303771
dump buffer
37313772
output pop
@@ -3785,6 +3826,79 @@ test_preprocessor_guarded_else(PyObject *module, PyObject *Py_UNUSED(ignored))
37853826

37863827
#endif /* !defined(CONDITION_A) && !(CONDITION_B) */
37873828

3829+
#if !defined(CONDITION_C)
3830+
3831+
PyDoc_STRVAR(test_preprocessor_guarded_ifndef_condition_c__doc__,
3832+
"test_preprocessor_guarded_ifndef_condition_c($module, /)\n"
3833+
"--\n"
3834+
"\n");
3835+
3836+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF \
3837+
{"test_preprocessor_guarded_ifndef_condition_c", (PyCFunction)test_preprocessor_guarded_ifndef_condition_c, METH_NOARGS, test_preprocessor_guarded_ifndef_condition_c__doc__},
3838+
3839+
static PyObject *
3840+
test_preprocessor_guarded_ifndef_condition_c(PyObject *module, PyObject *Py_UNUSED(ignored))
3841+
{
3842+
return test_preprocessor_guarded_ifndef_condition_c_impl(module);
3843+
}
3844+
3845+
#endif /* !defined(CONDITION_C) */
3846+
3847+
#if defined(CONDITION_C)
3848+
3849+
PyDoc_STRVAR(test_preprocessor_guarded_ifndef_not_condition_c__doc__,
3850+
"test_preprocessor_guarded_ifndef_not_condition_c($module, /)\n"
3851+
"--\n"
3852+
"\n");
3853+
3854+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF \
3855+
{"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__},
3856+
3857+
static PyObject *
3858+
test_preprocessor_guarded_ifndef_not_condition_c(PyObject *module, PyObject *Py_UNUSED(ignored))
3859+
{
3860+
return test_preprocessor_guarded_ifndef_not_condition_c_impl(module);
3861+
}
3862+
3863+
#endif /* defined(CONDITION_C) */
3864+
3865+
#if (CONDITION_D)
3866+
3867+
PyDoc_STRVAR(test_preprocessor_guarded_if_with_continuation__doc__,
3868+
"test_preprocessor_guarded_if_with_continuation($module, /)\n"
3869+
"--\n"
3870+
"\n");
3871+
3872+
#define TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF \
3873+
{"test_preprocessor_guarded_if_with_continuation", (PyCFunction)test_preprocessor_guarded_if_with_continuation, 9E88 METH_NOARGS, test_preprocessor_guarded_if_with_continuation__doc__},
3874+
3875+
static PyObject *
3876+
test_preprocessor_guarded_if_with_continuation(PyObject *module, PyObject *Py_UNUSED(ignored))
3877+
{
3878+
return test_preprocessor_guarded_if_with_continuation_impl(module);
3879+
}
3880+
3881+
#endif /* (CONDITION_D) */
3882+
3883+
#if (CONDITION_E || CONDITION_F)
3884+
3885+
PyDoc_STRVAR(test_preprocessor_guarded_if_e_or_f__doc__,
3886+
"test_preprocessor_guarded_if_e_or_f($module, /)\n"
3887+
"--\n"
3888+
"\n"
3889+
"Makes sure cpp.Monitor handles other directives than preprocessor conditionals.");
3890+
3891+
#define TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF \
3892+
{"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__},
3893+
3894+
static PyObject *
3895+
test_preprocessor_guarded_if_e_or_f(PyObject *module, PyObject *Py_UNUSED(ignored))
3896+
{
3897+
return test_preprocessor_guarded_if_e_or_f_impl(module);
3898+
}
3899+
3900+
#endif /* (CONDITION_E || CONDITION_F) */
3901+
37883902
#ifndef TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF
37893903
#define TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF
37903904
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF) */
@@ -3796,7 +3910,23 @@ test_preprocessor_guarded_else(PyObject *module, PyObject *Py_UNUSED(ignored))
37963910
#ifndef TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF
37973911
#define TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF
37983912
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF) */
3799-
/*[clinic end generated code: output=3804bb18d454038c input=3fc80c9989d2f2e1]*/
3913+
3914+
#ifndef TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF
3915+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF
3916+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IFNDEF_CONDITION_C_METHODDEF) */
3917+
3918+
#ifndef TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF
3919+
#define TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF
3920+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IFNDEF_NOT_CONDITION_C_METHODDEF) */
3921+
3922+
#ifndef TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF
3923+
#define TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF
3924+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IF_WITH_CONTINUATION_METHODDEF) */
3925+
3926+
#ifndef TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF
3927+
#define TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF
3928+
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_IF_E_OR_F_METHODDEF) */
3929+
/*[clinic end generated code: output=fcfae7cac7a99e62 input=3fc80c9989d2f2e1]*/
38003930

38013931
/*[clinic input]
38023932
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)
0