@@ -71,8 +71,9 @@ def _describe_activity(self):
7171 return 'compiling: %s' % ' ' .join (self .args )
7272
7373class TestStream :
74- def __init__ (self , exppath ):
74+ def __init__ (self , exppath , srcdir ):
7575 self .exppath = exppath
76+ self .srcdir = srcdir
7677 if os .path .exists (exppath ):
7778 with open (exppath ) as f :
7879 expdata = f .read ()
@@ -112,6 +113,10 @@ def _cleanup(self, text):
112113 # Handle stuff like this that changes every time:
113114 # "Preprocessed source stored into /tmp/ccRm9Xgx.out file, please attach this to your bugreport."
114115 continue
116+
117+ # Strip away references to the srcdir
118+ line = re .sub (self .srcdir , '' , line )
119+
115120 # Remove exact pointer addresses from repr():
116121 line = re .sub (' object at (0x[0-9a-f]*)>' ,
117122 ' object at 0xdeadbeef>' ,
@@ -272,14 +277,14 @@ class SkipTest(Exception):
272277 def __init__ (self , reason ):
273278 self .reason = reason
274279
275- def run_test (testdir ):
280+ def run_test (testdir , srcdir ):
276281 # Compile each 'input.c', using 'script.py'
277282 # Assume success and empty stdout; compare against expected stderr, or empty if file not present
278283 inputfiles = get_source_files (testdir )
279284 outfile = os .path .join (testdir , 'output.o' )
280285 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 )
283288
284289 cp = configparser .SafeConfigParser ()
285290 metadatapath = os .path .join (testdir , 'metadata.ini' )
@@ -423,11 +428,18 @@ def uses_python_headers():
423428 type = "string" ,
424429 dest = "excluded_dirs" ,
425430 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" )
426435parser .add_option ("-s" , "--show" ,
427436 action = "store_true" , dest = "show" , default = False ,
428437 help = "Show stdout, stderr and the command line for each test" )
429438(options , args ) = parser .parse_args ()
430439
440+ if options .srcdir is None :
441+ options .srcdir = os .getcwd () + os .sep
442+
431443# print (options, args)
432444
433445def find_tests_below (path ):
@@ -445,13 +457,18 @@ def find_tests_below(path):
445457 testdirs += find_tests_below (path )
446458else :
447459 # Run all the tests
448- testdirs = find_tests_below ('tests' )
460+ path = os .path .join (options .srcdir , 'tests' )
461+ testdirs = find_tests_below (path )
449462
450463def exclude_test (test ):
464+ if not test .startswith (options .srcdir ):
465+ test = os .path .join (options .srcdir , test )
451466 if test in testdirs :
452467 testdirs .remove (test )
453468
454469def exclude_tests_below (path ):
470+ if not path .startswith (options .srcdir ):
471+ path = os .path .join (options .srcdir , path )
455472 for test in find_tests_below (path ):
456473 exclude_test (test )
457474
@@ -784,7 +801,7 @@ def exclude_tests_below(path):
784801def run_one_test (testdir ):
785802 try :
786803 sys .stdout .write ('%s: ' % testdir )
787- run_test (testdir )
804+ run_test (testdir , options . srcdir )
788805 print ('OK' )
789806 return (testdir , 'OK' , None )
790807 except SkipTest :
0 commit comments