Cleanup and fix scripts/isolate_tests.py

This commit is contained in:
Federico Bond 2016-12-06 19:21:38 -03:00
parent 7a46e15efd
commit 72f9a4a73e

View File

@ -4,12 +4,17 @@
# multi-line strings into individual files. # multi-line strings into individual files.
# This can be used to extract the Solidity test cases # This can be used to extract the Solidity test cases
# into files for e.g. fuzz testing as # into files for e.g. fuzz testing as
# scripts/isolateTests.py tests/libsolidity/SolidityEndToEndTest.cpp # scripts/isolate_tests.py test/libsolidity/*
import sys import sys
lines = sys.stdin.read().split('\n')
def extract_cases(path):
lines = open(path).read().splitlines()
inside = False inside = False
tests = [] tests = []
for l in lines: for l in lines:
if inside: if inside:
if l.strip().endswith(')";'): if l.strip().endswith(')";'):
@ -20,5 +25,20 @@ for l in lines:
if l.strip().endswith('R"('): if l.strip().endswith('R"('):
inside = True inside = True
tests += [''] tests += ['']
for i in range(len(tests)):
open('test%d.sol' % i, 'w').write(tests[i]) 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)