doc/loupe-test.txt
author ali <ali@juiblex.co.uk>
Mon Feb 20 08:13:47 2012 +0000 (2012-02-20)
changeset 35 51a0beae92f6
parent 10 f28ad4577863
child 101 f44c530f80da
permissions -rw-r--r--
Add testcase for embedded CRs
     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 NL (as required by PG) rather than the UNIX
    95 standard NL. loupe-test deliberately ignores the line endings in testcase
    96 definition files and always uses CR NL. 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 Passing command line options
   103 ----------------------------
   104 
   105 Some of bookloupe's functionality is only available using command line
   106 options. loupe-test provides a means of specifying these with the
   107 OPTIONS tag:
   108 
   109 		┌──────────────────────────────────────────┐
   110                 │**************** OPTIONS **************** │
   111                 │-m                                        │
   112                 │-d                                        │
   113                 │**************** INPUT ****************   │
   114                 │&ldquo;He went <i>thataway!</i>&rdquo;    │
   115                 │**************** EXPECTED ****************│
   116 		└──────────────────────────────────────────┘
   117 
   118 Extra input files
   119 -----------------
   120 
   121 Under certain circumstances, bookloupe reads other input files than just
   122 the ebook. These can be specified in the testcase definition file by
   123 adding the name of the file to the INPUT tag:
   124 
   125        ┌───────────────────────────────────────────────────────────────┐
   126        │**************** OPTIONS ****************                      │
   127        │-u                                                             │
   128        │**************** INPUT(gutcheck.typ) ****************          │
   129        │arid                                                           │
   130        │**************** INPUT ****************                        │
   131        │I am the very model of a modern Major-General,                 │
   132        │I've information vegetable, animal, and mineral,               │
   133        │I know the kings of England, arid I quote the fights historical│
   134        │From Marathon to Waterloo, in order categorical;               │
   135        │I'm very well acquainted, too, with matters mathematical,      │
   136        │I understand equations, both the simple and quadratical,       │
   137        │About binomial theorem I'm teeming with a lot o' news--        │
   138        │With many cheerful facts about the square of the hypotenuse.   │
   139        │**************** EXPECTED ****************                     │
   140        │                                                               │
   141        │I know the kings of England, arid I quote the fights historical│
   142        │    Line 3 column 29 - Query possible scanno arid              │
   143        └───────────────────────────────────────────────────────────────┘
   144 
   145 False-positives
   146 ---------------
   147 
   148 Most of the time, the input can be tweaked so that all warnings bookloupe
   149 reports represent real errors in the text. Sometimes, however, this either
   150 cannot be done and still test what we need to. In these cases we need a
   151 means to describe these false-positives (warnings that do not describe
   152 a real error). This is important so that a later version of bookloupe can
   153 be improved to not issue the false-positive warning and still pass the
   154 test. In order to do this, we need to describe the warnings in a more
   155 structures manner, like this:
   156 
   157        ┌───────────────────────────────────────────────────────────────┐
   158        │**************** OPTIONS ****************                      │
   159        │-s                                                             │
   160        │**************** INPUT ****************                        │
   161        │'In a moment,' Peter replied,' I'm just coming.'               │
   162        │                                                               │
   163        │'Underneath the girls' scarves.                                │
   164        │                                                               │
   165        │**************** WARNINGS ****************                     │
   166        │<expected>                                                     │
   167        │  <error>                                                      │
   168        │    <at line="1" column="30"/>                                 │
   169        │    <text>Wrongspaced singlequotes?</text>                     │
   170        │  </error>                                                     │
   171        │  <false-positive>                                             │
   172        │    <at line="2"/>                                             │
   173        │    <text>Mismatched singlequotes?</text>                      │
   174        │  </false-positive>                                            │
   175        │  <false-negative>                                             │
   176        │    <at line="3" column="1"/>                                  │
   177        │    <at line="4"/>                                             │
   178        │    <text>Mismatched singlequotes?</text>                      │
   179        │  </false-negative>                                            │
   180        │</expected>                                                    │
   181        └───────────────────────────────────────────────────────────────┘
   182 
   183 Here, we use the "WARNINGS" tag instead of "EXPECTED" to denote that we
   184 wish to use structured warnings and the list of warnings is enclosed in
   185 an <expected> ... </expected> node.
   186 
   187 Each warning, or potential warnings is then described using either an
   188 "error" node (for warnings that represent real errors in the text), a
   189 "false-positive" node (for warnings that do not represent real errors),
   190 or a "false-negative" node (for warnings that should be issued, but that
   191 are not yet detected by bookloupe).
   192 
   193 Within each warning node, there are then one or more "at" nodes which
   194 list the acceptable locations for the warning to be reported at (the
   195 first listed should be the preferred location) and exactly one "text"
   196 node which must match the text of the warning issued.
   197 
   198 A testcase will pass if all the warnings marked as errors were issued and
   199 if no warnings were issued that are not listed in one form or another.
   200 If the testcase passes with an expected failure (ie., issues a warning
   201 for a false positive or does not issue a warning for a false negative),
   202 then the test is counted as passed, but a note will be printed describing
   203 this, eg.:
   204 
   205 sample: PASS (with 1 of 1 false positives and 1 of 1 false negatives)