From 09c3317bd89fdee914eeb6f977f04a6acb000880 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 15 Jun 2018 16:29:42 +0200 Subject: Correctly choose python version for scripts requiring python2. --- scripts/isolate_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/isolate_tests.py') diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 5bf577d3..82dff1e0 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # # This script reads C++ or RST source files and writes all # multi-line strings into individual files. -- cgit v1.2.3 From 1ebeb7e588a95a7ef57937d26752e0fbad606d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20R=C3=A9=20Medina?= Date: Wed, 4 Jul 2018 21:20:17 -0300 Subject: Change isolate_tests to support single files as an input On the documentation the examples for the usage of isolate_tests.py are shown with single files, and it's currently not working. It only works for folders or wildcards that return more than one file, since that's how os.walk works within a loop for that cases. Proposed an simple and easy fix. I extracted the core functionality for extracting tests from files, and made another function called `extract_and_write` If the program receives a single file the function `extract_and_write` is called once, it even works for `docs` when specified. If the program receives a path or a wildcard, works as used to. --- scripts/isolate_tests.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'scripts/isolate_tests.py') diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 82dff1e0..352a2fde 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -10,7 +10,7 @@ import sys import re import os import hashlib -from os.path import join +from os.path import join, isfile def extract_test_cases(path): lines = open(path, 'rb').read().splitlines() @@ -77,24 +77,31 @@ def write_cases(tests): for test in tests: open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test) + +def extract_and_write(f, path): + if docs: + cases = extract_docs_cases(path) + else: + if f.endswith(".sol"): + cases = [open(path, "r").read()] + else: + cases = extract_test_cases(path) + write_cases(cases) + if __name__ == '__main__': path = sys.argv[1] docs = False if len(sys.argv) > 2 and sys.argv[2] == 'docs': docs = True - for root, subdirs, files in os.walk(path): - if '_build' in subdirs: - subdirs.remove('_build') - if 'compilationTests' in subdirs: - subdirs.remove('compilationTests') - for f in files: - path = join(root, f) - if docs: - cases = extract_docs_cases(path) - else: - if f.endswith(".sol"): - cases = [open(path, "r").read()] - else: - cases = extract_test_cases(path) - write_cases(cases) + if isfile(path): + extract_and_write(path, path) + else: + for root, subdirs, files in os.walk(path): + if '_build' in subdirs: + subdirs.remove('_build') + if 'compilationTests' in subdirs: + subdirs.remove('compilationTests') + for f in files: + path = join(root, f) + extract_and_write(f, path) -- cgit v1.2.3 From 5640eba3827c56d1865f8643505714c4afaff1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20R=C3=A9=20Medina?= Date: Wed, 4 Jul 2018 21:31:08 -0300 Subject: Update isolate_tests to use simple quotes consistently. The previous code had double quotes and the project uses simple quotes. --- scripts/isolate_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/isolate_tests.py') diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 352a2fde..1f913504 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -82,8 +82,8 @@ def extract_and_write(f, path): if docs: cases = extract_docs_cases(path) else: - if f.endswith(".sol"): - cases = [open(path, "r").read()] + if f.endswith('.sol'): + cases = [open(path, 'r').read()] else: cases = extract_test_cases(path) write_cases(cases) -- cgit v1.2.3 From f873389c6227d41dbba9ba4c23ed055f286ecb71 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 9 Aug 2018 14:58:28 +0200 Subject: Test that documentation does not contain any warnings. --- scripts/isolate_tests.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'scripts/isolate_tests.py') diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 1f913504..57fc7ff0 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -56,20 +56,10 @@ def extract_docs_cases(path): else: tests[-1] += l + '\n' else: - m = re.search(r'^ // This will not compile', l) + m = re.search(r'^ pragma solidity .*[0-9]+\.[0-9]+\.[0-9]+;$', l) if m: - ignore = True - - if ignore: - # Abort if indentation is missing - m = re.search(r'^[^ ]+', l) - if m: - ignore = False - else: - m = re.search(r'^ pragma solidity .*[0-9]+\.[0-9]+\.[0-9]+;$', l) - if m: - inside = True - tests += [l] + inside = True + tests += [l] return tests -- cgit v1.2.3 From 6a5a187d83d97764fc6f77e392cdb2b9d8d6bb72 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 9 Aug 2018 20:48:41 +0200 Subject: Also extract tests that do not start with a pragma. --- scripts/isolate_tests.py | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'scripts/isolate_tests.py') diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 57fc7ff0..de2a4438 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -35,33 +35,26 @@ def extract_test_cases(path): return tests # Contract sources are indented by 4 spaces. -# Look for `pragma solidity` and abort a line not indented properly. -# If the comment `// This will not compile` is above the pragma, -# the code is skipped. +# Look for `pragma solidity`, `contract`, `library` or `interface` +# and abort a line not indented properly. def extract_docs_cases(path): - # Note: this code works, because splitlines() removes empty new lines - # and thus even if the empty new lines are missing indentation - lines = open(path, 'rb').read().splitlines() - - ignore = False inside = False tests = [] - for l in lines: - if inside: - # Abort if indentation is missing - m = re.search(r'^[^ ]+', l) - if m: - inside = False - else: - tests[-1] += l + '\n' - else: - m = re.search(r'^ pragma solidity .*[0-9]+\.[0-9]+\.[0-9]+;$', l) - if m: - inside = True - tests += [l] - - return tests + # Collect all snippets of indented blocks + for l in open(path, 'rb').read().splitlines(): + if l != '': + if not inside and l.startswith(' '): + # start new test + tests += [''] + inside = l.startswith(' ') + if inside: + tests[-1] += l + '\n' + # Filter all tests that do not contain Solidity + return [ + test for test in tests + if re.search(r'^ [ ]*(pragma solidity|contract |library |interface )', test, re.MULTILINE) + ] def write_cases(tests): for test in tests: -- cgit v1.2.3 From a102f3b783dec236e9a733f5a5338efce3ef8319 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 3 Sep 2018 15:01:15 +0200 Subject: Remove trailing whitespace for all files in the repository. --- scripts/isolate_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/isolate_tests.py') diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index de2a4438..06e9f9ea 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -79,7 +79,7 @@ if __name__ == '__main__': if isfile(path): extract_and_write(path, path) - else: + else: for root, subdirs, files in os.walk(path): if '_build' in subdirs: subdirs.remove('_build') -- cgit v1.2.3 From 69673f5a4b9ceb7eb71fc338078ce17145b58685 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 6 Sep 2018 11:37:44 +0200 Subject: Include origin filename in the filenames generated by isolate_tests.py. --- scripts/isolate_tests.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'scripts/isolate_tests.py') diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 06e9f9ea..8a9aa0a7 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -56,9 +56,10 @@ def extract_docs_cases(path): if re.search(r'^ [ ]*(pragma solidity|contract |library |interface )', test, re.MULTILINE) ] -def write_cases(tests): +def write_cases(f, tests): + cleaned_filename = f.replace(".","_").replace("-","_").replace(" ","_").lower() for test in tests: - open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test) + open('test_%s_%s.sol' % (hashlib.sha256(test).hexdigest(), cleaned_filename), 'wb').write(test) def extract_and_write(f, path): @@ -69,7 +70,7 @@ def extract_and_write(f, path): cases = [open(path, 'r').read()] else: cases = extract_test_cases(path) - write_cases(cases) + write_cases(f, cases) if __name__ == '__main__': path = sys.argv[1] -- cgit v1.2.3