]> git.notmuchmail.org Git - notmuch/blob - test/README
5861cc498027af53cbf3bcde2aec61e274bd4e13
[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 --verbose::
21         This makes the test more verbose.  Specifically, the
22         command being run and their output if any are also
23         output.
24
25 --debug::
26         This may help the person who is developing a new test.
27         It causes the command defined with test_debug to run.
28
29 --immediate::
30         This causes the test to immediately exit upon the first
31         failed test.
32
33 --valgrind::
34         Execute notmuch with valgrind and exit with status
35         126 on errors (just like regular tests, this will only stop
36         the test script when running under -i).  Valgrind errors
37         go to stderr, so you might want to pass the -v option, too.
38
39         Since it makes no sense to run the tests with --valgrind and
40         not see any output, this option implies --verbose.  For
41         convenience, it also implies --tee.
42
43 --tee::
44         In addition to printing the test output to the terminal,
45         write it to files named 't/test-results/$TEST_NAME.out'.
46         As the names depend on the tests' file names, it is safe to
47         run the tests with this option in parallel.
48
49 When invoking the test suite via "make test" any of the above options
50 can be specified as follows:
51
52         make test OPTIONS="--verbose"
53
54 Skipping Tests
55 --------------
56 If, for any reason, you need to skip one or more tests, you can do so
57 by setting the NOTMUCH_SKIP_TESTS variable to the name of one or more
58 sections of tests.
59
60 For example:
61
62     $ NOTMUCH_SKIP_TESTS="search reply" make test
63
64 Even more fine-grained skipping is possible by appending a test number
65 (or glob pattern) after the section name. For example, the first
66 search test and the second reply test could be skipped with:
67
68     $ NOTMUCH_SKIP_TESTS="search.1 reply.2" make test
69
70 Note that some tests in the existing test suite rely on previous test
71 items, so you cannot arbitrarily skip any test and expect the
72 remaining tests to be unaffected.
73
74 Writing Tests
75 -------------
76 The test script is written as a shell script.  It should start
77 with the standard "#!/bin/bash" with copyright notices, and an
78 assignment to variable 'test_description', like this:
79
80         #!/bin/bash
81         #
82         # Copyright (c) 2005 Junio C Hamano
83         #
84
85         test_description='xxx test (option --frotz)
86
87         This test exercises the "notmuch xxx" command when
88         given the option --frotz.'
89
90 Source 'test-lib.sh'
91 --------------------
92 After assigning test_description, the test script should source
93 test-lib.sh like this:
94
95         . ./test-lib.sh
96
97 This test harness library does the following things:
98
99  - If the script is invoked with command line argument --help
100    (or -h), it shows the test_description and exits.
101
102  - Creates a temporary directory with default notmuch-config and empty
103    mail store. This directory is 'test/tmp.<test-basename>'. The path
104    to notmuch-config is exported in NOTMUCH_CONFIG environment
105    variable and mail store path is stored in MAIL_DIR variable.
106
107  - Defines standard test helper functions for your scripts to
108    use.  These functions are designed to make all scripts behave
109    consistently when command line arguments --verbose (or -v),
110    --debug (or -d), and --immediate (or -i) is given.
111
112 End with test_done
113 ------------------
114 Your script will be a sequence of tests, using helper functions
115 from the test harness library.  At the end of the script, call
116 'test_done'.
117
118 Test harness library
119 --------------------
120 There are a handful helper functions defined in the test harness
121 library for your script to use.
122
123  - test_expect_success <message> <script>
124
125    This takes two strings as parameter, and evaluates the
126    <script>.  If it yields success, test is considered
127    successful.  <message> should state what it is testing.
128
129  - test_expect_failure <message> <script>
130
131    This is NOT the opposite of test_expect_success, but is used
132    to mark a test that demonstrates a known breakage.  Unlike
133    the usual test_expect_success tests, which say "ok" on
134    success and "FAIL" on failure, this will say "FIXED" on
135    success and "still broken" on failure.  Failures from these
136    tests won't cause -i (immediate) to stop.
137
138  - test_begin_subtest <message>
139
140    Set the test description message for a subsequent test_expect_equal
141    invocation (see below).
142
143  - test_expect_equal <output> <expected>
144
145    This is an often-used convenience function built on top of
146    test_expect_success. It uses the message from the last
147    test_begin_subtest call, so call before calling
148    test_expect_equal. This function generates a successful test if
149    both the <output> and <expected> strings are identical. If not, it
150    will generate a failure and print the difference of the two
151    strings.
152
153  - test_debug <script>
154
155    This takes a single argument, <script>, and evaluates it only
156    when the test script is started with --debug command line
157    argument.  This is primarily meant for use during the
158    development of a new test script.
159
160  - test_done
161
162    Your test script must have test_done at the end.  Its purpose
163    is to summarize successes and failures in the test script and
164    exit with an appropriate error code.
165 k