doc/loupe-test.txt
author ali <ali@juiblex.co.uk>
Tue Jan 31 01:07:38 2012 +0000 (2012-01-31)
changeset 13 eca715c100fe
parent 5 f600b0d1fc5d
child 19 05d082ebf685
permissions -rw-r--r--
Skip UTF-8 BOM in .tst files
     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 Caveats
   146 -------
   147 
   148 There is no support yet for testcases which are expected to fail.