Skip to content

Commit 8f1e676

Browse files
committed
Compare beebasm printed output to .gold.txt files
1 parent acc1849 commit 8f1e676

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
test/testlog.txt
77
test/**/test
88
test/**/test.ssd
9+
test/**/testgold.txt

test/errorlinenumber1.fail.gold.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
errorlinenumber1.fail.6502:10: error: Indirect mode not allowed for this instruction.
2+
3+
ldx (&70),y
4+
^
5+
6+
Call stack:
7+
errorlinenumber1.fail.6502:13

test/errorlinenumber2.fail.gold.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
errorlinenumber2.fail.6502:9: error: Indirect mode not allowed for this instruction.
2+
3+
ldx (&70),y
4+
^

test/testrunner.py

+39-6
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,19 @@ def beebasm_args(beebasm, file_name, ssd_name):
8181
args += ['-v', '-i', file_name]
8282
return args
8383

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):
8589
print(beebasm_arg_list)
8690
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)
8997

9098
def run_test(beebasm, path, file_names, file_name):
9199
if file_name.endswith('.inc.6502'):
@@ -98,18 +106,43 @@ def run_test(beebasm, path, file_names, file_name):
98106

99107
failure_test = file_name.endswith('.fail.6502')
100108
gold_ssd = replace_extension(file_name, '.gold.ssd')
109+
gold_txt = replace_extension(file_name, '.gold.txt')
101110
ssd_name = None
111+
gold_capture = None
102112
if gold_ssd in file_names:
103113
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)
104133

105-
result = execute_test(beebasm_args(beebasm, file_name, ssd_name))
106134
if failure_test and result:
107135
raise TestFailure('Failure test succeeded: ' + full_name)
108136
elif not failure_test and not result:
109137
raise TestFailure('Success test failed: ' + full_name)
110138

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)
113146

114147
def scan_directory(beebasm):
115148
for (path, directory_names, file_names) in os.walk('.', topdown = True):

0 commit comments

Comments
 (0)