-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.py
More file actions
executable file
·108 lines (95 loc) · 3.66 KB
/
Copy pathcheck.py
File metadata and controls
executable file
·108 lines (95 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
import re
import sys
import subprocess
def test(binname, filename):
beacon_list = []
exit_beacon = 0
line_number = 1
for line in open(filename, 'r'):
if line_number == 1:
match = re.search("// run", line)
if match:
exit_beacon_string = match.string[match.start():][len("// run "):-1]
exit_beacon = int(exit_beacon_string)
match = re.search("//~error:", line)
if match:
comment_string = match.string[match.start():]
# strip '//~error: ' and '\n'
just_beacon = comment_string[len("//~error: "):-1]
beacon_list.append((line_number, just_beacon))
line_number = line_number + 1
# Run compiler and capture output
error_list = []
r = subprocess.run([binname, filename], stdout=None, stderr=subprocess.PIPE, text=True)
if r.returncode != 0 and r.returncode != 1:
print('\033[0;31mabort\033[0m {} ({})'.format(filename, r.returncode))
return
for line in r.stderr.splitlines():
match = re.search("error:", line)
splits = line.split(':')
if not match or len(splits) < 5:
print('\033[0;31mcodegen\033[0m {} ({})'.format(filename, line))
return
line_number = int(splits[1])
# strip 'error: '
error_string = match.string[match.start():][len("error: "):]
error_list.append((line_number, error_string))
success = True
i = 0
j = 0
while i < len(error_list) and j < len(beacon_list):
this_error = error_list[i]
this_beacon = beacon_list[j]
if this_error[0] == this_beacon[0]:
if this_error[1] != this_beacon[1]:
success = False
print('line {}: expected: {}'.format(this_beacon[0], this_beacon[1]))
print('line {}: got: {}'.format(this_error[0], this_error[1]))
i = i + 1
j = j + 1
elif this_error[0] < this_beacon[0]:
success = False
print('line {}: got: {}'.format(this_error[0], this_error[1]))
i = i + 1
else:
success = False
print('line {}: expected: {}'.format(this_beacon[0], this_beacon[1]))
j = j + 1
# handle any remaining
while i < len(error_list):
success = False
this_error = error_list[i]
print('line {}: got: {}'.format(this_error[0], this_error[1]))
i = i + 1
while j < len(beacon_list):
success = False
this_beacon = beacon_list[j]
print('line {}: expected: {}'.format(this_beacon[0], this_beacon[1]))
j = j + 1
if not success:
print('\033[0;31msema\033[0m {}'.format(filename))
return
r = subprocess.run('./out')
if exit_beacon != r.returncode:
print('\033[0;31mrun\033[0m {} (expected {}, got {})'
.format(filename, exit_beacon, r.returncode))
return
print('\033[0;32mpass\033[0m {}'.format(filename))
if __name__ == "__main__":
if len(sys.argv) > 1:
test('build/ruse', sys.argv[1])
sys.exit(0)
test('build/ruse', 'test/simple.ruse')
test('build/ruse', 'test/return.ruse')
test('build/ruse', 'test/if.ruse')
test('build/ruse', 'test/typecheck.ruse')
test('build/ruse', 'test/array.ruse')
test('build/ruse', 'test/struct.ruse')
test('build/ruse', 'test/struct2.ruse')
test('build/ruse', 'test/func.ruse')
test('build/ruse', 'test/string.ruse')
test('build/ruse', 'test/ffi.ruse')
test('build/ruse', 'test/codegen.ruse')
test('build/ruse', 'test/codegen_struct.ruse')
test('build/ruse', 'test/ref.ruse')