@@ -71,8 +71,9 @@ def _describe_activity(self):
71
71
return 'compiling: %s' % ' ' .join (self .args )
72
72
73
73
class TestStream :
74
- def __init__ (self , exppath ):
74
+ def __init__ (self , exppath , srcdir ):
75
75
self .exppath = exppath
76
+ self .srcdir = srcdir
76
77
if os .path .exists (exppath ):
77
78
with open (exppath ) as f :
78
79
expdata = f .read ()
@@ -112,6 +113,10 @@ def _cleanup(self, text):
112
113
# Handle stuff like this that changes every time:
113
114
# "Preprocessed source stored into /tmp/ccRm9Xgx.out file, please attach this to your bugreport."
114
115
continue
116
+
117
+ # Strip away references to the srcdir
118
+ line = re .sub (self .srcdir , '' , line )
119
+
115
120
# Remove exact pointer addresses from repr():
116
121
line = re .sub (' object at (0x[0-9a-f]*)>' ,
117
122
' object at 0xdeadbeef>' ,
@@ -272,14 +277,14 @@ class SkipTest(Exception):
272
277
def __init__ (self , reason ):
273
278
self .reason = reason
274
279
275
- def run_test (testdir ):
280
+ def run_test (testdir , srcdir ):
276
281
# Compile each 'input.c', using 'script.py'
277
282
# Assume success and empty stdout; compare against expected stderr, or empty if file not present
278
283
inputfiles = get_source_files (testdir )
279
284
outfile = os .path .join (testdir , 'output.o' )
280
285
script_py = os .path .join (testdir , 'script.py' )
281
- out = TestStream (os .path .join (testdir , 'stdout.txt' ))
282
- err = TestStream (os .path .join (testdir , 'stderr.txt' ))
286
+ out = TestStream (os .path .join (testdir , 'stdout.txt' ), srcdir )
287
+ err = TestStream (os .path .join (testdir , 'stderr.txt' ), srcdir )
283
288
284
289
cp = configparser .SafeConfigParser ()
285
290
metadatapath = os .path .join (testdir , 'metadata.ini' )
@@ -423,11 +428,18 @@ def uses_python_headers():
423
428
type = "string" ,
424
429
dest = "excluded_dirs" ,
425
430
help = "exclude tests in DIR and below" , metavar = "DIR" )
431
+ parser .add_option ("--srcdir" ,
432
+ type = "string" ,
433
+ dest = "srcdir" ,
434
+ help = "FIXME" , metavar = "DIR" )
426
435
parser .add_option ("-s" , "--show" ,
427
436
action = "store_true" , dest = "show" , default = False ,
428
437
help = "Show stdout, stderr and the command line for each test" )
429
438
(options , args ) = parser .parse_args ()
430
439
440
+ if options .srcdir is None :
441
+ options .srcdir = os .getcwd () + os .sep
442
+
431
443
# print (options, args)
432
444
433
445
def find_tests_below (path ):
@@ -445,13 +457,18 @@ def find_tests_below(path):
445
457
testdirs += find_tests_below (path )
446
458
else :
447
459
# Run all the tests
448
- testdirs = find_tests_below ('tests' )
460
+ path = os .path .join (options .srcdir , 'tests' )
461
+ testdirs = find_tests_below (path )
449
462
450
463
def exclude_test (test ):
464
+ if not test .startswith (options .srcdir ):
465
+ test = os .path .join (options .srcdir , test )
451
466
if test in testdirs :
452
467
testdirs .remove (test )
453
468
454
469
def exclude_tests_below (path ):
470
+ if not path .startswith (options .srcdir ):
471
+ path = os .path .join (options .srcdir , path )
455
472
for test in find_tests_below (path ):
456
473
exclude_test (test )
457
474
@@ -784,7 +801,7 @@ def exclude_tests_below(path):
784
801
def run_one_test (testdir ):
785
802
try :
786
803
sys .stdout .write ('%s: ' % testdir )
787
- run_test (testdir )
804
+ run_test (testdir , options . srcdir )
788
805
print ('OK' )
789
806
return (testdir , 'OK' , None )
790
807
except SkipTest :
0 commit comments