diff options
author | chriseth <chris@ethereum.org> | 2018-03-16 07:46:57 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-03-16 07:47:32 +0800 |
commit | 658955579050c51cc9a714adc5986212796f8196 (patch) | |
tree | c4c8fe4a5f0c992e0f8686c3c3f814f2f92f6a47 /scripts | |
parent | 9e1095608d265ac941afbf1e4ed4c79d63a15926 (diff) | |
download | dexon-solidity-658955579050c51cc9a714adc5986212796f8196.tar.gz dexon-solidity-658955579050c51cc9a714adc5986212796f8196.tar.zst dexon-solidity-658955579050c51cc9a714adc5986212796f8196.zip |
Test extraction tool.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/extract_test_cases.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/extract_test_cases.py b/scripts/extract_test_cases.py new file mode 100755 index 00000000..07ef9a96 --- /dev/null +++ b/scripts/extract_test_cases.py @@ -0,0 +1,49 @@ +#!/usr/bin/python +# +# This script reads C++ or RST 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_test_cases(path): + lines = open(path, 'rb').read().splitlines() + + inside = False + delimiter = '' + test = '' + + ctr = 1 + test_name = '' + + for l in lines: + if inside: + if l.strip().endswith(')' + delimiter + '";'): + open('%03d_%s.sol' % (ctr, test_name), 'wb').write(test) + ctr += 1 + inside = False + test = '' + else: + l = re.sub('^\t\t', '', l) + l = l.replace('\t', ' ') + test += l + '\n' + else: + m = re.search(r'BOOST_AUTO_TEST_CASE\(([^(]*)\)', l.strip()) + if m: + test_name = m.group(1) + m = re.search(r'R"([^(]*)\($', l.strip()) + if m: + inside = True + delimiter = m.group(1) + + +if __name__ == '__main__': + path = sys.argv[1] + extract_test_cases(path) + |