-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcreate_error_tests_code.py
More file actions
executable file
·74 lines (60 loc) · 1.93 KB
/
create_error_tests_code.py
File metadata and controls
executable file
·74 lines (60 loc) · 1.93 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
#!/usr/bin/env python
import sys, os, string
def parse_line(line):
idx1 = line.find("(")
name = line[:idx1]
idx2 = line.find("):")
args = line[idx1 + 1 : idx2].split(",")
return (name, args)
def create_code(sig):
t = string.Template("""TEST_F(Errors, $name) {
$name$t r_error$args;
ASSERT_TRUE(string(r_error.what()).size() > 0);
try {
throw r_error;
FAIL();
} catch (std::exception& e) {
ASSERT_TRUE(string(e.what()).size() > 0);
}
}""")
args = ""
name_t = ""
for arg in sig[1]:
arg = arg.strip()
if arg.startswith("int"):
args += (", 0");
elif arg.startswith("double"):
args += (", 0.0")
elif arg.startswith("std::string") or arg.startswith("const std::string"):
args += (", \"foo\"")
elif arg.startswith("std::vector<std::string>"):
args += ", std::vector<string>{\"foo\"}"
elif arg.startswith("std::vector<int>"):
args += ", std::vector<int>{0}"
elif arg.startswith("std::vector<double>"):
args += ", std::vector<double>{0.0}"
elif arg.startswith("T"):
args += ", 1"
name_t = "<int>"
elif len(arg) > 0:
args += ", " + arg
if len(args) > 0:
args = "(" + args[2:] + ")"
return t.substitute(name = sig[0], t=name_t, args=args)
def run(f):
errors = []
with open(f) as f_in:
for line in f_in:
line = line.strip()
if line.startswith("Repast_Error"):
errors.append(parse_line(line))
code = []
for error in errors:
code.append(create_code(error))
for code in code:
print(code)
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: create_error_tests_code.py [path to RepastErrors.h]")
else:
run(sys.argv[1])