-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestMachine.py
More file actions
72 lines (64 loc) · 2.59 KB
/
Copy pathtestMachine.py
File metadata and controls
72 lines (64 loc) · 2.59 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
import subprocess
import codecs
exe_path = "./cmake-build-debug/BUAA_Compiler.exe"
# test_file_path = "D:\\Chaos\\Program\\C++\\BUAA_Compiler\\cmake-build-debug\\testfiles\\";
test_file_path = "D:\\Chaos\\课程\编译原理\\编译原理测试程序\\testfiles\\"
level = "A"
file_num = {'C': 29, 'B': 27, 'A': 26}
test_file_num = 30
_test_file_path = "./testfile.txt"
_output_file_path = "./pcoderesult.txt"
for i in range(1, file_num[level] + 1):
if level == 'C' and (i == 15 or i == 27 or i == 28):
continue
test_file_name = test_file_path + level + "\\testfile" + str(i) + ".txt"
input_file_name = test_file_path + level + "\\input" + str(i) + ".txt"
output_file_name = test_file_path + level + "\\output" + str(i) + ".txt"
_test_file = open(_test_file_path, "w")
test_file = open(test_file_name, "r")
input_file = open(input_file_name, "r")
print("---------------------------------------")
print("testing: " + str(i))
lines = test_file.readlines()
# try:
#
# except UnicodeDecodeError:
# test_file.close()
# test_file = codecs.open(test_file_name, "r", 'utf-8')
_test_file.writelines(lines)
_test_file.close()
test_file.close()
subp = subprocess.Popen(exe_path, stdin=input_file)
subp.wait(5)
input_file.close()
output_file = open(output_file_name, "r")
_output_file = open(_output_file_path, "r")
std_output = output_file.readlines()
m_output = _output_file.readlines()
isError = False
for j in range(0, len(std_output)):
l1 = std_output[j]
if len(m_output) <= j:
print("$$$$$$$$$$$$$$$ERROR$$$$$$$$$$$$$$$$$$$$\n testfile: " + str(i) + ", in line " + str(j))
print("your output is less than std_output, only " + str(j) + ' lines')
print("std output: ")
print(std_output)
print("your output: ")
print(m_output)
print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
isError = True
break
l2 = m_output[j]
# 可能出现标准输出的最后一行少一个\n
if l1 != l2 and not l2.startswith(l1):
print("$$$$$$$$$$$$$$$ERROR$$$$$$$$$$$$$$$$$$$$\n testfile: " + str(i) + ", in line " + str(j))
print("std : " + l1)
print("your: " + l2)
print("std len: " + str(len(l1)) + ", your len: " + str(len(l2)))
print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
isError = True
break
if isError is not True:
print("AC: testfile" + str(i))
output_file.close()
_output_file.close()