]> git.ipfire.org Git - thirdparty/git.git/blame - t/README
Enhance hold_lock_file_for_{update,append}() API
[thirdparty/git.git] / t / README
CommitLineData
986aa7f1
JH
1Core GIT Tests
2==============
3
4This directory holds many test scripts for core GIT tools. The
5first part of this short document describes how to run the tests
6and read their output.
7
8When fixing the tools or adding enhancements, you are strongly
9encouraged to add tests in this directory to cover what you are
10trying to fix or enhance. The later part of this short document
11describes how your test scripts should be organized.
12
13
14Running Tests
15-------------
16
17The easiest way to run tests is to say "make". This runs all
18the tests.
19
20 *** t0000-basic.sh ***
5c94f87e 21 * ok 1: .git/objects should be empty after git-init in an empty repo.
986aa7f1 22 * ok 2: .git/objects should have 256 subdirectories.
215a7ad1 23 * ok 3: git-update-index without --add should fail adding.
986aa7f1 24 ...
215a7ad1 25 * ok 23: no diff after checkout and git-update-index --refresh.
986aa7f1
JH
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 ...
31
32Or you can run each test individually from command line, like
33this:
34
14cd1ff3 35 $ sh ./t3001-ls-files-killed.sh
215a7ad1 36 * ok 1: git-update-index --add to add various paths.
986aa7f1
JH
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)
40
41You can pass --verbose (or -v), --debug (or -d), and --immediate
42(or -i) command line argument to the test.
43
44--verbose::
45 This makes the test more verbose. Specifically, the
46 command being run and their output if any are also
47 output.
48
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.
52
53--immediate::
54 This causes the test to immediately exit upon the first
55 failed test.
56
5e2c08c6
LW
57--long-tests::
58 This causes additional long-running tests to be run (where
59 available), for more exhaustive testing.
60
986aa7f1 61
fbd458a3
JN
62Skipping Tests
63--------------
64
65In some environments, certain tests have no way of succeeding
66due to platform limitation, such as lack of 'unzip' program, or
67filesystem that do not allow arbitrary sequence of non-NUL bytes
68as pathnames.
69
70You should be able to say something like
71
72 $ GIT_SKIP_TESTS=t9200.8 sh ./t9200-git-cvsexport-commit.sh
73
74and even:
75
76 $ GIT_SKIP_TESTS='t[0-4]??? t91?? t9200.8' make
77
78to omit such tests. The value of the environment variable is a
79SP separated list of patterns that tells which tests to skip,
80and either can match the "t[0-9]{4}" part to skip the whole
81test, or t[0-9]{4} followed by ".$number" to say which
82particular test to skip.
83
84Note that some tests in the existing test suite rely on previous
85test item, so you cannot arbitrarily disable one and expect the
86remainder of test to check what the test originally was intended
87to check.
88
89
f50c9f76
PB
90Naming Tests
91------------
92
93The test files are named as:
94
95 tNNNN-commandname-details.sh
96
97where N is a decimal digit.
98
99First digit tells the family:
100
101 0 - the absolute basics and global stuff
102 1 - the basic commands concerning database
103 2 - the basic commands concerning the working tree
104 3 - the other basic commands (e.g. ls-files)
105 4 - the diff commands
106 5 - the pull and exporting commands
107 6 - the revision tree commands (even e.g. merge-base)
8f4a9b62 108 7 - the porcelainish commands concerning the working tree
8757749e
JN
109 8 - the porcelainish commands concerning forensics
110 9 - the git tools
f50c9f76
PB
111
112Second digit tells the particular command we are testing.
113
114Third digit (optionally) tells the particular switch or group of switches
115we are testing.
116
77656600
JH
117If you create files under t/ directory (i.e. here) that is not
118the top-level test script, never name the file to match the above
119pattern. The Makefile here considers all such files as the
120top-level test script and tries to run all of them. A care is
121especially needed if you are creating a common test library
122file, similar to test-lib.sh, because such a library file may
123not be suitable for standalone execution.
124
f50c9f76 125
986aa7f1
JH
126Writing Tests
127-------------
128
129The test script is written as a shell script. It should start
130with the standard "#!/bin/sh" with copyright notices, and an
131assignment to variable 'test_description', like this:
132
133 #!/bin/sh
134 #
135 # Copyright (c) 2005 Junio C Hamano
136 #
137
14cd1ff3 138 test_description='xxx test (option --frotz)
986aa7f1
JH
139
140 This test registers the following structure in the cache
141 and tries to run git-ls-files with option --frotz.'
142
f50c9f76 143
986aa7f1
JH
144Source 'test-lib.sh'
145--------------------
146
147After assigning test_description, the test script should source
148test-lib.sh like this:
149
150 . ./test-lib.sh
151
152This test harness library does the following things:
153
154 - If the script is invoked with command line argument --help
155 (or -h), it shows the test_description and exits.
156
157 - Creates an empty test directory with an empty .git/objects
9231e3a9 158 database and chdir(2) into it. This directory is 't/trash directory'
986aa7f1
JH
159 if you must know, but I do not think you care.
160
161 - Defines standard test helper functions for your scripts to
162 use. These functions are designed to make all scripts behave
163 consistently when command line arguments --verbose (or -v),
164 --debug (or -d), and --immediate (or -i) is given.
165
14cd1ff3 166
986aa7f1
JH
167End with test_done
168------------------
169
170Your script will be a sequence of tests, using helper functions
171from the test harness library. At the end of the script, call
172'test_done'.
173
174
175Test harness library
176--------------------
177
178There are a handful helper functions defined in the test harness
179library for your script to use.
180
181 - test_expect_success <message> <script>
182
183 This takes two strings as parameter, and evaluates the
184 <script>. If it yields success, test is considered
185 successful. <message> should state what it is testing.
186
187 Example:
188
189 test_expect_success \
190 'git-write-tree should be able to write an empty tree.' \
191 'tree=$(git-write-tree)'
192
193 - test_expect_failure <message> <script>
194
41ac414e
JH
195 This is NOT the opposite of test_expect_success, but is used
196 to mark a test that demonstrates a known breakage. Unlike
197 the usual test_expect_success tests, which say "ok" on
198 success and "FAIL" on failure, this will say "FIXED" on
199 success and "still broken" on failure. Failures from these
200 tests won't cause -i (immediate) to stop.
986aa7f1
JH
201
202 - test_debug <script>
203
204 This takes a single argument, <script>, and evaluates it only
205 when the test script is started with --debug command line
206 argument. This is primarily meant for use during the
207 development of a new test script.
208
209 - test_done
210
211 Your test script must have test_done at the end. Its purpose
212 is to summarize successes and failures in the test script and
213 exit with an appropriate error code.
214
215
216Tips for Writing Tests
217----------------------
218
219As with any programming projects, existing programs are the best
220source of the information. However, do _not_ emulate
221t0000-basic.sh when writing your tests. The test is special in
222that it tries to validate the very core of GIT. For example, it
223knows that there will be 256 subdirectories under .git/objects/,
224and it knows that the object ID of an empty tree is a certain
22540-byte string. This is deliberately done so in t0000-basic.sh
226because the things the very basic core test tries to achieve is
227to serve as a basis for people who are changing the GIT internal
228drastically. For these people, after making certain changes,
229not seeing failures from the basic test _is_ a failure. And
230such drastic changes to the core GIT that even changes these
231otherwise supposedly stable object IDs should be accompanied by
232an update to t0000-basic.sh.
233
234However, other tests that simply rely on basic parts of the core
235GIT working properly should not have that level of intimate
236knowledge of the core GIT internals. If all the test scripts
237hardcoded the object IDs like t0000-basic.sh does, that defeats
238the purpose of t0000-basic.sh, which is to isolate that level of
239validation in one place. Your test also ends up needing
240updating when such a change to the internal happens, so do _not_
241do it and leave the low level of validation to t0000-basic.sh.