-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.in
More file actions
58 lines (41 loc) · 1.36 KB
/
test.in
File metadata and controls
58 lines (41 loc) · 1.36 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
#!/usr/bin/env python3
import argparse
import filecmp
import glob
import os
import subprocess
import sys
SRC = '@PROJECT_SOURCE_DIR@'
BIN = '@PROJECT_BINARY_DIR@'
def input_to_expect(input):
return input[:-3] + '.ans'
def input_to_output(input):
return input[:-3] + '.out'
def run_test(prog, input):
output = input_to_output(input)
expect = input_to_expect(input)
with open(input, 'r') as stdin, open(output, 'w') as stdout:
subprocess.call(prog, stdin=stdin, stdout=stdout)
res = filecmp.cmp(output, expect)
if not res:
print('input {} fails'.format(input), file=sys.stderr)
return res
def main():
parser = argparse.ArgumentParser(description='Test runner')
parser.add_argument('case', nargs=1, help='Test case')
parser.add_argument('--skip', action='store_true', help='Do not report error')
args = parser.parse_args()
pass_ = True
prog = os.path.join(BIN, 'bin', args.case[0])
case = args.case[0].split('-')[1]
input = os.path.join(SRC, 'data', '{}.in'.format(case))
res = run_test(prog, input)
if not res:
pass_ = False
for input in glob.iglob(os.path.join(SRC, 'data', '{}-*.in'.format(case))):
res = run_test(prog, input)
if not res:
pass_ = False
return 0 if pass_ or args.skip else -1
if __name__ == '__main__':
sys.exit(main())