@@ -81,11 +81,19 @@ def beebasm_args(beebasm, file_name, ssd_name):
81
81
args += ['-v' , '-i' , file_name ]
82
82
return args
83
83
84
- def execute_test (beebasm_arg_list ):
84
+ def execute (args , output ):
85
+ # Child stderr written to stdout to avoid output interleaving problems
86
+ return subprocess .Popen (args , stdout = output , stderr = output ).wait () == 0
87
+
88
+ def execute_test (beebasm_arg_list , capture_name ):
85
89
print (beebasm_arg_list )
86
90
sys .stdout .flush ()
87
- # Child stderr written to stdout to avoid output interleaving problems
88
- return subprocess .Popen (beebasm_arg_list , stdout = sys .stdout , stderr = sys .stdout ).wait () == 0
91
+
92
+ if capture_name == None :
93
+ return execute (beebasm_arg_list , sys .stdout )
94
+
95
+ with open (capture_name , 'w' , encoding = sys .stdout .encoding ) as capture :
96
+ return execute (beebasm_arg_list , capture )
89
97
90
98
def run_test (beebasm , path , file_names , file_name ):
91
99
if file_name .endswith ('.inc.6502' ):
@@ -98,18 +106,43 @@ def run_test(beebasm, path, file_names, file_name):
98
106
99
107
failure_test = file_name .endswith ('.fail.6502' )
100
108
gold_ssd = replace_extension (file_name , '.gold.ssd' )
109
+ gold_txt = replace_extension (file_name , '.gold.txt' )
101
110
ssd_name = None
111
+ gold_capture = None
102
112
if gold_ssd in file_names :
103
113
ssd_name = 'test.ssd'
114
+ if gold_txt in file_names :
115
+ gold_capture = 'testgold.txt'
116
+
117
+ result = execute_test (beebasm_args (beebasm , file_name , ssd_name ), gold_capture )
118
+
119
+ if not gold_capture is None :
120
+ # This won't work well if a test produces gigabytes of output. Don't do that!
121
+ with open (gold_capture , 'r' ) as capture_file :
122
+ capture = capture_file .read ()
123
+ # Duplicate captured data on stdout
124
+ sys .stdout .write (capture )
125
+ with open (gold_txt , 'r' ) as gold_file :
126
+ gold = gold_file .read ()
127
+ print ('Comparing beebasm output to' , gold_txt , end = '' )
128
+ if capture .find (gold ) != - 1 :
129
+ print (' succeeded' )
130
+ else :
131
+ print (' failed' )
132
+ raise TestFailure ('Test output does not include gold text: ' + gold_txt )
104
133
105
- result = execute_test (beebasm_args (beebasm , file_name , ssd_name ))
106
134
if failure_test and result :
107
135
raise TestFailure ('Failure test succeeded: ' + full_name )
108
136
elif not failure_test and not result :
109
137
raise TestFailure ('Success test failed: ' + full_name )
110
138
111
- if not failure_test and ssd_name != None and not compare_files (gold_ssd , ssd_name ):
112
- raise TestFailure ('ssd does not match gold ssd: ' + gold_ssd )
139
+ if not failure_test and ssd_name != None :
140
+ print ('Comparing output ssd to' , gold_ssd , end = '' )
141
+ if compare_files (gold_ssd , ssd_name ):
142
+ print (' succeeded' )
143
+ else :
144
+ print (' failed' )
145
+ raise TestFailure ('ssd does not match gold ssd: ' + gold_ssd )
113
146
114
147
def scan_directory (beebasm ):
115
148
for (path , directory_names , file_names ) in os .walk ('.' , topdown = True ):
0 commit comments