summaryrefslogtreecommitdiff
path: root/testasciidoc.html
blob: 504fa211e394df89a12722f9b669a95fd26ea25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 10.0.0a2" />
<title>AsciiDoc Tests</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css" />
<link rel="stylesheet" href="./layout2.css" type="text/css" />
<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install(1);
/*]]>*/
</script>
</head>
<body style="max-width:70em">
<div id="layout-menu-box">
<div id="layout-menu">
  <div>&#187;<a href="index.html">Home</a></div>
  <div>&#187;<a href="userguide.html">User&nbsp;Guide</a></div>
  <div>&#187;<a href="INSTALL.html">Installation</a></div>
  <div>&#187;<a href="faq.html">FAQ</a></div>
  <div>&#187;<a href="manpage.html">asciidoc(1)</a></div>
  <div>&#187;<a href="a2x.1.html">a2x(1)</a></div>
  <div>&#187;<a href="asciidocapi.html">API</a></div>
  <div>&#187;<a href="plugins.html">Plugins</a></div>
  <div>&#187;<a href="http://powerman.name/doc/asciidoc">Cheatsheet</a></div>
  <div>&#187;<a href="testasciidoc.html">Tests</a></div>
  <div>&#187;<a href="CHANGELOG.html">ChangeLog</a></div>
  <div>&#187;<a href="support.html">Support</a></div>
  <div id="page-source">&#187;<a href="testasciidoc.txt">Page&nbsp;Source</a></div>
</div>
</div>
<div id="layout-content-box">
<div id="layout-banner">
  <div id="layout-title">AsciiDoc</div>
  <div id="layout-description">Text based document generation</div>
</div>
<div id="layout-content">
<div id="header">
<h1>AsciiDoc Tests</h1>
<div id="toc">
  <div id="toctitle">Table of Contents</div>
  <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>AsciiDoc includes <em>testasciidoc</em>, a Python script runs a set of
AsciiDoc conformance tests. <em>testasciidoc</em> runs through a list of
AsciiDoc source files, generates backend outputs and then compares
them to expected result files. The whole process is driven by a
configuration file containing a list of user configurable test
specifications.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_rationale">Rationale</h2>
<div class="sectionbody">
<div class="paragraph"><p>When modifying AsciiDoc configuration files or source code it&#8217;s very
easy to introduce regression errors. <em>testasciidoc</em> is a tool for
writing many and varied test cases that can be run after changes have
been made in order to verify that existing behavior has not been
broken.</p></div>
<div class="paragraph"><p>The <em>testasciidoc</em> <em>update</em> command automates the (re)generation of
expected test result data.  Result data regeneration has to be
performed after changes to test case source files or after legitimate
changes to the AsciiDoc output formats&#8201;&#8212;&#8201;doing this manually is
prohibitively tedious.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_running_testasciidoc">Running testasciidoc</h2>
<div class="sectionbody">
<div class="paragraph"><p>The <code>testasciidoc.py</code> script and the default <code>testasciidoc.conf</code>
configuration file are located in the AsciiDoc distribution <code>tests</code>
directory.</p></div>
<div class="paragraph"><p>To view the command usage run:</p></div>
<div class="listingblock">
<div class="content">
<pre><code>$ python3 tests/testasciidoc.py
usage: testasciidoc.py [-h] [-v] [-f CONF_FILE] command ...

Run AsciiDoc conformance tests specified in configuration FILE.

positional arguments:
  command
    list                List tests
    run                 Execute tests
    update              Regenerate and update test data

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -f CONF_FILE, --conf-file CONF_FILE
                        Use configuration file CONF_FILE (default
                        configuration file is testasciidoc.conf in
                        testasciidoc.py directory)</code></pre>
</div></div>
<div class="paragraph"><p>To view the list of tests in the default <code>testasciidoc.conf</code>
configuration file run the <em>list</em> command:</p></div>
<div class="listingblock">
<div class="content">
<pre><code>$ python tests/testasciidoc.py list
1: Test cases
2: Tables
3: Source highlighter
4: Example article
5: Example book
6: Example multi-part book
7: !User Guide</code></pre>
</div></div>
<div class="paragraph"><p>The <em>!</em> prefix signals that a test is currently disabled.</p></div>
<div class="paragraph"><p>Before running the tests you will need to regenerate the expected
outputs by running the <em>update</em> command:</p></div>
<div class="listingblock">
<div class="content">
<pre><code>$ python tests/testasciidoc.py update
WRITING: tests/data/testcases-html4.html
WRITING: tests/data/testcases-xhtml11.html
WRITING: tests/data/testcases-docbook.xml
 :
WRITING: tests/data/book-multi-docbook.xml</code></pre>
</div></div>
<div class="paragraph"><p>Now you can run the tests:</p></div>
<div class="listingblock">
<div class="content">
<pre><code>$ python tests/testasciidoc.py run
1: Test cases
SOURCE: asciidoc: tests/data/testcases.txt
PASSED: html4: tests/data/testcases-html4.html
PASSED: xhtml11: tests/data/testcases-xhtml11.html
PASSED: docbook: tests/data/testcases-docbook.xml
 :
6: Example multi-part book
SOURCE: asciidoc: doc/book-multi.txt
PASSED: html4: tests/data/book-multi-html4.html
PASSED: xhtml11: tests/data/book-multi-xhtml11.html
PASSED: docbook: tests/data/book-multi-docbook.xml

TOTAL PASSED:  18</code></pre>
</div></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">
<div class="ulist"><ul>
<li>
<p>
<em>testasciidoc</em> requires AsciiDoc is located in your environment
  search path, if not you&#8217;ll need to set the <code>ASCIIDOC_PY</code> environment
  variable to point to <code>asciidoc.py</code>.
</p>
</li>
<li>
<p>
If you don&#8217;t have GNU source-highlight installed you should disable
  the <em>Tables</em> and <em>Source highlighter</em> tests in the
  <code>tests/testasciidoc.conf</code> configuration file.
</p>
</li>
<li>
<p>
The <code>run</code> and <code>update</code> commands both take optional <code>--number</code> and
  <code>--backend</code> options to specify a test case number and/or backend to
  test against. Use <code>python3 tests/testasciidoc.py run --help</code> for more
  information.
</p>
</li>
</ul></div>
</td>
</tr></table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_testasciidoc_commands">testasciidoc commands</h2>
<div class="sectionbody">
<div class="dlist"><dl>
<dt class="hdlist1">
<em>list</em>
</dt>
<dd>
<p>
  List test numbers and titles.  A <em>!</em> title prefix signals that a
  test is currently disabled.
</p>
</dd>
<dt class="hdlist1">
<em>run</em>
</dt>
<dd>
<p>
  Read and execute tests from the test configuration file. A test
  specifies AsciiDoc test case source file and command options.  The
  test compares generated outputs to expected outputs and any
  differences displayed as a diff.  You can run selected tests by
  specifying the test number and/or backend after the <code>run</code> command.
  Examples:
</p>
<div class="literalblock">
<div class="content">
<pre><code>python tests/testasciidoc.py run
python tests/testasciidoc.py run --number 3
python tests/testasciidoc.py run --backend html4
python tests/testasciidoc.py run --number 3 --backend html4</code></pre>
</div></div>
</dd>
<dt class="hdlist1">
<em>update</em>
</dt>
<dd>
<p>
  Generates and updates missing and out of date test output data
  files, this eliminates one of the most time consuming aspect of test
  management.  Use the <code>--force</code> option to force updates.
  Examples:
</p>
<div class="literalblock">
<div class="content">
<pre><code>python tests/testasciidoc.py update
python tests/testasciidoc.py update --number 4 --force</code></pre>
</div></div>
</dd>
</dl></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">You can run or update disabled tests by explicitly specifying
the test number.</td>
</tr></table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_test_configuration_file">Test configuration file</h2>
<div class="sectionbody">
<div class="paragraph"><p>The tests configuration file format consists of one or more test specs
separated by a line of one or more percent characters. Each test spec
consists of an optional test title and description followed by one or
more optional directives (a directive starts with a percent
character).  A <em>directive</em> consists begins with a line containing a <em>%</em>
character followed by a directive name followed by zero or more lines
of directive data.</p></div>
<div class="sect2">
<h3 id="_test_spec_format">Test spec format</h3>
<div class="listingblock">
<div class="content">
<pre><code>Optional test title
Optional test description...

% name
Optional base output file name. Defaults to base source file name.

% requires
Optional external requirements necessary to run the test, e.g. dot.

% source
AsciiDoc source file name.

% backends
Optional list of backends to be tested(default is all backends).

% options
Optional list of command-line option tuples.

% attributes
Optional dictionary of attribute values.

% artifacts
Optional list of artifacts that get generated from test, and which
will get cleaned up.</code></pre>
</div></div>
<div class="paragraph"><p>Example test spec:</p></div>
<div class="listingblock">
<div class="content">
<pre><code>Example book

% options
['--section-numbers',('--doctype','book')]

% requires
['source-highlight', 'dot']

% attributes
# Exclude date from document footer.
{'docdate':None}

% source
../doc/book.txt</code></pre>
</div></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">Take a look at the default <code>tests/testasciidoc.conf</code>
configuration file that comes with AsciiDoc.</td>
</tr></table>
</div>
<div class="ulist"><ul>
<li>
<p>
Tests can be disabled by prefixing the test title with an
  exclamation <em>!</em> character.
</p>
</li>
<li>
<p>
All relative file names are relative to the configuration file
  directory.
</p>
</li>
<li>
<p>
Multiple tests must by separated by a <code>%</code> separator line (one or
  more percent characters).
</p>
</li>
<li>
<p>
Lines starting with a percent character specify a test <em>directive</em>
  and may be followed by zero or more lines of directive data.
</p>
</li>
<li>
<p>
Directive data lines cannot start with a percent character.
</p>
</li>
<li>
<p>
Lines starting with a <code>#</code> hash character are ignored.
</p>
</li>
<li>
<p>
The <em>source</em> directive data is a single line containing the
  AsciiDoc source file name.
</p>
</li>
<li>
<p>
The <em>options</em> directive data is a Python list of <code>(name,value)</code>
  tuples specifying AsciiDoc command-line options. A string item is
  equivalent to a <code>(name,None)</code> tuple.
</p>
</li>
<li>
<p>
The <em>attributes</em> directive data specifies a Python dictionary
  containing AsciiDoc attributes to be passed to AsciiDoc.
</p>
</li>
<li>
<p>
The <code>requires</code> directive data specifies a Python list of strings
  which correspond to the command line program specified by filters
  in that test.
</p>
</li>
<li>
<p>
The <code>artifacts</code> directive data specifies a Python list of strings
  which corresponds to the list of files (usually image or other such
  files) that get generated when asciidoc is run over the input file.
  The files are deleted after the test is for a given source file is
  run for all backends.
</p>
</li>
</ul></div>
</div>
<div class="sect2">
<h3 id="_globals_directive">globals directive</h3>
<div class="paragraph"><p>An optional <em>globals</em> directive can precede all test specs, the
globals directive data is a Python dictionary containing global
values.  Currently the only global is <em>datadir</em>, the directory
containing expected output files (defaults to configuration file
directory). For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><code>% globals
{'datadir': 'data'}</code></pre>
</div></div>
<div class="paragraph"><p>Expected output test data files are stored in the <em>datadir</em> and are
named after the corresponding AsciiDoc input source file.  For example
if the AsciiDoc file name is <code>article.txt</code> then the corresponding
backend output files will be <code>article-html4.html</code>,
<code>article-xhtml11.html</code>, <code>article-docbook.xml</code> (stored in the <em>datadir</em>
directory).</p></div>
</div>
</div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Version 9.0.5<br />
Last updated 2021-02-01 01:50:57 UTC<br />
AsciiDoc is a trademark of the Eclipse Foundation, Inc.
</div>
<div id="footer-badges">
<a href="https://validator.w3.org/check?uri=referer">
  <img style="border:0;width:88px;height:31px"
    src="https://www.w3.org/Icons/valid-xhtml11-blue"
    alt="Valid XHTML 1.1" height="31" width="88" />
</a>
<a href="https://jigsaw.w3.org/css-validator/">
  <img style="border:0;width:88px;height:31px"
    src="https://jigsaw.w3.org/css-validator/images/vcss-blue"
    alt="Valid CSS!" />
</a>
</div>
</div>
</div>
</div>
</body>
</html>