@@ -1348,18 +1348,18 @@ def test_scaffolding(self):
13481348
13491349class ClinicExternalTest (TestCase ):
13501350maxDiff = None
1351+ clinic_py = os .path .join (test_tools .toolsdir ,"clinic" ,"clinic.py" )
13511352
13521353def _do_test (self ,* args ,expect_success = True ):
1353- clinic_py = os .path .join (test_tools .toolsdir ,"clinic" ,"clinic.py" )
13541354with subprocess .Popen (
1355- [sys .executable ,"-Xutf8" ,clinic_py ,* args ],
1355+ [sys .executable ,"-Xutf8" ,self . clinic_py ,* args ],
13561356encoding = "utf-8" ,
13571357bufsize = 0 ,
13581358stdout = subprocess .PIPE ,
13591359stderr = subprocess .PIPE ,
13601360 )as proc :
13611361proc .wait ()
1362- if expect_success == bool ( proc .returncode ) :
1362+ if expect_success and proc .returncode :
13631363self .fail ("" .join (proc .stderr ))
13641364stdout = proc .stdout .read ()
13651365stderr = proc .stderr .read ()
@@ -1449,6 +1449,49 @@ def test_cli_force(self):
14491449generated = f .read ()
14501450self .assertTrue (generated .endswith (checksum ))
14511451
1452+ def test_cli_make (self ):
1453+ c_code = dedent ("""
1454+ /*[clinic input]
1455+ [clinic start generated code]*/
1456+ """ )
1457+ py_code = "pass"
1458+ c_files = "file1.c" ,"file2.c"
1459+ py_files = "file1.py" ,"file2.py"
1460+
1461+ def create_files (files ,srcdir ,code ):
1462+ for fn in files :
1463+ path = os .path .join (srcdir ,fn )
1464+ with open (path ,"w" ,encoding = "utf-8" )as f :
1465+ f .write (code )
1466+
1467+ with os_helper .temp_dir ()as tmp_dir :
1468+ # add some folders, some C files and a Python file
1469+ create_files (c_files ,tmp_dir ,c_code )
1470+ create_files (py_files ,tmp_dir ,py_code )
1471+
1472+ # create C files in externals/ dir
1473+ ext_path = os .path .join (tmp_dir ,"externals" )
1474+ with os_helper .temp_dir (path = ext_path )as externals :
1475+ create_files (c_files ,externals ,c_code )
1476+
1477+ # run clinic in verbose mode with --make on tmpdir
1478+ out = self .expect_success ("-v" ,"--make" ,"--srcdir" ,tmp_dir )
1479+
1480+ # expect verbose mode to only mention the C files in tmp_dir
1481+ for filename in c_files :
1482+ with self .subTest (filename = filename ):
1483+ path = os .path .join (tmp_dir ,filename )
1484+ self .assertIn (path ,out )
1485+ for filename in py_files :
1486+ with self .subTest (filename = filename ):
1487+ path = os .path .join (tmp_dir ,filename )
1488+ self .assertNotIn (path ,out )
1489+ # don't expect C files from the externals dir
1490+ for filename in c_files :
1491+ with self .subTest (filename = filename ):
1492+ path = os .path .join (ext_path ,filename )
1493+ self .assertNotIn (path ,out )
1494+
14521495def test_cli_verbose (self ):
14531496with os_helper .temp_dir ()as tmp_dir :
14541497fn = os .path .join (tmp_dir ,"test.c" )
@@ -1534,6 +1577,35 @@ def test_cli_converters(self):
15341577f"expected converter{ converter !r} , got{ line !r} "
15351578 )
15361579
1580+ def test_cli_fail_converters_and_filename (self ):
1581+ out = self .expect_failure ("--converters" ,"test.c" )
1582+ msg = (
1583+ "Usage error: can't specify --converters "
1584+ "and a filename at the same time"
1585+ )
1586+ self .assertIn (msg ,out )
1587+
1588+ def test_cli_fail_no_filename (self ):
1589+ out = self .expect_failure ()
1590+ self .assertIn ("usage: clinic.py" ,out )
1591+
1592+ def test_cli_fail_output_and_multiple_files (self ):
1593+ out = self .expect_failure ("-o" ,"out.c" ,"input.c" ,"moreinput.c" )
1594+ msg = "Usage error: can't use -o with multiple filenames"
1595+ self .assertIn (msg ,out )
1596+
1597+ def test_cli_fail_filename_or_output_and_make (self ):
1598+ for opts in ("-o" ,"out.c" ), ("filename.c" ,):
1599+ with self .subTest (opts = opts ):
1600+ out = self .expect_failure ("--make" ,* opts )
1601+ msg = "Usage error: can't use -o or filenames with --make"
1602+ self .assertIn (msg ,out )
1603+
1604+ def test_cli_fail_make_without_srcdir (self ):
1605+ out = self .expect_failure ("--make" ,"--srcdir" ,"" )
1606+ msg = "Usage error: --srcdir must not be empty with --make"
1607+ self .assertIn (msg ,out )
1608+
15371609
15381610try :
15391611import _testclinic as ac_tester