mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1489 from federicobond/isolate-tests
Cleanup and fix scripts/isolate_tests.py
This commit is contained in:
commit
740294f65a
@ -1,24 +0,0 @@
|
|||||||
#!/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
|
|
||||||
# into files for e.g. fuzz testing as
|
|
||||||
# scripts/isolateTests.py tests/libsolidity/SolidityEndToEndTest.cpp
|
|
||||||
|
|
||||||
import sys
|
|
||||||
lines = sys.stdin.read().split('\n')
|
|
||||||
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 += ['']
|
|
||||||
for i in range(len(tests)):
|
|
||||||
open('test%d.sol' % i, 'w').write(tests[i])
|
|
44
scripts/isolate_tests.py
Executable file
44
scripts/isolate_tests.py
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
#!/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
|
||||||
|
# into files for e.g. fuzz testing as
|
||||||
|
# scripts/isolate_tests.py test/libsolidity/*
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
Loading…
Reference in New Issue
Block a user