-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_code_generation.py
More file actions
39 lines (38 loc) · 1.95 KB
/
test_code_generation.py
File metadata and controls
39 lines (38 loc) · 1.95 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
from glob import glob
from compiler import run
from os import mkdir, chdir, path
import subprocess
for file in glob('D:/University/Compiler Design/Project/CodeGeneration_Tests/*/input.txt'):
# for file in glob('/Users/fereshtah/Desktop/term 8/compiler/Project/Compiler-Project/CodeGeneration_Tests/*/input.txt'):
file = file.replace('\\', '/')
folder = file.split('/')[-2]
input_path = 'D:/University/Compiler Design/Project/CodeGeneration_Tests/' + folder
# input_path = '/Users/fereshtah/Desktop/term 8/compiler/Project/Compiler-Project/CodeGeneration_Tests/' + folder
chdir(input_path)
if not path.exists(input_path + '/output'):
mkdir('output')
run(input_path)
if folder[0] == 'T':
chdir(input_path + '/output')
result = subprocess.Popen(['tester_Windows'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = result.communicate()
out = stdout.decode('utf-8')
result = ''
while out.find('\nPRINT') > 0:
line = out[out.find('\nPRINT'):]
line = line[1:line.find('\r')]
out = out[out.find('\nPRINT') + 1:]
result += line + '\n'
result = result.replace(' ', '').replace('\t', '').replace('\n', '').replace('\r', '').lower()
with open(input_path + '/expected.txt', 'r') as f:
expected_result = f.read().replace(' ', '').replace('\t', '').replace('\n', '').replace('\r', '').lower()
else:
with open(input_path + '/semantic_errors.txt', 'r') as f:
expected_result = f.read().replace(' ', '').replace('\t', '').replace('\n', '').replace('\r', '').lower()
with open(input_path + '/output/semantic_errors.txt', 'r') as f:
result = f.read().replace(' ', '').replace('\t', '').replace('\n', '').replace('\r', '').lower()
if expected_result == result:
print('Test ' + folder + ': PASS\n')
else:
print('Test ' + folder + ': FAIL\n')
print(result)