forked from ethereum/solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_test_cases.py
executable file
·45 lines (39 loc) · 1.26 KB
/
extract_test_cases.py
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
#!/usr/bin/env python3
#
# This script reads C++ or RST source files and writes all
# multi-line strings into individual files.
# This can be used to extract the Solidity test cases
# into files for e.g. fuzz testing as
# scripts/isolate_tests.py test/libsolidity/*
import sys
import re
def extract_test_cases(_path):
with open(_path, mode='rb', encoding='utf8') as f:
lines = f.read().splitlines()
inside = False
delimiter = ''
test = ''
ctr = 1
test_name = ''
for l in lines:
if inside:
if l.strip().endswith(')' + delimiter + '";'):
with open(f'{ctr:03d}_{test_name}.sol', mode='wb', encoding='utf8') as f:
f.write(test)
ctr += 1
inside = False
test = ''
else:
l = re.sub('^\t\t', '', l)
l = l.replace('\t', ' ')
test += l + '\n'
else:
m = re.search(r'BOOST_AUTO_TEST_CASE\(([^(]*)\)', l.strip())
if m:
test_name = m.group(1)
m = re.search(r'R"([^(]*)\($', l.strip())
if m:
inside = True
delimiter = m.group(1)
if __name__ == '__main__':
extract_test_cases(sys.argv[1])