1 Return-Path: <sojkam1@fel.cvut.cz>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id DA99B431FC1
\r
6 for <notmuch@notmuchmail.org>; Wed, 9 Jun 2010 23:49:13 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 1tZOu9XUoNtJ for <notmuch@notmuchmail.org>;
\r
16 Wed, 9 Jun 2010 23:48:51 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id B5C964196F2
\r
19 for <notmuch@notmuchmail.org>; Wed, 9 Jun 2010 23:48:35 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.4])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 1341A19F33E1;
\r
22 Thu, 10 Jun 2010 08:48:35 +0200 (CEST)
\r
23 X-Virus-Scanned: IMAP AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,
\r
27 with ESMTP id yG24X6-oD+hX; Thu, 10 Jun 2010 08:48:31 +0200 (CEST)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id E111B19F35C9;
\r
30 Thu, 10 Jun 2010 08:48:31 +0200 (CEST)
\r
31 Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])
\r
32 (Authenticated sender: sojkam1)
\r
33 by imap.feld.cvut.cz (Postfix) with ESMTPSA id C374B15C062;
\r
34 Thu, 10 Jun 2010 08:48:31 +0200 (CEST)
\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.72)
\r
36 (envelope-from <sojkam1@fel.cvut.cz>)
\r
37 id 1OMbZ1-0000JU-6J; Thu, 10 Jun 2010 08:48:31 +0200
\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH v3 1/5] Copy test framework from Git
\r
41 Date: Thu, 10 Jun 2010 08:48:00 +0200
\r
42 Message-Id: <1276152484-1164-2-git-send-email-sojkam1@fel.cvut.cz>
\r
43 X-Mailer: git-send-email 1.7.1.3.g75e44
\r
44 In-Reply-To: <1276152484-1164-1-git-send-email-sojkam1@fel.cvut.cz>
\r
45 References: <1276152484-1164-1-git-send-email-sojkam1@fel.cvut.cz>
\r
46 X-BeenThere: notmuch@notmuchmail.org
\r
47 X-Mailman-Version: 2.1.13
\r
49 List-Id: "Use and development of the notmuch mail system."
\r
50 <notmuch.notmuchmail.org>
\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
54 List-Post: <mailto:notmuch@notmuchmail.org>
\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
58 X-List-Received-Date: Thu, 10 Jun 2010 06:49:14 -0000
\r
60 Git uses a simple and yet powerful test framework, written in shell.
\r
61 The framework is easy to use for both users and developers so I think
\r
62 it would help if it is used in notmuch as well.
\r
64 This is a copy of Git's test framework from commit
\r
65 b6b0afdc30e066788592ca07c9a6c6936c68cc11 in git repository.
\r
67 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
\r
69 test/Makefile | 48 +++
\r
70 test/README | 297 ++++++++++++++++
\r
71 test/aggregate-results.sh | 34 ++
\r
72 test/t0000-basic.sh | 389 +++++++++++++++++++++
\r
73 test/test-lib.sh | 832 +++++++++++++++++++++++++++++++++++++++++++++
\r
74 5 files changed, 1600 insertions(+), 0 deletions(-)
\r
75 create mode 100644 test/Makefile
\r
76 create mode 100644 test/README
\r
77 create mode 100755 test/aggregate-results.sh
\r
78 create mode 100755 test/t0000-basic.sh
\r
79 create mode 100644 test/test-lib.sh
\r
81 diff --git a/test/Makefile b/test/Makefile
\r
82 new file mode 100644
\r
83 index 0000000..25c559b
\r
89 +# Copyright (c) 2005 Junio C Hamano
\r
92 +-include ../config.mak
\r
94 +#GIT_TEST_OPTS=--verbose --debug
\r
95 +SHELL_PATH ?= $(SHELL)
\r
100 +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
\r
102 +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
\r
103 +TSVN = $(wildcard t91[0-9][0-9]-*.sh)
\r
106 + $(MAKE) aggregate-results-and-cleanup
\r
109 + @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
\r
112 + $(RM) -r test-results
\r
115 + $(RM) -r 'trash directory'.* test-results
\r
116 + $(RM) t????/cvsroot/CVSROOT/?*
\r
117 + $(RM) -r valgrind/bin
\r
119 +aggregate-results-and-cleanup: $(T)
\r
120 + $(MAKE) aggregate-results
\r
123 +aggregate-results:
\r
124 + '$(SHELL_PATH_SQ)' ./aggregate-results.sh test-results/t*-*
\r
126 +# we can test NO_OPTIMIZE_COMMITS independently of LC_ALL
\r
128 + $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C
\r
129 + $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=0 LC_ALL=en_US.UTF-8
\r
132 + GIT_TEST_OPTS=--valgrind $(MAKE)
\r
134 +.PHONY: pre-clean $(T) aggregate-results clean valgrind
\r
135 diff --git a/test/README b/test/README
\r
136 new file mode 100644
\r
137 index 0000000..dcd3ebb
\r
144 +This directory holds many test scripts for core GIT tools. The
\r
145 +first part of this short document describes how to run the tests
\r
146 +and read their output.
\r
148 +When fixing the tools or adding enhancements, you are strongly
\r
149 +encouraged to add tests in this directory to cover what you are
\r
150 +trying to fix or enhance. The later part of this short document
\r
151 +describes how your test scripts should be organized.
\r
157 +The easiest way to run tests is to say "make". This runs all
\r
160 + *** t0000-basic.sh ***
\r
161 + * ok 1: .git/objects should be empty after git-init in an empty repo.
\r
162 + * ok 2: .git/objects should have 256 subdirectories.
\r
163 + * ok 3: git-update-index without --add should fail adding.
\r
165 + * ok 23: no diff after checkout and git-update-index --refresh.
\r
166 + * passed all 23 test(s)
\r
167 + *** t0100-environment-names.sh ***
\r
168 + * ok 1: using old names should issue warnings.
\r
169 + * ok 2: using old names but having new names should not issue warnings.
\r
172 +Or you can run each test individually from command line, like
\r
175 + $ sh ./t3001-ls-files-killed.sh
\r
176 + * ok 1: git-update-index --add to add various paths.
\r
177 + * ok 2: git-ls-files -k to show killed files.
\r
178 + * ok 3: validate git-ls-files -k output.
\r
179 + * passed all 3 test(s)
\r
181 +You can pass --verbose (or -v), --debug (or -d), and --immediate
\r
182 +(or -i) command line argument to the test, or by setting GIT_TEST_OPTS
\r
183 +appropriately before running "make".
\r
186 + This makes the test more verbose. Specifically, the
\r
187 + command being run and their output if any are also
\r
191 + This may help the person who is developing a new test.
\r
192 + It causes the command defined with test_debug to run.
\r
195 + This causes the test to immediately exit upon the first
\r
199 + This causes additional long-running tests to be run (where
\r
200 + available), for more exhaustive testing.
\r
203 + Execute all Git binaries with valgrind and exit with status
\r
204 + 126 on errors (just like regular tests, this will only stop
\r
205 + the test script when running under -i). Valgrind errors
\r
206 + go to stderr, so you might want to pass the -v option, too.
\r
208 + Since it makes no sense to run the tests with --valgrind and
\r
209 + not see any output, this option implies --verbose. For
\r
210 + convenience, it also implies --tee.
\r
213 + In addition to printing the test output to the terminal,
\r
214 + write it to files named 't/test-results/$TEST_NAME.out'.
\r
215 + As the names depend on the tests' file names, it is safe to
\r
216 + run the tests with this option in parallel.
\r
219 + By default tests are run without dashed forms of
\r
220 + commands (like git-commit) in the PATH (it only uses
\r
221 + wrappers from ../bin-wrappers). Use this option to include
\r
222 + the build directory (..) in the PATH, which contains all
\r
223 + the dashed forms of commands. This option is currently
\r
224 + implied by other options like --valgrind and
\r
225 + GIT_TEST_INSTALLED.
\r
227 +You can also set the GIT_TEST_INSTALLED environment variable to
\r
228 +the bindir of an existing git installation to test that installation.
\r
229 +You still need to have built this git sandbox, from which various
\r
230 +test-* support programs, templates, and perl libraries are used.
\r
231 +If your installed git is incomplete, it will silently test parts of
\r
232 +your built version instead.
\r
234 +When using GIT_TEST_INSTALLED, you can also set GIT_TEST_EXEC_PATH to
\r
235 +override the location of the dashed-form subcommands (what
\r
236 +GIT_EXEC_PATH would be used for during normal operation).
\r
237 +GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.
\r
243 +In some environments, certain tests have no way of succeeding
\r
244 +due to platform limitation, such as lack of 'unzip' program, or
\r
245 +filesystem that do not allow arbitrary sequence of non-NUL bytes
\r
248 +You should be able to say something like
\r
250 + $ GIT_SKIP_TESTS=t9200.8 sh ./t9200-git-cvsexport-commit.sh
\r
254 + $ GIT_SKIP_TESTS='t[0-4]??? t91?? t9200.8' make
\r
256 +to omit such tests. The value of the environment variable is a
\r
257 +SP separated list of patterns that tells which tests to skip,
\r
258 +and either can match the "t[0-9]{4}" part to skip the whole
\r
259 +test, or t[0-9]{4} followed by ".$number" to say which
\r
260 +particular test to skip.
\r
262 +Note that some tests in the existing test suite rely on previous
\r
263 +test item, so you cannot arbitrarily disable one and expect the
\r
264 +remainder of test to check what the test originally was intended
\r
271 +The test files are named as:
\r
273 + tNNNN-commandname-details.sh
\r
275 +where N is a decimal digit.
\r
277 +First digit tells the family:
\r
279 + 0 - the absolute basics and global stuff
\r
280 + 1 - the basic commands concerning database
\r
281 + 2 - the basic commands concerning the working tree
\r
282 + 3 - the other basic commands (e.g. ls-files)
\r
283 + 4 - the diff commands
\r
284 + 5 - the pull and exporting commands
\r
285 + 6 - the revision tree commands (even e.g. merge-base)
\r
286 + 7 - the porcelainish commands concerning the working tree
\r
287 + 8 - the porcelainish commands concerning forensics
\r
288 + 9 - the git tools
\r
290 +Second digit tells the particular command we are testing.
\r
292 +Third digit (optionally) tells the particular switch or group of switches
\r
295 +If you create files under t/ directory (i.e. here) that is not
\r
296 +the top-level test script, never name the file to match the above
\r
297 +pattern. The Makefile here considers all such files as the
\r
298 +top-level test script and tries to run all of them. A care is
\r
299 +especially needed if you are creating a common test library
\r
300 +file, similar to test-lib.sh, because such a library file may
\r
301 +not be suitable for standalone execution.
\r
307 +The test script is written as a shell script. It should start
\r
308 +with the standard "#!/bin/sh" with copyright notices, and an
\r
309 +assignment to variable 'test_description', like this:
\r
313 + # Copyright (c) 2005 Junio C Hamano
\r
316 + test_description='xxx test (option --frotz)
\r
318 + This test registers the following structure in the cache
\r
319 + and tries to run git-ls-files with option --frotz.'
\r
322 +Source 'test-lib.sh'
\r
323 +--------------------
\r
325 +After assigning test_description, the test script should source
\r
326 +test-lib.sh like this:
\r
330 +This test harness library does the following things:
\r
332 + - If the script is invoked with command line argument --help
\r
333 + (or -h), it shows the test_description and exits.
\r
335 + - Creates an empty test directory with an empty .git/objects
\r
336 + database and chdir(2) into it. This directory is 't/trash directory'
\r
337 + if you must know, but I do not think you care.
\r
339 + - Defines standard test helper functions for your scripts to
\r
340 + use. These functions are designed to make all scripts behave
\r
341 + consistently when command line arguments --verbose (or -v),
\r
342 + --debug (or -d), and --immediate (or -i) is given.
\r
345 +End with test_done
\r
346 +------------------
\r
348 +Your script will be a sequence of tests, using helper functions
\r
349 +from the test harness library. At the end of the script, call
\r
353 +Test harness library
\r
354 +--------------------
\r
356 +There are a handful helper functions defined in the test harness
\r
357 +library for your script to use.
\r
359 + - test_expect_success <message> <script>
\r
361 + This takes two strings as parameter, and evaluates the
\r
362 + <script>. If it yields success, test is considered
\r
363 + successful. <message> should state what it is testing.
\r
367 + test_expect_success \
\r
368 + 'git-write-tree should be able to write an empty tree.' \
\r
369 + 'tree=$(git-write-tree)'
\r
371 + - test_expect_failure <message> <script>
\r
373 + This is NOT the opposite of test_expect_success, but is used
\r
374 + to mark a test that demonstrates a known breakage. Unlike
\r
375 + the usual test_expect_success tests, which say "ok" on
\r
376 + success and "FAIL" on failure, this will say "FIXED" on
\r
377 + success and "still broken" on failure. Failures from these
\r
378 + tests won't cause -i (immediate) to stop.
\r
380 + - test_debug <script>
\r
382 + This takes a single argument, <script>, and evaluates it only
\r
383 + when the test script is started with --debug command line
\r
384 + argument. This is primarily meant for use during the
\r
385 + development of a new test script.
\r
389 + Your test script must have test_done at the end. Its purpose
\r
390 + is to summarize successes and failures in the test script and
\r
391 + exit with an appropriate error code.
\r
395 + Make commit and tag names consistent by setting the author and
\r
396 + committer times to defined stated. Subsequent calls will
\r
397 + advance the times by a fixed amount.
\r
399 + - test_commit <message> [<filename> [<contents>]]
\r
401 + Creates a commit with the given message, committing the given
\r
402 + file with the given contents (default for both is to reuse the
\r
403 + message string), and adds a tag (again reusing the message
\r
404 + string as name). Calls test_tick to make the SHA-1s
\r
407 + - test_merge <message> <commit-or-tag>
\r
409 + Merges the given rev using the given message. Like test_commit,
\r
410 + creates a tag and calls test_tick before committing.
\r
412 +Tips for Writing Tests
\r
413 +----------------------
\r
415 +As with any programming projects, existing programs are the best
\r
416 +source of the information. However, do _not_ emulate
\r
417 +t0000-basic.sh when writing your tests. The test is special in
\r
418 +that it tries to validate the very core of GIT. For example, it
\r
419 +knows that there will be 256 subdirectories under .git/objects/,
\r
420 +and it knows that the object ID of an empty tree is a certain
\r
421 +40-byte string. This is deliberately done so in t0000-basic.sh
\r
422 +because the things the very basic core test tries to achieve is
\r
423 +to serve as a basis for people who are changing the GIT internal
\r
424 +drastically. For these people, after making certain changes,
\r
425 +not seeing failures from the basic test _is_ a failure. And
\r
426 +such drastic changes to the core GIT that even changes these
\r
427 +otherwise supposedly stable object IDs should be accompanied by
\r
428 +an update to t0000-basic.sh.
\r
430 +However, other tests that simply rely on basic parts of the core
\r
431 +GIT working properly should not have that level of intimate
\r
432 +knowledge of the core GIT internals. If all the test scripts
\r
433 +hardcoded the object IDs like t0000-basic.sh does, that defeats
\r
434 +the purpose of t0000-basic.sh, which is to isolate that level of
\r
435 +validation in one place. Your test also ends up needing
\r
436 +updating when such a change to the internal happens, so do _not_
\r
437 +do it and leave the low level of validation to t0000-basic.sh.
\r
438 diff --git a/test/aggregate-results.sh b/test/aggregate-results.sh
\r
439 new file mode 100755
\r
440 index 0000000..d5bab75
\r
442 +++ b/test/aggregate-results.sh
\r
454 + while read type value
\r
460 + fixed=$(($fixed + $value)) ;;
\r
462 + success=$(($success + $value)) ;;
\r
464 + failed=$(($failed + $value)) ;;
\r
466 + broken=$(($broken + $value)) ;;
\r
468 + total=$(($total + $value)) ;;
\r
473 +printf "%-8s%d\n" fixed $fixed
\r
474 +printf "%-8s%d\n" success $success
\r
475 +printf "%-8s%d\n" failed $failed
\r
476 +printf "%-8s%d\n" broken $broken
\r
477 +printf "%-8s%d\n" total $total
\r
478 diff --git a/test/t0000-basic.sh b/test/t0000-basic.sh
\r
479 new file mode 100755
\r
480 index 0000000..3ec9cbe
\r
482 +++ b/test/t0000-basic.sh
\r
486 +# Copyright (c) 2005 Junio C Hamano
\r
489 +test_description='Test the very basics part #1.
\r
491 +The rest of the test suite does not check the basic operation of git
\r
492 +plumbing commands to work very carefully. Their job is to concentrate
\r
493 +on tricky features that caused bugs in the past to detect regression.
\r
495 +This test runs very basic features, like registering things in cache,
\r
496 +writing tree, etc.
\r
498 +Note that this test *deliberately* hard-codes many expected object
\r
499 +IDs. When object ID computation changes, like in the previous case of
\r
500 +swapping compression and hashing order, the person who is making the
\r
501 +modification *should* take notice and update the test vectors here.
\r
504 +################################################################
\r
505 +# It appears that people try to run tests without building...
\r
510 + echo >&2 'You do not seem to have built git yet.'
\r
516 +################################################################
\r
517 +# git init has been done in an empty repository.
\r
518 +# make sure it is empty.
\r
520 +find .git/objects -type f -print >should-be-empty
\r
521 +test_expect_success \
\r
522 + '.git/objects should be empty after git init in an empty repo.' \
\r
523 + 'cmp -s /dev/null should-be-empty'
\r
525 +# also it should have 2 subdirectories; no fan-out anymore, pack, and info.
\r
526 +# 3 is counting "objects" itself
\r
527 +find .git/objects -type d -print >full-of-directories
\r
528 +test_expect_success \
\r
529 + '.git/objects should have 3 subdirectories.' \
\r
530 + 'test $(wc -l < full-of-directories) = 3'
\r
532 +################################################################
\r
534 +test_expect_success 'success is reported like this' '
\r
537 +test_expect_failure 'pretend we have a known breakage' '
\r
540 +test_expect_failure 'pretend we have fixed a known breakage' '
\r
543 +test_set_prereq HAVEIT
\r
545 +test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
\r
546 + test_have_prereq HAVEIT &&
\r
550 +test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
\r
553 +if test $haveit$donthaveit != yesyes
\r
555 + say "bug in test framework: prerequisite tags do not work reliably"
\r
560 +test_expect_success 'tests clean up after themselves' '
\r
561 + test_when_finished clean=yes
\r
565 +test_expect_code 1 'tests clean up even after a failure' '
\r
566 + test_when_finished cleaner=yes &&
\r
570 +if test $clean$cleaner != yesyes
\r
572 + say "bug in test framework: cleanup commands do not work reliably"
\r
576 +test_expect_code 2 'failure to clean up causes the test to fail' '
\r
577 + test_when_finished "(exit 2)"
\r
580 +################################################################
\r
581 +# Basics of the basics
\r
583 +# updating a new file without --add should fail.
\r
584 +test_expect_success 'git update-index without --add should fail adding.' '
\r
585 + test_must_fail git update-index should-be-empty
\r
588 +# and with --add it should succeed, even if it is empty (it used to fail).
\r
589 +test_expect_success \
\r
590 + 'git update-index with --add should succeed.' \
\r
591 + 'git update-index --add should-be-empty'
\r
593 +test_expect_success \
\r
594 + 'writing tree out with git write-tree' \
\r
595 + 'tree=$(git write-tree)'
\r
597 +# we know the shape and contents of the tree and know the object ID for it.
\r
598 +test_expect_success \
\r
599 + 'validate object ID of a known tree.' \
\r
600 + 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
\r
603 +rm -f should-be-empty full-of-directories
\r
604 +test_expect_success 'git update-index without --remove should fail removing.' '
\r
605 + test_must_fail git update-index should-be-empty
\r
608 +test_expect_success \
\r
609 + 'git update-index with --remove should be able to remove.' \
\r
610 + 'git update-index --remove should-be-empty'
\r
612 +# Empty tree can be written with recent write-tree.
\r
613 +test_expect_success \
\r
614 + 'git write-tree should be able to write an empty tree.' \
\r
615 + 'tree=$(git write-tree)'
\r
617 +test_expect_success \
\r
618 + 'validate object ID of a known tree.' \
\r
619 + 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
\r
621 +# Various types of objects
\r
622 +# Some filesystems do not support symblic links; on such systems
\r
623 +# some expected values are different
\r
624 +mkdir path2 path3 path3/subp3
\r
625 +paths='path0 path2/file2 path3/file3 path3/subp3/file3'
\r
628 + echo "hello $p" >$p
\r
630 +if test_have_prereq SYMLINKS
\r
634 + ln -s "hello $p" ${p}sym
\r
637 + expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b
\r
638 + expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3
\r
639 + expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
\r
641 + expectfilter='grep -v sym'
\r
642 + expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
\r
643 + expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
\r
644 + expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f
\r
647 +test_expect_success \
\r
648 + 'adding various types of objects with git update-index --add.' \
\r
649 + 'find path* ! -type d -print | xargs git update-index --add'
\r
651 +# Show them and see that matches what we expect.
\r
652 +test_expect_success \
\r
653 + 'showing stage with git ls-files --stage' \
\r
654 + 'git ls-files --stage >current'
\r
656 +$expectfilter >expected <<\EOF
\r
657 +100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
\r
658 +120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
\r
659 +100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
\r
660 +120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
\r
661 +100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
\r
662 +120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
\r
663 +100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
\r
664 +120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
\r
666 +test_expect_success \
\r
667 + 'validate git ls-files output for a known tree.' \
\r
668 + 'test_cmp expected current'
\r
670 +test_expect_success \
\r
671 + 'writing tree out with git write-tree.' \
\r
672 + 'tree=$(git write-tree)'
\r
673 +test_expect_success \
\r
674 + 'validate object ID for a known tree.' \
\r
675 + 'test "$tree" = "$expectedtree"'
\r
677 +test_expect_success \
\r
678 + 'showing tree with git ls-tree' \
\r
679 + 'git ls-tree $tree >current'
\r
680 +cat >expected <<\EOF
\r
681 +100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
\r
682 +120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
\r
683 +040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
\r
684 +040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
\r
686 +test_expect_success SYMLINKS \
\r
687 + 'git ls-tree output for a known tree.' \
\r
688 + 'test_cmp expected current'
\r
690 +# This changed in ls-tree pathspec change -- recursive does
\r
691 +# not show tree nodes anymore.
\r
692 +test_expect_success \
\r
693 + 'showing tree with git ls-tree -r' \
\r
694 + 'git ls-tree -r $tree >current'
\r
695 +$expectfilter >expected <<\EOF
\r
696 +100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
\r
697 +120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
\r
698 +100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
\r
699 +120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
\r
700 +100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
\r
701 +120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
\r
702 +100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
\r
703 +120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
\r
705 +test_expect_success \
\r
706 + 'git ls-tree -r output for a known tree.' \
\r
707 + 'test_cmp expected current'
\r
709 +# But with -r -t we can have both.
\r
710 +test_expect_success \
\r
711 + 'showing tree with git ls-tree -r -t' \
\r
712 + 'git ls-tree -r -t $tree >current'
\r
713 +cat >expected <<\EOF
\r
714 +100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
\r
715 +120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
\r
716 +040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
\r
717 +100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
\r
718 +120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
\r
719 +040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
\r
720 +100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
\r
721 +120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
\r
722 +040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
\r
723 +100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
\r
724 +120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
\r
726 +test_expect_success SYMLINKS \
\r
727 + 'git ls-tree -r output for a known tree.' \
\r
728 + 'test_cmp expected current'
\r
730 +test_expect_success \
\r
731 + 'writing partial tree out with git write-tree --prefix.' \
\r
732 + 'ptree=$(git write-tree --prefix=path3)'
\r
733 +test_expect_success \
\r
734 + 'validate object ID for a known tree.' \
\r
735 + 'test "$ptree" = "$expectedptree1"'
\r
737 +test_expect_success \
\r
738 + 'writing partial tree out with git write-tree --prefix.' \
\r
739 + 'ptree=$(git write-tree --prefix=path3/subp3)'
\r
740 +test_expect_success \
\r
741 + 'validate object ID for a known tree.' \
\r
742 + 'test "$ptree" = "$expectedptree2"'
\r
744 +cat >badobjects <<EOF
\r
745 +100644 blob 1000000000000000000000000000000000000000 dir/file1
\r
746 +100644 blob 2000000000000000000000000000000000000000 dir/file2
\r
747 +100644 blob 3000000000000000000000000000000000000000 dir/file3
\r
748 +100644 blob 4000000000000000000000000000000000000000 dir/file4
\r
749 +100644 blob 5000000000000000000000000000000000000000 dir/file5
\r
753 +test_expect_success \
\r
754 + 'put invalid objects into the index.' \
\r
755 + 'git update-index --index-info < badobjects'
\r
757 +test_expect_success 'writing this tree without --missing-ok.' '
\r
758 + test_must_fail git write-tree
\r
761 +test_expect_success \
\r
762 + 'writing this tree with --missing-ok.' \
\r
763 + 'git write-tree --missing-ok'
\r
766 +################################################################
\r
768 +test_expect_success \
\r
769 + 'git read-tree followed by write-tree should be idempotent.' \
\r
770 + 'git read-tree $tree &&
\r
771 + test -f .git/index &&
\r
772 + newtree=$(git write-tree) &&
\r
773 + test "$newtree" = "$tree"'
\r
775 +$expectfilter >expected <<\EOF
\r
776 +:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
\r
777 +:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
\r
778 +:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
\r
779 +:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
\r
780 +:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
\r
781 +:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
\r
782 +:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
\r
783 +:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
\r
785 +test_expect_success \
\r
786 + 'validate git diff-files output for a know cache/work tree state.' \
\r
787 + 'git diff-files >current && diff >/dev/null -b current expected'
\r
789 +test_expect_success \
\r
790 + 'git update-index --refresh should succeed.' \
\r
791 + 'git update-index --refresh'
\r
793 +test_expect_success \
\r
794 + 'no diff after checkout and git update-index --refresh.' \
\r
795 + 'git diff-files >current && cmp -s current /dev/null'
\r
797 +################################################################
\r
799 +test_expect_success \
\r
800 + 'git commit-tree records the correct tree in a commit.' \
\r
801 + 'commit0=$(echo NO | git commit-tree $P) &&
\r
802 + tree=$(git show --pretty=raw $commit0 |
\r
803 + sed -n -e "s/^tree //p" -e "/^author /q") &&
\r
804 + test "z$tree" = "z$P"'
\r
806 +test_expect_success \
\r
807 + 'git commit-tree records the correct parent in a commit.' \
\r
808 + 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
\r
809 + parent=$(git show --pretty=raw $commit1 |
\r
810 + sed -n -e "s/^parent //p" -e "/^author /q") &&
\r
811 + test "z$commit0" = "z$parent"'
\r
813 +test_expect_success \
\r
814 + 'git commit-tree omits duplicated parent in a commit.' \
\r
815 + 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
\r
816 + parent=$(git show --pretty=raw $commit2 |
\r
817 + sed -n -e "s/^parent //p" -e "/^author /q" |
\r
819 + test "z$commit0" = "z$parent" &&
\r
820 + numparent=$(git show --pretty=raw $commit2 |
\r
821 + sed -n -e "s/^parent //p" -e "/^author /q" |
\r
823 + test $numparent = 1'
\r
825 +test_expect_success 'update-index D/F conflict' '
\r
827 + mv path2 path0 &&
\r
829 + git update-index --add --replace path2 path0/file2 &&
\r
830 + numpath0=$(git ls-files path0 | wc -l) &&
\r
831 + test $numpath0 = 1
\r
834 +test_expect_success SYMLINKS 'absolute path works as expected' '
\r
836 + ln -s ../.git first/.git &&
\r
838 + ln -s ../first second/other &&
\r
840 + dir="$(cd .git; pwd -P)" &&
\r
841 + dir2=third/../second/other/.git &&
\r
842 + test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
\r
843 + file="$dir"/index &&
\r
844 + test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
\r
846 + test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
\r
847 + ln -s ../first/file .git/syml &&
\r
848 + sym="$(cd first; pwd -P)"/file &&
\r
849 + test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
\r
852 +test_expect_success 'very long name in the index handled sanely' '
\r
855 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
\r
856 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
\r
857 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
\r
861 + git update-index --add path4 &&
\r
863 + git ls-files -s path4 |
\r
864 + sed -e "s/ .*/ /" |
\r
867 + ) | git update-index --index-info &&
\r
868 + len=$(git ls-files "a*" | wc -c) &&
\r
873 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
874 new file mode 100644
\r
875 index 0000000..7422bba
\r
877 +++ b/test/test-lib.sh
\r
881 +# Copyright (c) 2005 Junio C Hamano
\r
883 +# This program is free software: you can redistribute it and/or modify
\r
884 +# it under the terms of the GNU General Public License as published by
\r
885 +# the Free Software Foundation, either version 2 of the License, or
\r
886 +# (at your option) any later version.
\r
888 +# This program is distributed in the hope that it will be useful,
\r
889 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
890 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
891 +# GNU General Public License for more details.
\r
893 +# You should have received a copy of the GNU General Public License
\r
894 +# along with this program. If not, see http://www.gnu.org/licenses/ .
\r
896 +# if --tee was passed, write the output not only to the terminal, but
\r
897 +# additionally to the file test-results/$BASENAME.out, too.
\r
898 +case "$GIT_TEST_TEE_STARTED, $* " in
\r
900 + # do not redirect again
\r
902 +*' --tee '*|*' --va'*)
\r
903 + mkdir -p test-results
\r
904 + BASE=test-results/$(basename "$0" .sh)
\r
905 + (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
\r
906 + echo $? > $BASE.exit) | tee $BASE.out
\r
907 + test "$(cat $BASE.exit)" = 0
\r
912 +# Keep the original TERM for say_color
\r
913 +ORIGINAL_TERM=$TERM
\r
915 +# For repeatability, reset the environment to known value.
\r
921 +export LANG LC_ALL PAGER TERM TZ
\r
926 +unset AUTHOR_EMAIL
\r
928 +unset COMMIT_AUTHOR_EMAIL
\r
929 +unset COMMIT_AUTHOR_NAME
\r
931 +unset GIT_ALTERNATE_OBJECT_DIRECTORIES
\r
932 +unset GIT_AUTHOR_DATE
\r
933 +GIT_AUTHOR_EMAIL=author@example.com
\r
934 +GIT_AUTHOR_NAME='A U Thor'
\r
935 +unset GIT_COMMITTER_DATE
\r
936 +GIT_COMMITTER_EMAIL=committer@example.com
\r
937 +GIT_COMMITTER_NAME='C O Mitter'
\r
938 +unset GIT_DIFF_OPTS
\r
940 +unset GIT_WORK_TREE
\r
941 +unset GIT_EXTERNAL_DIFF
\r
942 +unset GIT_INDEX_FILE
\r
943 +unset GIT_OBJECT_DIRECTORY
\r
944 +unset GIT_CEILING_DIRECTORIES
\r
945 +unset SHA1_FILE_DIRECTORIES
\r
946 +unset SHA1_FILE_DIRECTORY
\r
947 +unset GIT_NOTES_REF
\r
948 +unset GIT_NOTES_DISPLAY_REF
\r
949 +unset GIT_NOTES_REWRITE_REF
\r
950 +unset GIT_NOTES_REWRITE_MODE
\r
951 +GIT_MERGE_VERBOSITY=5
\r
952 +export GIT_MERGE_VERBOSITY
\r
953 +export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
\r
954 +export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
\r
956 +GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
\r
958 +# Protect ourselves from common misconfiguration to export
\r
959 +# CDPATH into the environment
\r
962 +unset GREP_OPTIONS
\r
964 +case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
\r
966 + echo "* warning: Some tests will not work if GIT_TRACE" \
\r
967 + "is set as to trace on STDERR ! *"
\r
968 + echo "* warning: Please set GIT_TRACE to something" \
\r
969 + "other than 1, 2 or true ! *"
\r
975 +# A regexp to match 5 and 40 hexdigits
\r
976 +_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
\r
977 +_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
\r
979 +# Each test should start with something like this, after copyright notices:
\r
981 +# test_description='Description of this test...
\r
982 +# This test checks if command xyzzy does the right thing...
\r
985 +[ "x$ORIGINAL_TERM" != "xdumb" ] && (
\r
986 + TERM=$ORIGINAL_TERM &&
\r
989 + tput bold >/dev/null 2>&1 &&
\r
990 + tput setaf 1 >/dev/null 2>&1 &&
\r
991 + tput sgr0 >/dev/null 2>&1
\r
995 +while test "$#" -ne 0
\r
998 + -d|--d|--de|--deb|--debu|--debug)
\r
999 + debug=t; shift ;;
\r
1000 + -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
\r
1001 + immediate=t; shift ;;
\r
1002 + -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
\r
1003 + GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
\r
1004 + -h|--h|--he|--hel|--help)
\r
1005 + help=t; shift ;;
\r
1006 + -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
\r
1007 + verbose=t; shift ;;
\r
1008 + -q|--q|--qu|--qui|--quie|--quiet)
\r
1009 + quiet=t; shift ;;
\r
1011 + with_dashes=t; shift ;;
\r
1013 + color=; shift ;;
\r
1017 + --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
\r
1018 + valgrind=t; verbose=t; shift ;;
\r
1020 + shift ;; # was handled already
\r
1022 + root=$(expr "z$1" : 'z[^=]*=\(.*\)')
\r
1025 + echo "error: unknown test option '$1'" >&2; exit 1 ;;
\r
1029 +if test -n "$color"; then
\r
1032 + TERM=$ORIGINAL_TERM
\r
1035 + error) tput bold; tput setaf 1;; # bold red
\r
1036 + skip) tput bold; tput setaf 2;; # bold green
\r
1037 + pass) tput setaf 2;; # green
\r
1038 + info) tput setaf 3;; # brown
\r
1039 + *) test -n "$quiet" && return;;
\r
1042 + printf "* %s" "$*"
\r
1049 + test -z "$1" && test -n "$quiet" && return
\r
1056 + say_color error "error: $*"
\r
1062 + say_color info "$*"
\r
1065 +test "${test_description}" != "" ||
\r
1066 +error "Test script did not set test_description."
\r
1068 +if test "$help" = "t"
\r
1070 + echo "$test_description"
\r
1075 +if test "$verbose" = "t"
\r
1079 + exec 4>/dev/null 3>/dev/null
\r
1090 + if test -n "$GIT_EXIT_OK"
\r
1094 + echo >&5 "FATAL: Unexpected exit with code $code"
\r
1102 +# The semantics of the editor variables are that of invoking
\r
1103 +# sh -c "$EDITOR \"$@\"" files ...
\r
1105 +# If our trash directory contains shell metacharacters, they will be
\r
1106 +# interpreted if we just set $EDITOR directly, so do a little dance with
\r
1107 +# environment variables to work around this.
\r
1109 +# In particular, quoting isn't enough, as the path may contain the same quote
\r
1110 +# that we're using.
\r
1111 +test_set_editor () {
\r
1112 + FAKE_EDITOR="$1"
\r
1113 + export FAKE_EDITOR
\r
1114 + EDITOR='"$FAKE_EDITOR"'
\r
1118 +test_decode_color () {
\r
1119 + sed -e 's/.\[1m/<WHITE>/g' \
\r
1120 + -e 's/.\[31m/<RED>/g' \
\r
1121 + -e 's/.\[32m/<GREEN>/g' \
\r
1122 + -e 's/.\[33m/<YELLOW>/g' \
\r
1123 + -e 's/.\[34m/<BLUE>/g' \
\r
1124 + -e 's/.\[35m/<MAGENTA>/g' \
\r
1125 + -e 's/.\[36m/<CYAN>/g' \
\r
1126 + -e 's/.\[m/<RESET>/g'
\r
1130 + perl -pe 'y/Q/\000/'
\r
1138 + sed -e 's/$/Q/' | tr Q '\015'
\r
1142 + tr '\015' Q | sed -e 's/Q$//'
\r
1146 + if test -z "${test_tick+set}"
\r
1148 + test_tick=1112911993
\r
1150 + test_tick=$(($test_tick + 60))
\r
1152 + GIT_COMMITTER_DATE="$test_tick -0700"
\r
1153 + GIT_AUTHOR_DATE="$test_tick -0700"
\r
1154 + export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
\r
1157 +# Call test_commit with the arguments "<message> [<file> [<contents>]]"
\r
1159 +# This will commit a file with the given contents and the given commit
\r
1160 +# message. It will also add a tag with <message> as name.
\r
1162 +# Both <file> and <contents> default to <message>.
\r
1165 + file=${2:-"$1.t"}
\r
1166 + echo "${3-$1}" > "$file" &&
\r
1167 + git add "$file" &&
\r
1169 + git commit -m "$1" &&
\r
1173 +# Call test_merge with the arguments "<message> <commit>", where <commit>
\r
1174 +# can be a tag pointing to the commit-to-merge.
\r
1178 + git merge -m "$1" "$2" &&
\r
1182 +# This function helps systems where core.filemode=false is set.
\r
1183 +# Use it instead of plain 'chmod +x' to set or unset the executable bit
\r
1184 +# of a file in the working directory and add it to the index.
\r
1188 + git update-index --add "--chmod=$@"
\r
1191 +# Use test_set_prereq to tell that a particular prerequisite is available.
\r
1192 +# The prerequisite can later be checked for in two ways:
\r
1194 +# - Explicitly using test_have_prereq.
\r
1196 +# - Implicitly by specifying the prerequisite tag in the calls to
\r
1197 +# test_expect_{success,failure,code}.
\r
1199 +# The single parameter is the prerequisite tag (a simple word, in all
\r
1200 +# capital letters by convention).
\r
1202 +test_set_prereq () {
\r
1203 + satisfied="$satisfied$1 "
\r
1207 +test_have_prereq () {
\r
1208 + case $satisfied in
\r
1210 + : yes, have it ;;
\r
1216 +# You are not expected to call test_ok_ and test_failure_ directly, use
\r
1217 +# the text_expect_* functions instead.
\r
1220 + test_success=$(($test_success + 1))
\r
1221 + say_color "" " ok $test_count: $@"
\r
1224 +test_failure_ () {
\r
1225 + test_failure=$(($test_failure + 1))
\r
1226 + say_color error "FAIL $test_count: $1"
\r
1228 + echo "$@" | sed -e 's/^/ /'
\r
1229 + test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
\r
1232 +test_known_broken_ok_ () {
\r
1233 + test_fixed=$(($test_fixed+1))
\r
1234 + say_color "" " FIXED $test_count: $@"
\r
1237 +test_known_broken_failure_ () {
\r
1238 + test_broken=$(($test_broken+1))
\r
1239 + say_color skip " still broken $test_count: $@"
\r
1243 + test "$debug" = "" || eval "$1"
\r
1248 + eval >&3 2>&4 "$1"
\r
1250 + eval >&3 2>&4 "$test_cleanup"
\r
1255 + test_count=$(($test_count+1))
\r
1257 + for skp in $GIT_SKIP_TESTS
\r
1259 + case $this_test.$test_count in
\r
1264 + if test -z "$to_skip" && test -n "$prereq" &&
\r
1265 + ! test_have_prereq "$prereq"
\r
1269 + case "$to_skip" in
\r
1271 + say_color skip >&3 "skipping test: $@"
\r
1272 + say_color skip "skip $test_count: $1"
\r
1281 +test_expect_failure () {
\r
1282 + test "$#" = 3 && { prereq=$1; shift; } || prereq=
\r
1283 + test "$#" = 2 ||
\r
1284 + error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
\r
1285 + if ! test_skip "$@"
\r
1287 + say >&3 "checking known breakage: $2"
\r
1289 + if [ "$?" = 0 -a "$eval_ret" = 0 ]
\r
1291 + test_known_broken_ok_ "$1"
\r
1293 + test_known_broken_failure_ "$1"
\r
1299 +test_expect_success () {
\r
1300 + test "$#" = 3 && { prereq=$1; shift; } || prereq=
\r
1301 + test "$#" = 2 ||
\r
1302 + error "bug in the test script: not 2 or 3 parameters to test-expect-success"
\r
1303 + if ! test_skip "$@"
\r
1305 + say >&3 "expecting success: $2"
\r
1307 + if [ "$?" = 0 -a "$eval_ret" = 0 ]
\r
1311 + test_failure_ "$@"
\r
1317 +test_expect_code () {
\r
1318 + test "$#" = 4 && { prereq=$1; shift; } || prereq=
\r
1319 + test "$#" = 3 ||
\r
1320 + error "bug in the test script: not 3 or 4 parameters to test-expect-code"
\r
1321 + if ! test_skip "$@"
\r
1323 + say >&3 "expecting exit code $1: $3"
\r
1325 + if [ "$?" = 0 -a "$eval_ret" = "$1" ]
\r
1329 + test_failure_ "$@"
\r
1335 +# test_external runs external test scripts that provide continuous
\r
1336 +# test output about their progress, and succeeds/fails on
\r
1337 +# zero/non-zero exit code. It outputs the test output on stdout even
\r
1338 +# in non-verbose mode, and announces the external script with "* run
\r
1339 +# <n>: ..." before running it. When providing relative paths, keep in
\r
1340 +# mind that all scripts run in "trash directory".
\r
1341 +# Usage: test_external description command arguments...
\r
1342 +# Example: test_external 'Perl API' perl ../path/to/test.pl
\r
1343 +test_external () {
\r
1344 + test "$#" = 4 && { prereq=$1; shift; } || prereq=
\r
1345 + test "$#" = 3 ||
\r
1346 + error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
\r
1349 + if ! test_skip "$descr" "$@"
\r
1351 + # Announce the script to reduce confusion about the
\r
1352 + # test output that follows.
\r
1353 + say_color "" " run $test_count: $descr ($*)"
\r
1354 + # Run command; redirect its stderr to &4 as in
\r
1355 + # test_run_, but keep its stdout on our stdout even in
\r
1356 + # non-verbose mode.
\r
1360 + test_ok_ "$descr"
\r
1362 + test_failure_ "$descr" "$@"
\r
1367 +# Like test_external, but in addition tests that the command generated
\r
1368 +# no output on stderr.
\r
1369 +test_external_without_stderr () {
\r
1370 + # The temporary file has no (and must have no) security
\r
1372 + tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
\r
1373 + stderr="$tmp/git-external-stderr.$$.tmp"
\r
1374 + test_external "$@" 4> "$stderr"
\r
1375 + [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
\r
1376 + descr="no stderr: $1"
\r
1378 + say >&3 "expecting no stderr from previous command"
\r
1379 + if [ ! -s "$stderr" ]; then
\r
1381 + test_ok_ "$descr"
\r
1383 + if [ "$verbose" = t ]; then
\r
1384 + output=`echo; echo Stderr is:; cat "$stderr"`
\r
1388 + # rm first in case test_failure exits.
\r
1390 + test_failure_ "$descr" "$@" "$output"
\r
1394 +# This is not among top-level (test_expect_success | test_expect_failure)
\r
1395 +# but is a prefix that can be used in the test script, like:
\r
1397 +# test_expect_success 'complain and die' '
\r
1398 +# do something &&
\r
1399 +# do something else &&
\r
1400 +# test_must_fail git checkout ../outerspace
\r
1403 +# Writing this as "! git checkout ../outerspace" is wrong, because
\r
1404 +# the failure could be due to a segv. We want a controlled failure.
\r
1406 +test_must_fail () {
\r
1408 + test $? -gt 0 -a $? -le 129 -o $? -gt 192
\r
1411 +# test_cmp is a helper function to compare actual and expected output.
\r
1412 +# You can use it like:
\r
1414 +# test_expect_success 'foo works' '
\r
1415 +# echo expected >expected &&
\r
1417 +# test_cmp expected actual
\r
1420 +# This could be written as either "cmp" or "diff -u", but:
\r
1421 +# - cmp's output is not nearly as easy to read as diff -u
\r
1422 +# - not all diff versions understand "-u"
\r
1425 + $GIT_TEST_CMP "$@"
\r
1428 +# This function can be used to schedule some commands to be run
\r
1429 +# unconditionally at the end of the test to restore sanity:
\r
1431 +# test_expect_success 'test core.capslock' '
\r
1432 +# git config core.capslock true &&
\r
1433 +# test_when_finished "git config --unset core.capslock" &&
\r
1437 +# That would be roughly equivalent to
\r
1439 +# test_expect_success 'test core.capslock' '
\r
1440 +# git config core.capslock true &&
\r
1442 +# git config --unset core.capslock
\r
1445 +# except that the greeting and config --unset must both succeed for
\r
1446 +# the test to pass.
\r
1448 +test_when_finished () {
\r
1449 + test_cleanup="{ $*
\r
1450 + } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
\r
1453 +# Most tests can use the created repository, but some may need to create more.
\r
1454 +# Usage: test_create_repo <directory>
\r
1455 +test_create_repo () {
\r
1456 + test "$#" = 1 ||
\r
1457 + error "bug in the test script: not 1 parameter to test-create-repo"
\r
1460 + mkdir -p "$repo"
\r
1461 + cd "$repo" || error "Cannot setup test environment"
\r
1462 + "$GIT_EXEC_PATH/git-init" "--template=$TEST_DIRECTORY/../templates/blt/" >&3 2>&4 ||
\r
1463 + error "cannot run git init -- have you built things yet?"
\r
1464 + mv .git/hooks .git/hooks-disabled
\r
1470 + test_results_dir="$TEST_DIRECTORY/test-results"
\r
1471 + mkdir -p "$test_results_dir"
\r
1472 + test_results_path="$test_results_dir/${0%.sh}-$$"
\r
1474 + echo "total $test_count" >> $test_results_path
\r
1475 + echo "success $test_success" >> $test_results_path
\r
1476 + echo "fixed $test_fixed" >> $test_results_path
\r
1477 + echo "broken $test_broken" >> $test_results_path
\r
1478 + echo "failed $test_failure" >> $test_results_path
\r
1479 + echo "" >> $test_results_path
\r
1481 + if test "$test_fixed" != 0
\r
1483 + say_color pass "fixed $test_fixed known breakage(s)"
\r
1485 + if test "$test_broken" != 0
\r
1487 + say_color error "still have $test_broken known breakage(s)"
\r
1488 + msg="remaining $(($test_count-$test_broken)) test(s)"
\r
1490 + msg="$test_count test(s)"
\r
1492 + case "$test_failure" in
\r
1494 + say_color pass "passed all $msg"
\r
1496 + test -d "$remove_trash" &&
\r
1497 + cd "$(dirname "$remove_trash")" &&
\r
1498 + rm -rf "$(basename "$remove_trash")"
\r
1503 + say_color error "failed $test_failure among $msg"
\r
1509 +# Test the binaries we have just built. The tests are kept in
\r
1510 +# t/ subdirectory and are run in 'trash directory' subdirectory.
\r
1511 +TEST_DIRECTORY=$(pwd)
\r
1512 +if test -n "$valgrind"
\r
1514 + make_symlink () {
\r
1516 + test "$1" = "$(readlink "$2")" || {
\r
1517 + # be super paranoid
\r
1518 + if mkdir "$2".lock
\r
1521 + ln -s "$1" "$2" &&
\r
1524 + while test -d "$2".lock
\r
1526 + say "Waiting for lock on $2."
\r
1533 + make_valgrind_symlink () {
\r
1534 + # handle only executables
\r
1535 + test -x "$1" || return
\r
1537 + base=$(basename "$1")
\r
1538 + symlink_target=$TEST_DIRECTORY/../$base
\r
1539 + # do not override scripts
\r
1540 + if test -x "$symlink_target" &&
\r
1541 + test ! -d "$symlink_target" &&
\r
1542 + test "#!" != "$(head -c 2 < "$symlink_target")"
\r
1544 + symlink_target=../valgrind.sh
\r
1548 + symlink_target=../unprocessed-script
\r
1550 + # create the link, or replace it if it is out of date
\r
1551 + make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
\r
1554 + # override all git executables in TEST_DIRECTORY/..
\r
1555 + GIT_VALGRIND=$TEST_DIRECTORY/valgrind
\r
1556 + mkdir -p "$GIT_VALGRIND"/bin
\r
1557 + for file in $TEST_DIRECTORY/../git* $TEST_DIRECTORY/../test-*
\r
1559 + make_valgrind_symlink $file
\r
1563 + for path in $PATH
\r
1565 + ls "$path"/git-* 2> /dev/null |
\r
1568 + make_valgrind_symlink "$file"
\r
1572 + PATH=$GIT_VALGRIND/bin:$PATH
\r
1573 + GIT_EXEC_PATH=$GIT_VALGRIND/bin
\r
1574 + export GIT_VALGRIND
\r
1575 +elif test -n "$GIT_TEST_INSTALLED" ; then
\r
1576 + GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
\r
1577 + error "Cannot run git from $GIT_TEST_INSTALLED."
\r
1578 + PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH
\r
1579 + GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
\r
1580 +else # normal case, use ../bin-wrappers only unless $with_dashes:
\r
1581 + git_bin_dir="$TEST_DIRECTORY/../bin-wrappers"
\r
1582 + if ! test -x "$git_bin_dir/git" ; then
\r
1583 + if test -z "$with_dashes" ; then
\r
1584 + say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
\r
1588 + PATH="$git_bin_dir:$PATH"
\r
1589 + GIT_EXEC_PATH=$TEST_DIRECTORY/..
\r
1590 + if test -n "$with_dashes" ; then
\r
1591 + PATH="$TEST_DIRECTORY/..:$PATH"
\r
1594 +GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
\r
1596 +GIT_CONFIG_NOSYSTEM=1
\r
1597 +GIT_CONFIG_NOGLOBAL=1
\r
1598 +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL
\r
1600 +. ../GIT-BUILD-OPTIONS
\r
1602 +GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git
\r
1603 +export GITPERLLIB
\r
1604 +test -d ../templates/blt || {
\r
1605 + error "You haven't built things yet, have you?"
\r
1608 +if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON"
\r
1610 + GITPYTHONLIB="$(pwd)/../git_remote_helpers/build/lib"
\r
1611 + export GITPYTHONLIB
\r
1612 + test -d ../git_remote_helpers/build || {
\r
1613 + error "You haven't built git_remote_helpers yet, have you?"
\r
1617 +if ! test -x ../test-chmtime; then
\r
1618 + echo >&2 'You need to build test-chmtime:'
\r
1619 + echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
\r
1623 +# Test repository
\r
1624 +test="trash directory.$(basename "$0" .sh)"
\r
1625 +test -n "$root" && test="$root/$test"
\r
1627 +/*) TRASH_DIRECTORY="$test" ;;
\r
1628 + *) TRASH_DIRECTORY="$TEST_DIRECTORY/$test" ;;
\r
1630 +test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
\r
1631 +rm -fr "$test" || {
\r
1633 + echo >&5 "FATAL: Cannot prepare test area"
\r
1637 +test_create_repo "$test"
\r
1638 +# Use -P to resolve symlinks in our working directory so that the cwd
\r
1639 +# in subprocesses like git equals our $PWD (for pathname comparisons).
\r
1640 +cd -P "$test" || exit 1
\r
1642 +this_test=${0##*/}
\r
1643 +this_test=${this_test%%-*}
\r
1644 +for skp in $GIT_SKIP_TESTS
\r
1647 + for skp in $GIT_SKIP_TESTS
\r
1649 + case "$this_test" in
\r
1654 + case "$to_skip" in
\r
1656 + say_color skip >&3 "skipping test $this_test altogether"
\r
1657 + say_color skip "skip all tests in $this_test"
\r
1662 +# Provide an implementation of the 'yes' utility
\r
1677 +# Fix some commands on Windows
\r
1678 +case $(uname -s) in
\r
1680 + # Windows has its own (incompatible) sort and find
\r
1682 + /usr/bin/sort "$@"
\r
1685 + /usr/bin/find "$@"
\r
1690 + # git sees Windows-style pwd
\r
1694 + # no POSIX permissions
\r
1695 + # backslashes in pathspec are converted to '/'
\r
1696 + # exec does not inherit the PID
\r
1699 + test_set_prereq POSIXPERM
\r
1700 + test_set_prereq BSLASHPSPEC
\r
1701 + test_set_prereq EXECKEEPSPID
\r
1705 +test -z "$NO_PERL" && test_set_prereq PERL
\r
1706 +test -z "$NO_PYTHON" && test_set_prereq PYTHON
\r
1708 +# test whether the filesystem supports symbolic links
\r
1709 +ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
\r