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
|
2016-12-06 22:21:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def extract_cases(path):
|
|
|
|
lines = open(path).read().splitlines()
|
|
|
|
|
|
|
|
inside = False
|
|
|
|
tests = []
|
|
|
|
|
|
|
|
for l in lines:
|
|
|
|
if inside:
|
|
|
|
if l.strip().endswith(')";'):
|
|
|
|
inside = False
|
|
|
|
else:
|
|
|
|
tests[-1] += l + '\n'
|
|
|
|
else:
|
|
|
|
if l.strip().endswith('R"('):
|
|
|
|
inside = True
|
|
|
|
tests += ['']
|
|
|
|
|
|
|
|
return tests
|
|
|
|
|
|
|
|
|
|
|
|
def write_cases(tests, start=0):
|
|
|
|
for i, test in enumerate(tests, start=start):
|
|
|
|
open('test%d.sol' % i, 'w').write(test)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
files = sys.argv[1:]
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
for path in files:
|
|
|
|
cases = extract_cases(path)
|
|
|
|
write_cases(cases, start=i)
|
|
|
|
i += len(cases)
|