aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/isolate_tests.py
diff options
context:
space:
mode:
authorFederico Bond <federicobond@gmail.com>2016-12-07 06:21:38 +0800
committerFederico Bond <federicobond@gmail.com>2016-12-07 06:21:38 +0800
commit72f9a4a73eba906f349ccb3e577899d0f9add963 (patch)
tree08cdd07bad285e991c1f80715df4572043f8b690 /scripts/isolate_tests.py
parent7a46e15efd13a15788278627fef3394a8fd0e349 (diff)
downloaddexon-solidity-72f9a4a73eba906f349ccb3e577899d0f9add963.tar.gz
dexon-solidity-72f9a4a73eba906f349ccb3e577899d0f9add963.tar.zst
dexon-solidity-72f9a4a73eba906f349ccb3e577899d0f9add963.zip
Cleanup and fix scripts/isolate_tests.py
Diffstat (limited to 'scripts/isolate_tests.py')
-rwxr-xr-xscripts/isolate_tests.py52
1 files changed, 36 insertions, 16 deletions
diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py
index fed779d3..91900aa6 100755
--- a/scripts/isolate_tests.py
+++ b/scripts/isolate_tests.py
@@ -4,21 +4,41 @@
# 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
+# scripts/isolate_tests.py test/libsolidity/*
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])
+
+
+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)