@@ -1348,18 +1348,18 @@ def test_scaffolding(self):
1348
1348
1349
1349
class ClinicExternalTest (TestCase ):
1350
1350
maxDiff = None
1351
+ clinic_py = os .path .join (test_tools .toolsdir , "clinic" , "clinic.py" )
1351
1352
1352
1353
def _do_test (self , * args , expect_success = True ):
1353
- clinic_py = os .path .join (test_tools .toolsdir , "clinic" , "clinic.py" )
1354
1354
with subprocess .Popen (
1355
- [sys .executable , "-Xutf8" , clinic_py , * args ],
1355
+ [sys .executable , "-Xutf8" , self . clinic_py , * args ],
1356
1356
encoding = "utf-8" ,
1357
1357
bufsize = 0 ,
1358
1358
stdout = subprocess .PIPE ,
1359
1359
stderr = subprocess .PIPE ,
1360
1360
) as proc :
1361
1361
proc .wait ()
1362
- if expect_success == bool ( proc .returncode ) :
1362
+ if expect_success and proc .returncode :
1363
1363
self .fail ("" .join (proc .stderr ))
1364
1364
stdout = proc .stdout .read ()
1365
1365
stderr = proc .stderr .read ()
@@ -1449,6 +1449,49 @@ def test_cli_force(self):
1449
1449
generated = f .read ()
1450
1450
self .assertTrue (generated .endswith (checksum ))
1451
1451
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
+
1452
1495
def test_cli_verbose (self ):
1453
1496
with os_helper .temp_dir () as tmp_dir :
1454
1497
fn = os .path .join (tmp_dir , "test.c" )
@@ -1534,6 +1577,35 @@ def test_cli_converters(self):
1534
1577
f"expected converter { converter !r} , got { line !r} "
1535
1578
)
1536
1579
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
+
1537
1609
1538
1610
try :
1539
1611
import _testclinic as ac_tester
0 commit comments