@@ -1294,18 +1294,18 @@ def test_scaffolding(self):
1294
1294
1295
1295
class ClinicExternalTest (TestCase ):
1296
1296
maxDiff = None
1297
+ clinic_py = os .path .join (test_tools .toolsdir , "clinic" , "clinic.py" )
1297
1298
1298
1299
def _do_test (self , * args , expect_success = True ):
1299
- clinic_py = os .path .join (test_tools .toolsdir , "clinic" , "clinic.py" )
1300
1300
with subprocess .Popen (
1301
- [sys .executable , "-Xutf8" , clinic_py , * args ],
1301
+ [sys .executable , "-Xutf8" , self . clinic_py , * args ],
1302
1302
encoding = "utf-8" ,
1303
1303
bufsize = 0 ,
1304
1304
stdout = subprocess .PIPE ,
1305
1305
stderr = subprocess .PIPE ,
1306
1306
) as proc :
1307
1307
proc .wait ()
1308
- if expect_success == bool ( proc .returncode ) :
1308
+ if expect_success and proc .returncode :
1309
1309
self .fail ("" .join (proc .stderr ))
1310
1310
stdout = proc .stdout .read ()
1311
1311
stderr = proc .stderr .read ()
@@ -1395,6 +1395,49 @@ def test_cli_force(self):
1395
1395
generated = f .read ()
1396
1396
self .assertTrue (generated .endswith (checksum ))
1397
1397
1398
+ def test_cli_make (self ):
1399
+ c_code = dedent ("""
1400
+ /*[clinic input]
1401
+ [clinic start generated code]*/
1402
+ """ )
1403
+ py_code = "pass"
1404
+ c_files = "file1.c" , "file2.c"
1405
+ py_files = "file1.py" , "file2.py"
1406
+
1407
+ def create_files (files , srcdir , code ):
1408
+ for fn in files :
1409
+ path = os .path .join (srcdir , fn )
1410
+ with open (path , "w" , encoding = "utf-8" ) as f :
1411
+ f .write (code )
1412
+
1413
+ with os_helper .temp_dir () as tmp_dir :
1414
+ # add some folders, some C files and a Python file
1415
+ create_files (c_files , tmp_dir , c_code )
1416
+ create_files (py_files , tmp_dir , py_code )
1417
+
1418
+ # create C files in externals/ dir
1419
+ ext_path = os .path .join (tmp_dir , "externals" )
1420
+ with os_helper .temp_dir (path = ext_path ) as externals :
1421
+ create_files (c_files , externals , c_code )
1422
+
1423
+ # run clinic in verbose mode with --make on tmpdir
1424
+ out = self .expect_success ("-v" , "--make" , "--srcdir" , tmp_dir )
1425
+
1426
+ # expect verbose mode to only mention the C files in tmp_dir
1427
+ for filename in c_files :
1428
+ with self .subTest (filename = filename ):
1429
+ path = os .path .join (tmp_dir , filename )
1430
+ self .assertIn (path , out )
1431
+ for filename in py_files :
1432
+ with self .subTest (filename = filename ):
1433
+ path = os .path .join (tmp_dir , filename )
1434
+ self .assertNotIn (path , out )
1435
+ # don't expect C files from the externals dir
1436
+ for filename in c_files :
1437
+ with self .subTest (filename = filename ):
1438
+ path = os .path .join (ext_path , filename )
1439
+ self .assertNotIn (path , out )
1440
+
1398
1441
def test_cli_verbose (self ):
1399
1442
with os_helper .temp_dir () as tmp_dir :
1400
1443
fn = os .path .join (tmp_dir , "test.c" )
@@ -1481,6 +1524,35 @@ def test_cli_converters(self):
1481
1524
f"expected converter { converter !r} , got { line !r} "
1482
1525
)
1483
1526
1527
+ def test_cli_fail_converters_and_filename (self ):
1528
+ out = self .expect_failure ("--converters" , "test.c" )
1529
+ msg = (
1530
+ "Usage error: can't specify --converters "
1531
+ "and a filename at the same time"
1532
+ )
1533
+ self .assertIn (msg , out )
1534
+
1535
+ def test_cli_fail_no_filename (self ):
1536
+ out = self .expect_failure ()
1537
+ self .assertIn ("usage: clinic.py" , out )
1538
+
1539
+ def test_cli_fail_output_and_multiple_files (self ):
1540
+ out = self .expect_failure ("-o" , "out.c" , "input.c" , "moreinput.c" )
1541
+ msg = "Usage error: can't use -o with multiple filenames"
1542
+ self .assertIn (msg , out )
1543
+
1544
+ def test_cli_fail_filename_or_output_and_make (self ):
1545
+ for opts in ("-o" , "out.c" ), ("filename.c" ,):
1546
+ with self .subTest (opts = opts ):
1547
+ out = self .expect_failure ("--make" , * opts )
1548
+ msg = "Usage error: can't use -o or filenames with --make"
1549
+ self .assertIn (msg , out )
1550
+
1551
+ def test_cli_fail_make_without_srcdir (self ):
1552
+ out = self .expect_failure ("--make" , "--srcdir" , "" )
1553
+ msg = "Usage error: --srcdir must not be empty with --make"
1554
+ self .assertIn (msg , out )
1555
+
1484
1556
1485
1557
try :
1486
1558
import _testclinic as ac_tester
0 commit comments