8000 [3.12] gh-106368: Increase Argument Clinic test coverage for cpp.Moni… · python/cpython@941ac1e · GitHub
[go: up one dir, main page]

Skip to content

Commit 941ac1e

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

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

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

37923833
#endif /* !defined(CONDITION_A) && !(CONDITION_B) */
37933834

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

38073937
/*[clinic input]
38083938
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