blob: 8f12d48fe8b4ffe4a4b37dcd16ce58e50837433f [file] [log] [blame]
Core GIT Tests
This directory holds many test scripts for core GIT tools. The
first part of this short document describes how to run the tests
and read their output.
When fixing the tools or adding enhancements, you are strongly
encouraged to add tests in this directory to cover what you are
describes how your test scripts should be organized.
Running Tests
the tests.
*** ***
* passed all 23 test(s)
*** ***
* ok 1: using old names should issue warnings.
Or you can run each test individually from command line, like
$ sh ./
* passed all 3 test(s)
(or -i) command line argument to the test.
This makes the test more verbose. Specifically, the
command being run and their output if any are also
This may help the person who is developing a new test.
It causes the command defined with test_debug to run.
This causes the test to immediately exit upon the first
failed test.
This causes additional long-running tests to be run (where
available), for more exhaustive testing.
Skipping Tests
In some environments, certain tests have no way of succeeding
due to platform limitation, such as lack of 'unzip' program, or
filesystem that do not allow arbitrary sequence of non-NUL bytes
as pathnames.
You should be able to say something like
$ GIT_SKIP_TESTS=t9200.8 sh ./
and even:
$ GIT_SKIP_TESTS='t[0-4]??? t91?? t9200.8' make
to omit such tests. The value of the environment variable is a
SP separated list of patterns that tells which tests to skip,
and either can match the "t[0-9]{4}" part to skip the whole
test, or t[0-9]{4} followed by ".$number" to say which
particular test to skip.
Note that some tests in the existing test suite rely on previous
test item, so you cannot arbitrarily disable one and expect the
remainder of test to check what the test originally was intended
to check.
Naming Tests
The test files are named as:
where N is a decimal digit.
First digit tells the family:
0 - the absolute basics and global stuff
1 - the basic commands concerning database
2 - the basic commands concerning the working tree
4 - the diff commands
5 - the pull and exporting commands
7 - the porcelainish commands concerning the working tree
8 - the porcelainish commands concerning forensics
9 - the git tools
Second digit tells the particular command we are testing.
we are testing.
pattern. The Makefile here considers all such files as the
especially needed if you are creating a common test library
file, similar to, because such a library file may
not be suitable for standalone execution.
Writing Tests
assignment to variable 'test_description', like this:
# Copyright (c) 2005 Junio C Hamano
test_description='xxx test (option --frotz)
This test registers the following structure in the cache
Source ''
After assigning test_description, the test script should source like this:
. ./
This test harness library does the following things:
database and chdir(2) into it. This directory is 't/trash directory'
- Defines standard test helper functions for your scripts to
use. These functions are designed to make all scripts behave
End with test_done
Your script will be a sequence of tests, using helper functions
Test harness library
There are a handful helper functions defined in the test harness
library for your script to use.
- test_expect_success <message> <script>
This takes two strings as parameter, and evaluates the
<script>. If it yields success, test is considered
successful. <message> should state what it is testing.
test_expect_success \
- test_expect_failure <message> <script>
This is NOT the opposite of test_expect_success, but is used
to mark a test that demonstrates a known breakage. Unlike
the usual test_expect_success tests, which say "ok" on
success and "FAIL" on failure, this will say "FIXED" on
success and "still broken" on failure. Failures from these
tests won't cause -i (immediate) to stop.
- test_debug <script>
when the test script is started with --debug command line
argument. This is primarily meant for use during the
development of a new test script.
- test_done
Your test script must have test_done at the end. Its purpose
is to summarize successes and failures in the test script and
exit with an appropriate error code.
Tips for Writing Tests
As with any programming projects, existing programs are the best
40-byte string. This is deliberately done so in
because the things the very basic core test tries to achieve is
drastically. For these people, after making certain changes,
not seeing failures from the basic test _is_ a failure. And
such drastic changes to the core GIT that even changes these
otherwise supposedly stable object IDs should be accompanied by
an update to
GIT working properly should not have that level of intimate
knowledge of the core GIT internals. If all the test scripts
hardcoded the object IDs like does, that defeats
the purpose of, which is to isolate that level of
validation in one place. Your test also ends up needing
do it and leave the low level of validation to