test-lib.sh: add --long-tests option
[git/gitweb.git] / t / README
blobdc892631e00c16ef1477b8ab9b157a27dece91fe
1 Core GIT Tests
2 ==============
4 This directory holds many test scripts for core GIT tools.  The
5 first part of this short document describes how to run the tests
6 and read their output.
8 When fixing the tools or adding enhancements, you are strongly
9 encouraged to add tests in this directory to cover what you are
10 trying to fix or enhance.  The later part of this short document
11 describes how your test scripts should be organized.
14 Running Tests
15 -------------
17 The easiest way to run tests is to say "make".  This runs all
18 the tests.
20     *** t0000-basic.sh ***
21     *   ok 1: .git/objects should be empty after git-init in an empty repo.
22     *   ok 2: .git/objects should have 256 subdirectories.
23     *   ok 3: git-update-index without --add should fail adding.
24     ...
25     *   ok 23: no diff after checkout and git-update-index --refresh.
26     * passed all 23 test(s)
27     *** t0100-environment-names.sh ***
28     *   ok 1: using old names should issue warnings.
29     *   ok 2: using old names but having new names should not issue warnings.
30     ...
32 Or you can run each test individually from command line, like
33 this:
35     $ sh ./t3001-ls-files-killed.sh
36     *   ok 1: git-update-index --add to add various paths.
37     *   ok 2: git-ls-files -k to show killed files.
38     *   ok 3: validate git-ls-files -k output.
39     * passed all 3 test(s)
41 You can pass --verbose (or -v), --debug (or -d), and --immediate
42 (or -i) command line argument to the test.
44 --verbose::
45         This makes the test more verbose.  Specifically, the
46         command being run and their output if any are also
47         output.
49 --debug::
50         This may help the person who is developing a new test.
51         It causes the command defined with test_debug to run.
53 --immediate::
54         This causes the test to immediately exit upon the first
55         failed test.
57 --long-tests::
58         This causes additional long-running tests to be run (where
59         available), for more exhaustive testing.
62 Naming Tests
63 ------------
65 The test files are named as:
67         tNNNN-commandname-details.sh
69 where N is a decimal digit.
71 First digit tells the family:
73         0 - the absolute basics and global stuff
74         1 - the basic commands concerning database
75         2 - the basic commands concerning the working tree
76         3 - the other basic commands (e.g. ls-files)
77         4 - the diff commands
78         5 - the pull and exporting commands
79         6 - the revision tree commands (even e.g. merge-base)
80         7 - the porcelainish commands concerning the working tree
81         8 - the porcelainish commands concerning forensics
82         9 - the git tools
84 Second digit tells the particular command we are testing.
86 Third digit (optionally) tells the particular switch or group of switches
87 we are testing.
89 If you create files under t/ directory (i.e. here) that is not
90 the top-level test script, never name the file to match the above
91 pattern.  The Makefile here considers all such files as the
92 top-level test script and tries to run all of them.  A care is
93 especially needed if you are creating a common test library
94 file, similar to test-lib.sh, because such a library file may
95 not be suitable for standalone execution.
98 Writing Tests
99 -------------
101 The test script is written as a shell script.  It should start
102 with the standard "#!/bin/sh" with copyright notices, and an
103 assignment to variable 'test_description', like this:
105         #!/bin/sh
106         #
107         # Copyright (c) 2005 Junio C Hamano
108         #
110         test_description='xxx test (option --frotz)
112         This test registers the following structure in the cache
113         and tries to run git-ls-files with option --frotz.'
116 Source 'test-lib.sh'
117 --------------------
119 After assigning test_description, the test script should source
120 test-lib.sh like this:
122         . ./test-lib.sh
124 This test harness library does the following things:
126  - If the script is invoked with command line argument --help
127    (or -h), it shows the test_description and exits.
129  - Creates an empty test directory with an empty .git/objects
130    database and chdir(2) into it.  This directory is 't/trash directory'
131    if you must know, but I do not think you care.
133  - Defines standard test helper functions for your scripts to
134    use.  These functions are designed to make all scripts behave
135    consistently when command line arguments --verbose (or -v),
136    --debug (or -d), and --immediate (or -i) is given.
139 End with test_done
140 ------------------
142 Your script will be a sequence of tests, using helper functions
143 from the test harness library.  At the end of the script, call
144 'test_done'.
147 Test harness library
148 --------------------
150 There are a handful helper functions defined in the test harness
151 library for your script to use.
153  - test_expect_success <message> <script>
155    This takes two strings as parameter, and evaluates the
156    <script>.  If it yields success, test is considered
157    successful.  <message> should state what it is testing.
159    Example:
161         test_expect_success \
162             'git-write-tree should be able to write an empty tree.' \
163             'tree=$(git-write-tree)'
165  - test_expect_failure <message> <script>
167    This is NOT the opposite of test_expect_success, but is used
168    to mark a test that demonstrates a known breakage.  Unlike
169    the usual test_expect_success tests, which say "ok" on
170    success and "FAIL" on failure, this will say "FIXED" on
171    success and "still broken" on failure.  Failures from these
172    tests won't cause -i (immediate) to stop.
174  - test_debug <script>
176    This takes a single argument, <script>, and evaluates it only
177    when the test script is started with --debug command line
178    argument.  This is primarily meant for use during the
179    development of a new test script.
181  - test_done
183    Your test script must have test_done at the end.  Its purpose
184    is to summarize successes and failures in the test script and
185    exit with an appropriate error code.
188 Tips for Writing Tests
189 ----------------------
191 As with any programming projects, existing programs are the best
192 source of the information.  However, do _not_ emulate
193 t0000-basic.sh when writing your tests.  The test is special in
194 that it tries to validate the very core of GIT.  For example, it
195 knows that there will be 256 subdirectories under .git/objects/,
196 and it knows that the object ID of an empty tree is a certain
197 40-byte string.  This is deliberately done so in t0000-basic.sh
198 because the things the very basic core test tries to achieve is
199 to serve as a basis for people who are changing the GIT internal
200 drastically.  For these people, after making certain changes,
201 not seeing failures from the basic test _is_ a failure.  And
202 such drastic changes to the core GIT that even changes these
203 otherwise supposedly stable object IDs should be accompanied by
204 an update to t0000-basic.sh.
206 However, other tests that simply rely on basic parts of the core
207 GIT working properly should not have that level of intimate
208 knowledge of the core GIT internals.  If all the test scripts
209 hardcoded the object IDs like t0000-basic.sh does, that defeats
210 the purpose of t0000-basic.sh, which is to isolate that level of
211 validation in one place.  Your test also ends up needing
212 updating when such a change to the internal happens, so do _not_
213 do it and leave the low level of validation to t0000-basic.sh.