2016-09-30 11:09:45 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# This script reads C++ source files and writes all
|
|
|
|
# multi-line strings into individual files.
|
|
|
|
# This can be used to extract the Solidity test cases
|
2016-10-10 20:04:11 +00:00
|
|
|
# into files for e.g. fuzz testing as
|
2016-12-06 22:21:38 +00:00
|
|
|
# scripts/isolate_tests.py test/libsolidity/*
|
2016-09-30 11:09:45 +00:00
|
|
|
|
|
|
|
import sys
|
2017-03-15 11:07:59 +00:00
|
|
|
import re
|
2017-03-22 19:19:20 +00:00
|
|
|
import os
|
|
|
|
import hashlib
|
|
|
|
from os.path import join
|
2016-12-06 22:21:38 +00:00
|
|
|
|
|
|
|
def extract_cases(path):
|
2017-03-22 19:19:20 +00:00
|
|
|
lines = open(path, 'rb').read().splitlines()
|
2016-12-06 22:21:38 +00:00
|
|
|
|
|
|
|
inside = False
|
2017-03-15 11:07:59 +00:00
|
|
|
delimiter = ''
|
2016-12-06 22:21:38 +00:00
|
|
|
tests = []
|
|
|
|
|
|
|
|
for l in lines:
|
|
|
|
if inside:
|
2017-03-15 11:07:59 +00:00
|
|
|
if l.strip().endswith(')' + delimiter + '";'):
|
2016-12-06 22:21:38 +00:00
|
|
|
inside = False
|
|
|
|
else:
|
|
|
|
tests[-1] += l + '\n'
|
|
|
|
else:
|
2017-03-15 11:07:59 +00:00
|
|
|
m = re.search(r'R"([^(]*)\($', l.strip())
|
|
|
|
if m:
|
2016-12-06 22:21:38 +00:00
|
|
|
inside = True
|
2017-03-15 11:07:59 +00:00
|
|
|
delimiter = m.group(1)
|
2016-12-06 22:21:38 +00:00
|
|
|
tests += ['']
|
|
|
|
|
|
|
|
return tests
|
|
|
|
|
|
|
|
|
2017-03-22 19:19:20 +00:00
|
|
|
def write_cases(tests):
|
|
|
|
for test in tests:
|
|
|
|
open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test)
|
2016-12-06 22:21:38 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-03-22 19:19:20 +00:00
|
|
|
path = sys.argv[1]
|
2016-12-06 22:21:38 +00:00
|
|
|
|
2017-03-22 19:19:20 +00:00
|
|
|
for root, dir, files in os.walk(path):
|
|
|
|
for f in files:
|
|
|
|
cases = extract_cases(join(root, f))
|
|
|
|
write_cases(cases)
|