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
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.
17 The easiest way to run tests is to say "make". This runs all
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.
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.
32 Or you can run each test individually from command line, like
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, or by setting GIT_TEST_OPTS
43 appropriately before running "make".
46 This makes the test more verbose. Specifically, the
47 command being run and their output if any are also
51 This may help the person who is developing a new test.
52 It causes the command defined with test_debug to run.
55 This causes the test to immediately exit upon the first
59 This causes additional long-running tests to be run (where
60 available), for more exhaustive testing.
63 Execute all Git binaries with valgrind and exit with status
64 126 on errors (just like regular tests, this will only stop
65 the test script when running under -i). Valgrind errors
66 go to stderr, so you might want to pass the -v option, too.
69 In addition to printing the test output to the terminal,
70 write it to files named 't/test-results/$TEST_NAME.out'.
71 As the names depend on the tests' file names, it is safe to
72 run the tests with this option in parallel.
77 In some environments, certain tests have no way of succeeding
78 due to platform limitation, such as lack of 'unzip' program, or
79 filesystem that do not allow arbitrary sequence of non-NUL bytes
82 You should be able to say something like
84 $ GIT_SKIP_TESTS=t9200.8 sh ./t9200-git-cvsexport-commit.sh
88 $ GIT_SKIP_TESTS='t[0-4]??? t91?? t9200.8' make
90 to omit such tests. The value of the environment variable is a
91 SP separated list of patterns that tells which tests to skip,
92 and either can match the "t[0-9]{4}" part to skip the whole
93 test, or t[0-9]{4} followed by ".$number" to say which
94 particular test to skip.
96 Note that some tests in the existing test suite rely on previous
97 test item, so you cannot arbitrarily disable one and expect the
98 remainder of test to check what the test originally was intended
105 The test files are named as:
107 tNNNN-commandname-details.sh
109 where N is a decimal digit.
111 First digit tells the family:
113 0 - the absolute basics and global stuff
114 1 - the basic commands concerning database
115 2 - the basic commands concerning the working tree
116 3 - the other basic commands (e.g. ls-files)
117 4 - the diff commands
118 5 - the pull and exporting commands
119 6 - the revision tree commands (even e.g. merge-base)
120 7 - the porcelainish commands concerning the working tree
121 8 - the porcelainish commands concerning forensics
124 Second digit tells the particular command we are testing.
126 Third digit (optionally) tells the particular switch or group of switches
129 If you create files under t/ directory (i.e. here) that is not
130 the top-level test script, never name the file to match the above
131 pattern. The Makefile here considers all such files as the
132 top-level test script and tries to run all of them. A care is
133 especially needed if you are creating a common test library
134 file, similar to test-lib.sh, because such a library file may
135 not be suitable for standalone execution.
141 The test script is written as a shell script. It should start
142 with the standard "#!/bin/sh" with copyright notices, and an
143 assignment to variable 'test_description', like this:
147 # Copyright (c) 2005 Junio C Hamano
150 test_description='xxx test (option --frotz)
152 This test registers the following structure in the cache
153 and tries to run git-ls-files with option --frotz.'
159 After assigning test_description, the test script should source
160 test-lib.sh like this:
164 This test harness library does the following things:
166 - If the script is invoked with command line argument --help
167 (or -h), it shows the test_description and exits.
169 - Creates an empty test directory with an empty .git/objects
170 database and chdir(2) into it. This directory is 't/trash directory'
171 if you must know, but I do not think you care.
173 - Defines standard test helper functions for your scripts to
174 use. These functions are designed to make all scripts behave
175 consistently when command line arguments --verbose (or -v),
176 --debug (or -d), and --immediate (or -i) is given.
182 Your script will be a sequence of tests, using helper functions
183 from the test harness library. At the end of the script, call
190 There are a handful helper functions defined in the test harness
191 library for your script to use.
193 - test_expect_success <message> <script>
195 This takes two strings as parameter, and evaluates the
196 <script>. If it yields success, test is considered
197 successful. <message> should state what it is testing.
201 test_expect_success \
202 'git-write-tree should be able to write an empty tree.' \
203 'tree=$(git-write-tree)'
205 - test_expect_failure <message> <script>
207 This is NOT the opposite of test_expect_success, but is used
208 to mark a test that demonstrates a known breakage. Unlike
209 the usual test_expect_success tests, which say "ok" on
210 success and "FAIL" on failure, this will say "FIXED" on
211 success and "still broken" on failure. Failures from these
212 tests won't cause -i (immediate) to stop.
214 - test_debug <script>
216 This takes a single argument, <script>, and evaluates it only
217 when the test script is started with --debug command line
218 argument. This is primarily meant for use during the
219 development of a new test script.
223 Your test script must have test_done at the end. Its purpose
224 is to summarize successes and failures in the test script and
225 exit with an appropriate error code.
229 Make commit and tag names consistent by setting the author and
230 committer times to defined stated. Subsequent calls will
231 advance the times by a fixed amount.
233 - test_commit <message> [<filename> [<contents>]]
235 Creates a commit with the given message, committing the given
236 file with the given contents (default for both is to reuse the
237 message string), and adds a tag (again reusing the message
238 string as name). Calls test_tick to make the SHA-1s
241 - test_merge <message> <commit-or-tag>
243 Merges the given rev using the given message. Like test_commit,
244 creates a tag and calls test_tick before committing.
246 Tips for Writing Tests
247 ----------------------
249 As with any programming projects, existing programs are the best
250 source of the information. However, do _not_ emulate
251 t0000-basic.sh when writing your tests. The test is special in
252 that it tries to validate the very core of GIT. For example, it
253 knows that there will be 256 subdirectories under .git/objects/,
254 and it knows that the object ID of an empty tree is a certain
255 40-byte string. This is deliberately done so in t0000-basic.sh
256 because the things the very basic core test tries to achieve is
257 to serve as a basis for people who are changing the GIT internal
258 drastically. For these people, after making certain changes,
259 not seeing failures from the basic test _is_ a failure. And
260 such drastic changes to the core GIT that even changes these
261 otherwise supposedly stable object IDs should be accompanied by
262 an update to t0000-basic.sh.
264 However, other tests that simply rely on basic parts of the core
265 GIT working properly should not have that level of intimate
266 knowledge of the core GIT internals. If all the test scripts
267 hardcoded the object IDs like t0000-basic.sh does, that defeats
268 the purpose of t0000-basic.sh, which is to isolate that level of
269 validation in one place. Your test also ends up needing
270 updating when such a change to the internal happens, so do _not_
271 do it and leave the low level of validation to t0000-basic.sh.