File: 04-tutorial-lit-and-filecheck.rst

package info (click to toggle)
filecheck 0.0.24%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,384 kB
  • sloc: python: 1,132; sh: 26; makefile: 14; ansic: 10
file content (152 lines) | stat: -rw-r--r-- 2,878 bytes parent folder | download
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
Tutorial: LIT and FileCheck
===========================

This tutorial assumes that you have installed ``lit`` and ``filecheck`` and have
them available in your PATH:

.. code-block:: bash

   $ filecheck
   /usr/local/bin/filecheck
   <check-file> not specified

.. code-block:: bash

   $ lit
   ...
   lit: error: No inputs specified

Minimal example
---------------

When writing LIT/FileCheck tests it is common, but not required, to combine
LIT's ``RUN`` commands and FileCheck's ``CHECK`` assertions in a single file.

Let's create a file ``minimal.itest`` with the following contents

.. code-block:: text

    RUN: echo "Hello world" | filecheck %s
    CHECK: Hello world

LIT expects a config file in a directory from which it is run. Let's create
a minimal one called ``lit.cfg``:

.. code-block:: text

    import lit.formats
    config.test_format = lit.formats.ShTest("0")

Now we can run ``lit``:

.. code-block:: bash

    lit minimal.itest

.. code-block:: bash

    -- Testing: 1 tests, single process --
    PASS: <unnamed> :: test.itest (1 of 1)
    Testing Time: 0.10s
      Expected Passes    : 1

Example: testing output of C program
------------------------------------

Passing test
~~~~~~~~~~~~

Test file ``01-pass.c``:

.. code-block:: c

    /**
    RUN: clang %s -o %S/hello-world && %S/hello-world | filecheck %s
    CHECK: Hello world
     */

    #include <stdio.h>
    int main() {
      printf("Hello world\n");
      return 0;
    }

Command:

.. code-block:: bash

   $ lit 01-pass.c

Output:

.. code-block:: text

    -- Testing: 1 tests, single process --
    PASS: <unnamed> :: 01-pass.c (1 of 1)
    Testing Time: 0.10s
      Expected Passes    : 1

Failing test
~~~~~~~~~~~~

Test file ``02-fail.c``:

.. code-block:: c

    /**
    RUN: clang %s -o %S/hello-world && %S/hello-world | filecheck %s
    CHECK: Wrong line
     */

    #include <stdio.h>
    int main() {
      printf("Hello world\n");
      return 0;
    }


Command:

.. code-block:: bash

    $ lit 02-fail.c

Output:

.. code-block:: text

    -- Testing: 1 tests, single process --
    FAIL: <unnamed> :: 02-fail.c (1 of 1)
    Testing Time: 0.11s
    ********************
    Failing Tests (1):
        <unnamed> :: 02-fail.c

      Unexpected Failures: 1

The verbose version:

.. code-block:: bash

    $ lit -v 02-fail.c

Produces more output:

.. code-block:: text

    -- Testing: 1 tests, single process --
    FAIL: <unnamed> :: 02-fail.c (1 of 1)
    ******************** TEST '<unnamed> :: 02-fail.c' FAILED ********************
    02-fail.c:3:8: error: CHECK: expected string not found in input
    CHECK: Wrong line
           ^
    <stdin>:1:1: note: scanning from here
    Hello world
    ...
    ********************
    Testing Time: 0.11s
    ********************
    Failing Tests (1):
        <unnamed> :: 02-fail.c

      Unexpected Failures: 1