]> git.notmuchmail.org Git - notmuch/blob - test/README
test: Add a new test_expect_equal_failure
[notmuch] / test / README
1 Notmuch test suite
2 ==================
3 This directory contains the test suite for notmuch.
4
5 When fixing bugs or enhancing notmuch, you are strongly encouraged to
6 add tests in this directory to cover what you are trying to fix or
7 enhance.
8
9 Running Tests
10 -------------
11 The easiest way to run tests is to say "make test", (or simply run the
12 notmuch-test script). Either command will run all available tests.
13
14 Alternately, you can run a specific subset of tests by simply invoking
15 one of the executable scripts in this directory, (such as ./search,
16 ./reply, etc.)
17
18 The following command-line options are available when running tests:
19
20 --debug::
21         This may help the person who is developing a new test.
22         It causes the command defined with test_debug to run.
23
24 --immediate::
25         This causes the test to immediately exit upon the first
26         failed test.
27
28 --valgrind::
29         Execute notmuch with valgrind and exit with status
30         126 on errors (just like regular tests, this will only stop
31         the test script when running under -i).  Valgrind errors
32         go to stderr, so you might want to pass the -v option, too.
33
34         Since it makes no sense to run the tests with --valgrind and
35         not see any output, this option implies --verbose.  For
36         convenience, it also implies --tee.
37
38 --tee::
39         In addition to printing the test output to the terminal,
40         write it to files named 't/test-results/$TEST_NAME.out'.
41         As the names depend on the tests' file names, it is safe to
42         run the tests with this option in parallel.
43
44 When invoking the test suite via "make test" any of the above options
45 can be specified as follows:
46
47         make test OPTIONS="--verbose"
48
49 Skipping Tests
50 --------------
51 If, for any reason, you need to skip one or more tests, you can do so
52 by setting the NOTMUCH_SKIP_TESTS variable to the name of one or more
53 sections of tests.
54
55 For example:
56
57     $ NOTMUCH_SKIP_TESTS="search reply" make test
58
59 Even more fine-grained skipping is possible by appending a test number
60 (or glob pattern) after the section name. For example, the first
61 search test and the second reply test could be skipped with:
62
63     $ NOTMUCH_SKIP_TESTS="search.1 reply.2" make test
64
65 Note that some tests in the existing test suite rely on previous test
66 items, so you cannot arbitrarily skip any test and expect the
67 remaining tests to be unaffected.
68
69 Writing Tests
70 -------------
71 The test script is written as a shell script.  It should start
72 with the standard "#!/bin/bash" with copyright notices, and an
73 assignment to variable 'test_description', like this:
74
75         #!/bin/bash
76         #
77         # Copyright (c) 2005 Junio C Hamano
78         #
79
80         test_description='xxx test (option --frotz)
81
82         This test exercises the "notmuch xxx" command when
83         given the option --frotz.'
84
85 Source 'test-lib.sh'
86 --------------------
87 After assigning test_description, the test script should source
88 test-lib.sh like this:
89
90         . ./test-lib.sh
91
92 This test harness library does the following things:
93
94  - If the script is invoked with command line argument --help
95    (or -h), it shows the test_description and exits.
96
97  - Creates a temporary directory with default notmuch-config and a
98    mail store with a corpus of mail, (initially, 50 early messages
99    sent to the notmuch list). This directory is
100    test/tmp.<test-basename>. The path to notmuch-config is exported in
101    NOTMUCH_CONFIG environment variable and mail store path is stored
102    in MAIL_DIR variable.
103
104  - Defines standard test helper functions for your scripts to
105    use.  These functions are designed to make all scripts behave
106    consistently when command line arguments --verbose (or -v),
107    --debug (or -d), and --immediate (or -i) is given.
108
109 End with test_done
110 ------------------
111 Your script will be a sequence of tests, using helper functions
112 from the test harness library.  At the end of the script, call
113 'test_done'.
114
115 Test harness library
116 --------------------
117 There are a handful helper functions defined in the test harness
118 library for your script to use.
119
120  test_expect_success <message> <script>
121
122    This takes two strings as parameter, and evaluates the
123    <script>.  If it yields success, test is considered
124    successful.  <message> should state what it is testing.
125
126  test_expect_failure <message> <script>
127
128    This is NOT the opposite of test_expect_success, but is used
129    to mark a test that demonstrates a known breakage.  Unlike
130    the usual test_expect_success tests, which say "ok" on
131    success and "FAIL" on failure, this will say "FIXED" on
132    success and "still broken" on failure.  Failures from these
133    tests won't cause -i (immediate) to stop.
134
135  test_begin_subtest <message>
136
137    Set the test description message for a subsequent test_expect_equal
138    invocation (see below).
139
140  test_expect_equal <output> <expected>
141
142    This is an often-used convenience function built on top of
143    test_expect_success. It uses the message from the last
144    test_begin_subtest call, so call before calling
145    test_expect_equal. This function generates a successful test if
146    both the <output> and <expected> strings are identical. If not, it
147    will generate a failure and print the difference of the two
148    strings.
149
150  test_expect_equal_failure <output> <expected>
151
152    This works similar to test_expect_equal (see above) but is used to
153    mark a test that demonstrates a known breakage, (that is, the
154    author of the test expectes "output" and "expected" to differ until
155    the breakage is fixed). See test_expect_failure for details.
156
157  test_debug <script>
158
159    This takes a single argument, <script>, and evaluates it only
160    when the test script is started with --debug command line
161    argument.  This is primarily meant for use during the
162    development of a new test script.
163
164  test_emacs <emacs-lisp-expressions>
165
166    This function executes the provided emacs lisp script within
167    emacs. The script can be a sequence of emacs lisp expressions,
168    (that is, they will be evaluated within a progn form). The lisp
169    expressions can call `message' to generate output on stdout to be
170    examined by the calling test script.
171
172  test_done
173
174    Your test script must have test_done at the end.  Its purpose
175    is to summarize successes and failures in the test script and
176    exit with an appropriate error code.
177
178 There are also a number of mail-specific functions which are useful in
179 writing tests:
180
181   generate_message
182
183     Generates a message with an optional template. Most tests will
184     actually prefere to call add_message. See below.
185
186   add_message
187
188     Generate a message and add it to the database (by calling "notmuch
189     new"). It is sufficient to simply call add_message with no
190     arguments if you don't care about the content of the message. If
191     more control is needed, arguments can be provide to specify many
192     different header values for the new message. See the documentation
193     within test-lib.sh or refer to many example calls within existing
194     tests.
195
196   add_email_corpus
197
198     This function should be called at the beginning of a test file
199     when a test needs to operate on a non-empty body of messages. It
200     will intialize the mail database to a known state of 50 sample
201     messages, (culled from the early history of the notmuch mailing
202     list).