@@ -249,6 +249,68 @@ def test_cpp_monitor_fail_no_matching_if(self):
249249 out = self .expect_failure (raw )
250250 self .assertEqual (out , msg )
251251
252+ def test_directive_output_unknown_preset (self ):
253+ out = self .expect_failure ("""
254+ /*[clinic input]
255+ output preset nosuchpreset
256+ [clinic start generated code]*/
257+ """ )
258+ msg = "Unknown preset 'nosuchpreset'"
259+ self .assertIn (msg , out )
260+
261+ def test_directive_output_cant_pop (self ):
262+ out = self .expect_failure ("""
263+ /*[clinic input]
264+ output pop
265+ [clinic start generated code]*/
266+ """ )
267+ msg = "Can't 'output pop', stack is empty"
268+ self .assertIn (msg , out )
269+
270+ def test_directive_output_print (self ):
271+ raw = dedent ("""
272+ /*[clinic input]
273+ output print 'I told you once.'
274+ [clinic start generated code]*/
275+ """ )
276+ out = self .clinic .parse (raw )
277+ # The generated output will differ for every run, but we can check that
278+ # it starts with the clinic block, we check that it contains all the
279+ # expected fields, and we check that it contains the checksum line.
280+ self .assertTrue (out .startswith (dedent ("""
281+ /*[clinic input]
282+ output print 'I told you once.'
283+ [clinic start generated code]*/
284+ """ )))
285+ fields = {
286+ "cpp_endif" ,
287+ "cpp_if" ,
288+ "docstring_definition" ,
289+ "docstring_prototype" ,
290+ "impl_definition" ,
291+ "impl_prototype" ,
292+ "methoddef_define" ,
293+ "methoddef_ifndef" ,
294+ "parser_definition" ,
295+ "parser_prototype" ,
296+ }
297+ for field in fields :
298+ with self .subTest (field = field ):
299+ self .assertIn (field , out )
300+ last_line = out .rstrip ().split ("\n " )[- 1 ]
301+ self .assertTrue (
302+ last_line .startswith ("/*[clinic end generated code: output=" )
303+ )
304+
305+ def test_unknown_destination_command (self ):
306+ out = self .expect_failure ("""
307+ /*[clinic input]
308+ destination buffer nosuchcommand
309+ [clinic start generated code]*/
310+ """ )
311+ msg = "unknown destination command 'nosuchcommand'"
312+ self .assertIn (msg , out )
313+
252314
253315class ClinicGroupPermuterTest (TestCase ):
254316 def _test (self , l , m , r , output ):
0 commit comments