mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Also extract tests that do not start with a pragma.
This commit is contained in:
parent
6cf299bec6
commit
6a5a187d83
@ -35,33 +35,26 @@ def extract_test_cases(path):
|
|||||||
return tests
|
return tests
|
||||||
|
|
||||||
# Contract sources are indented by 4 spaces.
|
# Contract sources are indented by 4 spaces.
|
||||||
# Look for `pragma solidity` and abort a line not indented properly.
|
# Look for `pragma solidity`, `contract`, `library` or `interface`
|
||||||
# If the comment `// This will not compile` is above the pragma,
|
# and abort a line not indented properly.
|
||||||
# the code is skipped.
|
|
||||||
def extract_docs_cases(path):
|
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
|
inside = False
|
||||||
tests = []
|
tests = []
|
||||||
|
|
||||||
for l in lines:
|
# 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:
|
if inside:
|
||||||
# Abort if indentation is missing
|
|
||||||
m = re.search(r'^[^ ]+', l)
|
|
||||||
if m:
|
|
||||||
inside = False
|
|
||||||
else:
|
|
||||||
tests[-1] += l + '\n'
|
tests[-1] += l + '\n'
|
||||||
else:
|
# Filter all tests that do not contain Solidity
|
||||||
m = re.search(r'^ pragma solidity .*[0-9]+\.[0-9]+\.[0-9]+;$', l)
|
return [
|
||||||
if m:
|
test for test in tests
|
||||||
inside = True
|
if re.search(r'^ [ ]*(pragma solidity|contract |library |interface )', test, re.MULTILINE)
|
||||||
tests += [l]
|
]
|
||||||
|
|
||||||
return tests
|
|
||||||
|
|
||||||
def write_cases(tests):
|
def write_cases(tests):
|
||||||
for test in tests:
|
for test in tests:
|
||||||
|
@ -181,9 +181,17 @@ TMPDIR=$(mktemp -d)
|
|||||||
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/ docs
|
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/ docs
|
||||||
for f in *.sol
|
for f in *.sol
|
||||||
do
|
do
|
||||||
|
# The contributors guide uses syntax tests, but we cannot
|
||||||
|
# really handle them here.
|
||||||
|
if grep -E 'DeclarationError:|// ----' "$f" >/dev/null
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
echo "$f"
|
echo "$f"
|
||||||
opts=''
|
opts=''
|
||||||
if grep "This will not compile" "$f" >/dev/null
|
# We expect errors if explicitly stated, or if imports
|
||||||
|
# are used (in the style guide)
|
||||||
|
if grep -E "This will not compile|import \"" "$f" >/dev/null
|
||||||
then
|
then
|
||||||
opts="-e"
|
opts="-e"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user