diff options
Diffstat (limited to 'scripts/isolate_tests.py')
-rwxr-xr-x | scripts/isolate_tests.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py new file mode 100755 index 00000000..a1d1c75c --- /dev/null +++ b/scripts/isolate_tests.py @@ -0,0 +1,48 @@ +#!/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 +import re +import os +import hashlib +from os.path import join + +def extract_cases(path): + lines = open(path, 'rb').read().splitlines() + + inside = False + delimiter = '' + tests = [] + + for l in lines: + if inside: + if l.strip().endswith(')' + delimiter + '";'): + inside = False + else: + tests[-1] += l + '\n' + else: + m = re.search(r'R"([^(]*)\($', l.strip()) + if m: + inside = True + delimiter = m.group(1) + tests += [''] + + return tests + + +def write_cases(tests): + for test in tests: + open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test) + +if __name__ == '__main__': + path = sys.argv[1] + + for root, dir, files in os.walk(path): + for f in files: + cases = extract_cases(join(root, f)) + write_cases(cases) |