Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

"Errors should never pass silently" #27

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/testasciidoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ Optional list of command-line option tuples.
% attributes
Optional dictionary of attribute values.

% messages
Optional list of expected messages

---------------------------------------------------------------------

Example test spec:
Expand Down Expand Up @@ -209,6 +212,10 @@ configuration file that comes with AsciiDoc.
equivalent to a `(name,None)` tuple.
- The 'attributes' directive data specifies a Python dictionary
containing AsciiDoc attributes to be passed to AsciiDoc.
- The 'messages' directive is a list of messages expected on the
screen. The format is `WARNING: something goes wrong` where
filename and line number are omitted. Unexpected messages will
be reported as warnings in the test report.

globals directive
~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions docbook45.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ latexmath-style=template="latexmathblock",subs=()
{title#}</figure>
{title%}</informalfigure>

[unfloat-blockmacro]
# nothing to see here

[indexterm-inlinemacro]
# Index term.
# Generate separate index entries for primary, secondary and tertiary
Expand Down
2 changes: 1 addition & 1 deletion filters/latex/latex2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def main():
if dpi and not dpi.isdigit():
usage('invalid DPI')
sys.exit(1)
if not imgfmt in {'png', 'svg'}:
if imgfmt not in ('png', 'svg'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it restores compatibility with Python 2.6

usage('Invalid image format. Valid values are "png" or "svg".')
sys.exit(1)
if outfile is None:
Expand Down
9 changes: 9 additions & 0 deletions tests/testasciidoc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Test cases
% source
data/testcases.txt

% messages
WARNING: nested inline passthrough

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Filters

Expand All @@ -27,6 +30,9 @@ Old tables
% source
data/oldtables.txt

% messages
DEPRECATED: old tables syntax
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message is perfectly valid: we test a deprecated feature


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Source highlighter

Expand Down Expand Up @@ -776,6 +782,9 @@ UTF-8 BOM test
% source
data/utf8-bom-test.txt

% messages
WARNING: maximum include depth exceeded
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message is valid, the [depth=1] is explicitly set in the test case:
https://github.com/asciidoc/asciidoc/blob/master/tests/data/utf8-bom-test.txt#L7


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Deprecated quote attributes

Expand Down
30 changes: 24 additions & 6 deletions tests/testasciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(self):
self.options = []
self.attributes = {'asciidoc-version': 'test'}
self.backends = BACKENDS
self.messages = []
self.datadir = None # Where output files are stored.
self.disabled = False

Expand Down Expand Up @@ -161,6 +162,10 @@ def parse(self, lines, confdir, datadir):
self.backends = eval(' '.join(data))
elif directive == 'name':
self.name = data[0].strip()
elif directive == 'messages':
for msg in data:
(level, sep, text) = msg.partition(':')
self.messages.append((level, text))
else:
raise (ValueError, 'illegal directive: %s' % l[0])
if not self.title:
Expand Down Expand Up @@ -206,13 +211,18 @@ def generate_expected(self, backend):
infile = self.source
outfile = StringIO.StringIO()
asciidoc.execute(infile, outfile, backend)
return outfile.getvalue().splitlines()
messages = []
for msg in asciidoc.messages:
(level, fname, line, text) = msg.split(':', 3)
if (level, text) not in self.messages:
messages.append(msg)
return outfile.getvalue().splitlines(), messages

def update_expected(self, backend):
"""
Generate and write backend data.
"""
lines = self.generate_expected(backend)
lines, __ = self.generate_expected(backend)
if not os.path.isdir(self.datadir):
print('CREATING: %s' % self.datadir)
os.mkdir(self.datadir)
Expand Down Expand Up @@ -245,7 +255,7 @@ def run(self, backend=None):
else:
backends = [backend]
result = True # Assume success.
self.passed = self.failed = self.skipped = 0
self.passed = self.failed = self.warned = self.skipped = 0
print('%d: %s' % (self.number, self.title))
if self.source and os.path.isfile(self.source):
print('SOURCE: asciidoc: %s' % self.source)
Expand All @@ -254,8 +264,10 @@ def run(self, backend=None):
if not self.is_missing(backend):
expected = self.get_expected(backend)
strip_end(expected)
got = self.generate_expected(backend)
got, messages = self.generate_expected(backend)
strip_end(got)
for msg in messages:
print(' %s' % msg)
lines = []
for line in difflib.unified_diff(got, expected, n=0):
lines.append(line)
Expand All @@ -269,6 +281,9 @@ def run(self, backend=None):
for line in lines:
message(line)
message()
elif messages:
self.warned += 1
print('WARNED: %s: %s' % (backend, fromfile))
else:
self.passed += 1
print('PASSED: %s: %s' % (backend, fromfile))
Expand Down Expand Up @@ -328,17 +343,20 @@ def run(self, number=None, backend=None):
Run all tests.
If number is specified run test number (1..).
"""
self.passed = self.failed = self.skipped = 0
self.passed = self.failed = self.warned = self.skipped = 0
for test in self.tests:
if (not test.disabled or number) and (not number or number == test.number) and (not backend or backend in test.backends):
test.run(backend)
self.passed += test.passed
self.failed += test.failed
self.warned += test.warned
self.skipped += test.skipped
if self.passed > 0:
print('TOTAL PASSED: %s' % self.passed)
if self.failed > 0:
print('TOTAL FAILED: %s' % self.failed)
if self.warned > 0:
print('TOTAL WARNED: %s' % self.warned)
if self.skipped > 0:
print('TOTAL SKIPPED: %s' % self.skipped)

Expand Down Expand Up @@ -434,7 +452,7 @@ def usage(msg=None):
sys.exit(1)
if cmd == 'run':
tests.run(number, backend)
if tests.failed:
if tests.failed or tests.warned or tests.skipped:
sys.exit(1)
elif cmd == 'update':
tests.update(number, backend, force=force)
Expand Down