doc/loupe-test.txt
author ali <ali@juiblex.co.uk>
Sat Oct 26 18:47:33 2013 +0100 (2013-10-26)
changeset 101 f44c530f80da
parent 19 05d082ebf685
child 105 2d48e8cdda24
permissions -rw-r--r--
Fix bug #24: Accept alternate form of newline
     1                            bookloupe test framework
     2                            ========================
     3 
     4 Running existing testcases
     5 --------------------------
     6 
     7 The test harness (the program that runs a test) is called loupe-test. The
     8 various testcases are stored in multiple text files, typically with a .tst
     9 extension.
    10 
    11 To run a testcase when all of bookloupe, loupe-test and the testcase file are
    12 in the current directory simply do something like:
    13 
    14 % loupe-test missing-space.tst
    15 
    16 from a command prompt. Under MS-Windows, this is called a command window and
    17 the prompt will normally look slightly different, eg.,
    18 
    19 C:\DP> loupe-test missing-space.tst
    20 
    21 To run all the tests in the current directory, do something like this:
    22 
    23 % loupe-test *.tst
    24 
    25 If bookloupe is not in the current directory or you want to run the testsuite
    26 against gutcheck (the program that bookloupe is based on), then you can set an
    27 environment variable (BOOKLOUPE) to point at it. For example, on MS-Windows
    28 you might do:
    29 
    30 C:\DP> set BOOKLOUPE=C:\GUTCHECK\GUTCHECK.EXE
    31 C:\DP> loupe-test *.tst
    32 
    33 Writing your own testcases
    34 --------------------------
    35 
    36 Writing a new testcase is pretty painless. Most testcases follow this simple
    37 pattern:
    38 
    39 		┌──────────────────────────────────────────┐
    40 		│**************** INPUT ****************   │
    41 		│"Look!John, over there!"                  │
    42 		│**************** EXPECTED ****************│
    43 		│                                          │
    44 		│"Look!John, over there!"                  │
    45 		│    Line 1 column 6 - Missing space?      │
    46 		└──────────────────────────────────────────┘
    47 
    48 The sixteen asterisks in this example form what is known as the "flag". This
    49 flag must come before and after all tags (eg., INPUT and EXPECTED). In the
    50 unlikely event that you need sixteen asterisks at the start of a line of text,
    51 then simply choose a different flag and use it throughout the file (flags
    52 can be any sequence of ASCII characters except control codes and space).
    53 
    54 Note that the header that bookloupe and gutcheck normally output is not
    55 included in the expected output. This avoids problems with not knowing
    56 beforehand the name of the file that bookloupe/gutcheck will be asked to
    57 look at (and saves typing!). bookloupe (and gutcheck) prints a blank line
    58 before each warning. These are not part of the header and so do need to
    59 be included.
    60 
    61 To test that bookloupe produces no output, you still need to include
    62 an EXPECTED tag, just with no text following it. If there is no EXPECTED
    63 tag, then loupe-test will consider that no expectation exists and won't
    64 check the output at all.
    65 
    66 Non-ASCII testcases
    67 -------------------
    68 
    69 The testcase definitions (the .tst files) are always written in UTF-8
    70 which is a superset of ASCII. Since gutcheck does not understand UTF-8
    71 this causes a problem when it is desired to include characters that
    72 are not in ASCII in a testcase. To solve this problem it is possible
    73 to specify an encoding to use for the test. It is very important to
    74 undertand that this specifies the encoding that loupe-test will use to
    75 talk to bookloupe/gutcheck and _not_ the encoding of the .tst file
    76 (which remains UTF-8). gutcheck understands Latin-1 (at least to a
    77 limited extent), the canonical name for which is ISO-8859-1:
    78 
    79       ┌─────────────────────────────────────────────────────────────────┐
    80       │**************** ENCODING ****************                       │
    81       │ISO-8859-1                                                       │
    82       │**************** INPUT ****************                          │
    83       │"Hello," he said, "I wanted to bave a tête-à-tête with you."     │
    84       │**************** EXPECTED ****************                       │
    85       │                                                                 │
    86       │"Hello," he said, "I wanted to bave a tête-à-tête with you."     │
    87       │    Line 1 column 31 - Query word bave - not reporting duplicates│
    88       └─────────────────────────────────────────────────────────────────┘
    89 
    90 Embedded linefeeds
    91 ------------------
    92 
    93 One of the tests that bookloupe/gutcheck need to do is check that all
    94 lines are ended with CR LF (as required by PG) rather than the UNIX
    95 standard LF. loupe-test deliberately ignores the line endings in testcase
    96 definition files and uses the expected CR LF. Thus there is needed a means
    97 to embed a linefeed (aka newline) character into the input to be sent
    98 to bookloupe/gutcheck to test that it correctly identified the problem.
    99 loupe-test recognises the unicode symbol for linefeed (U+240A): ␊ which
   100 can be used for this purpose instead of a normal newline.
   101 
   102 UNIX-style newlines
   103 -------------------
   104 
   105 To make life easier for users on UNIX and similar platforms, bookloupe
   106 recognises the case of all lines terminated with UNIX-style newlines.
   107 It notes this in the summary but does not issue any warnings. We thus
   108 need some way to test this case which we do by the NEWLINES tag:
   109 
   110   ┌──────────────────────────────────────────────────────────────────────────┐
   111   │**************** NEWLINES ****************                                │
   112   │LF                                                                        │
   113   │**************** INPUT ****************                                   │
   114   │Katherine was assailed by a sudden doubt. Had she mailed that letter? Yes,│
   115   │she was certain of that. She had run out to the mail box at ten o'clock   │
   116   │at night especially to mail it. What had gone wrong? Why wasn't there     │
   117   │someone to meet her?                                                      │
   118   └──────────────────────────────────────────────────────────────────────────┘
   119 
   120 The possible options are CRLF for DOS-style newlines (the default) and
   121 LF for UNIX-style newlines.
   122 
   123 Passing command line options
   124 ----------------------------
   125 
   126 Some of bookloupe's functionality is only available using command line
   127 options. loupe-test provides a means of specifying these with the
   128 OPTIONS tag:
   129 
   130 		┌──────────────────────────────────────────┐
   131                 │**************** OPTIONS **************** │
   132                 │-m                                        │
   133                 │-d                                        │
   134                 │**************** INPUT ****************   │
   135                 │&ldquo;He went <i>thataway!</i>&rdquo;    │
   136                 │**************** EXPECTED ****************│
   137 		└──────────────────────────────────────────┘
   138 
   139 Extra input files
   140 -----------------
   141 
   142 Under certain circumstances, bookloupe reads other input files than just
   143 the ebook. These can be specified in the testcase definition file by
   144 adding the name of the file to the INPUT tag:
   145 
   146        ┌───────────────────────────────────────────────────────────────┐
   147        │**************** OPTIONS ****************                      │
   148        │-u                                                             │
   149        │**************** INPUT(gutcheck.typ) ****************          │
   150        │arid                                                           │
   151        │**************** INPUT ****************                        │
   152        │I am the very model of a modern Major-General,                 │
   153        │I've information vegetable, animal, and mineral,               │
   154        │I know the kings of England, arid I quote the fights historical│
   155        │From Marathon to Waterloo, in order categorical;               │
   156        │I'm very well acquainted, too, with matters mathematical,      │
   157        │I understand equations, both the simple and quadratical,       │
   158        │About binomial theorem I'm teeming with a lot o' news--        │
   159        │With many cheerful facts about the square of the hypotenuse.   │
   160        │**************** EXPECTED ****************                     │
   161        │                                                               │
   162        │I know the kings of England, arid I quote the fights historical│
   163        │    Line 3 column 29 - Query possible scanno arid              │
   164        └───────────────────────────────────────────────────────────────┘
   165 
   166 False-positives
   167 ---------------
   168 
   169 Most of the time, the input can be tweaked so that all warnings bookloupe
   170 reports represent real errors in the text. Sometimes, however, this either
   171 cannot be done and still test what we need to. In these cases we need a
   172 means to describe these false-positives (warnings that do not describe
   173 a real error). This is important so that a later version of bookloupe can
   174 be improved to not issue the false-positive warning and still pass the
   175 test. In order to do this, we need to describe the warnings in a more
   176 structures manner, like this:
   177 
   178        ┌───────────────────────────────────────────────────────────────┐
   179        │**************** OPTIONS ****************                      │
   180        │-s                                                             │
   181        │**************** INPUT ****************                        │
   182        │'In a moment,' Peter replied,' I'm just coming.'               │
   183        │                                                               │
   184        │'Underneath the girls' scarves.                                │
   185        │                                                               │
   186        │**************** WARNINGS ****************                     │
   187        │<expected>                                                     │
   188        │  <error>                                                      │
   189        │    <at line="1" column="30"/>                                 │
   190        │    <text>Wrongspaced singlequotes?</text>                     │
   191        │  </error>                                                     │
   192        │  <false-positive>                                             │
   193        │    <at line="2"/>                                             │
   194        │    <text>Mismatched singlequotes?</text>                      │
   195        │  </false-positive>                                            │
   196        │  <false-negative>                                             │
   197        │    <at line="3" column="1"/>                                  │
   198        │    <at line="4"/>                                             │
   199        │    <text>Mismatched singlequotes?</text>                      │
   200        │  </false-negative>                                            │
   201        │</expected>                                                    │
   202        └───────────────────────────────────────────────────────────────┘
   203 
   204 Here, we use the "WARNINGS" tag instead of "EXPECTED" to denote that we
   205 wish to use structured warnings and the list of warnings is enclosed in
   206 an <expected> ... </expected> node.
   207 
   208 Each warning, or potential warnings is then described using either an
   209 "error" node (for warnings that represent real errors in the text), a
   210 "false-positive" node (for warnings that do not represent real errors),
   211 or a "false-negative" node (for warnings that should be issued, but that
   212 are not yet detected by bookloupe).
   213 
   214 Within each warning node, there are then one or more "at" nodes which
   215 list the acceptable locations for the warning to be reported at (the
   216 first listed should be the preferred location) and exactly one "text"
   217 node which must match the text of the warning issued.
   218 
   219 A testcase will pass if all the warnings marked as errors were issued and
   220 if no warnings were issued that are not listed in one form or another.
   221 If the testcase passes with an expected failure (ie., issues a warning
   222 for a false positive or does not issue a warning for a false negative),
   223 then the test is counted as passed, but a note will be printed describing
   224 this, eg.:
   225 
   226 sample: PASS (with 1 of 1 false positives and 1 of 1 false negatives)
   227 
   228 The summary
   229 -----------
   230 
   231 As part of the header (the first section of output), bookloupe may display
   232 a number of summary lines. These are characterized by a leading ASCII
   233 long arrow (-->) and generally say something about the ebook as a whole
   234 rather than individual lines. Where it is desired to test for the presence
   235 of a summary line, a "summary" node can be included within the "expected"
   236 node of a testcase using structured warnings. The "summary" node can contain
   237 one or more "text" nodes which indicate the text of lines that must be
   238 present in the summary section in order for the test to pass. No account is
   239 taken of the order of such lines and other summary lines may also be present.