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 531A6431FC0
\r
6 for <notmuch@notmuchmail.org>; Mon, 8 Feb 2010 07:16:32 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.35 tagged_above=-999 required=5 tests=[AWL=0.249,
\r
12 BAYES_00=-2.599] 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 QdFBl+kr3uDP for <notmuch@notmuchmail.org>;
\r
16 Mon, 8 Feb 2010 07:16:27 -0800 (PST)
\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 03A8A431FAE
\r
19 for <notmuch@notmuchmail.org>; Mon, 8 Feb 2010 07:16:27 -0800 (PST)
\r
20 Received: from localhost (unknown [192.168.200.4])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 61D8319F3390;
\r
22 Mon, 8 Feb 2010 16:16:26 +0100 (CET)
\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 H+VHx3-9po36; Mon, 8 Feb 2010 16:16:21 +0100 (CET)
\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 35B5719F3380;
\r
30 Mon, 8 Feb 2010 16:16:21 +0100 (CET)
\r
31 Received: from localhost.localdomain (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 23D1315C052;
\r
34 Mon, 8 Feb 2010 16:16:21 +0100 (CET)
\r
35 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
36 To: notmuch@notmuchmail.org
\r
37 Date: Mon, 8 Feb 2010 16:16:07 +0100
\r
38 Message-Id: <1265642169-15801-1-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 1.6.6
\r
40 In-Reply-To: <201002081614.24284.sojkam1@fel.cvut.cz>
\r
41 References: <201002081614.24284.sojkam1@fel.cvut.cz>
\r
42 Subject: [notmuch] [PATCH 1/3] Copy test framework from Git
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\r
46 List-Id: "Use and development of the notmuch mail system."
\r
47 <notmuch.notmuchmail.org>
\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
51 List-Post: <mailto:notmuch@notmuchmail.org>
\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
55 X-List-Received-Date: Mon, 08 Feb 2010 15:16:32 -0000
\r
57 Git uses a simple and yet powerfull test framework, written in shell.
\r
58 The framework is easy to use for both users and developers so I thing
\r
59 it would help if it is used in notmuch as well.
\r
61 This is a copy of Git's test framework from commit
\r
62 b8bba419250711a69e09e7648e5c991f4847a127.
\r
64 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
\r
66 test/Makefile | 46 +++
\r
67 test/README | 297 +++++++++++++++++
\r
68 test/aggregate-results.sh | 34 ++
\r
69 test/t0000-basic.sh | 368 +++++++++++++++++++++
\r
70 test/test-lib.sh | 787 +++++++++++++++++++++++++++++++++++++++++++++
\r
71 5 files changed, 1532 insertions(+), 0 deletions(-)
\r
72 create mode 100644 test/Makefile
\r
73 create mode 100644 test/README
\r
74 create mode 100755 test/aggregate-results.sh
\r
75 create mode 100755 test/t0000-basic.sh
\r
76 create mode 100644 test/test-lib.sh
\r
78 diff --git a/test/Makefile b/test/Makefile
\r
79 new file mode 100644
\r
80 index 0000000..bd09390
\r
86 +# Copyright (c) 2005 Junio C Hamano
\r
89 +-include ../config.mak
\r
91 +#GIT_TEST_OPTS=--verbose --debug
\r
92 +SHELL_PATH ?= $(SHELL)
\r
97 +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
\r
99 +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
\r
100 +TSVN = $(wildcard t91[0-9][0-9]-*.sh)
\r
103 + $(MAKE) aggregate-results-and-cleanup
\r
106 + @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
\r
109 + $(RM) -r test-results
\r
112 + $(RM) -r 'trash directory'.* test-results
\r
114 +aggregate-results-and-cleanup: $(T)
\r
115 + $(MAKE) aggregate-results
\r
118 +aggregate-results:
\r
119 + '$(SHELL_PATH_SQ)' ./aggregate-results.sh test-results/t*-*
\r
121 +# we can test NO_OPTIMIZE_COMMITS independently of LC_ALL
\r
123 + $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C
\r
124 + $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=0 LC_ALL=en_US.UTF-8
\r
127 + GIT_TEST_OPTS=--valgrind $(MAKE)
\r
129 +.PHONY: pre-clean $(T) aggregate-results clean valgrind
\r
130 diff --git a/test/README b/test/README
\r
131 new file mode 100644
\r
132 index 0000000..dcd3ebb
\r
139 +This directory holds many test scripts for core GIT tools. The
\r
140 +first part of this short document describes how to run the tests
\r
141 +and read their output.
\r
143 +When fixing the tools or adding enhancements, you are strongly
\r
144 +encouraged to add tests in this directory to cover what you are
\r
145 +trying to fix or enhance. The later part of this short document
\r
146 +describes how your test scripts should be organized.
\r
152 +The easiest way to run tests is to say "make". This runs all
\r
155 + *** t0000-basic.sh ***
\r
156 + * ok 1: .git/objects should be empty after git-init in an empty repo.
\r
157 + * ok 2: .git/objects should have 256 subdirectories.
\r
158 + * ok 3: git-update-index without --add should fail adding.
\r
160 + * ok 23: no diff after checkout and git-update-index --refresh.
\r
161 + * passed all 23 test(s)
\r
162 + *** t0100-environment-names.sh ***
\r
163 + * ok 1: using old names should issue warnings.
\r
164 + * ok 2: using old names but having new names should not issue warnings.
\r
167 +Or you can run each test individually from command line, like
\r
170 + $ sh ./t3001-ls-files-killed.sh
\r
171 + * ok 1: git-update-index --add to add various paths.
\r
172 + * ok 2: git-ls-files -k to show killed files.
\r
173 + * ok 3: validate git-ls-files -k output.
\r
174 + * passed all 3 test(s)
\r
176 +You can pass --verbose (or -v), --debug (or -d), and --immediate
\r
177 +(or -i) command line argument to the test, or by setting GIT_TEST_OPTS
\r
178 +appropriately before running "make".
\r
181 + This makes the test more verbose. Specifically, the
\r
182 + command being run and their output if any are also
\r
186 + This may help the person who is developing a new test.
\r
187 + It causes the command defined with test_debug to run.
\r
190 + This causes the test to immediately exit upon the first
\r
194 + This causes additional long-running tests to be run (where
\r
195 + available), for more exhaustive testing.
\r
198 + Execute all Git binaries with valgrind and exit with status
\r
199 + 126 on errors (just like regular tests, this will only stop
\r
200 + the test script when running under -i). Valgrind errors
\r
201 + go to stderr, so you might want to pass the -v option, too.
\r
203 + Since it makes no sense to run the tests with --valgrind and
\r
204 + not see any output, this option implies --verbose. For
\r
205 + convenience, it also implies --tee.
\r
208 + In addition to printing the test output to the terminal,
\r
209 + write it to files named 't/test-results/$TEST_NAME.out'.
\r
210 + As the names depend on the tests' file names, it is safe to
\r
211 + run the tests with this option in parallel.
\r
214 + By default tests are run without dashed forms of
\r
215 + commands (like git-commit) in the PATH (it only uses
\r
216 + wrappers from ../bin-wrappers). Use this option to include
\r
217 + the build directory (..) in the PATH, which contains all
\r
218 + the dashed forms of commands. This option is currently
\r
219 + implied by other options like --valgrind and
\r
220 + GIT_TEST_INSTALLED.
\r
222 +You can also set the GIT_TEST_INSTALLED environment variable to
\r
223 +the bindir of an existing git installation to test that installation.
\r
224 +You still need to have built this git sandbox, from which various
\r
225 +test-* support programs, templates, and perl libraries are used.
\r
226 +If your installed git is incomplete, it will silently test parts of
\r
227 +your built version instead.
\r
229 +When using GIT_TEST_INSTALLED, you can also set GIT_TEST_EXEC_PATH to
\r
230 +override the location of the dashed-form subcommands (what
\r
231 +GIT_EXEC_PATH would be used for during normal operation).
\r
232 +GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.
\r
238 +In some environments, certain tests have no way of succeeding
\r
239 +due to platform limitation, such as lack of 'unzip' program, or
\r
240 +filesystem that do not allow arbitrary sequence of non-NUL bytes
\r
243 +You should be able to say something like
\r
245 + $ GIT_SKIP_TESTS=t9200.8 sh ./t9200-git-cvsexport-commit.sh
\r
249 + $ GIT_SKIP_TESTS='t[0-4]??? t91?? t9200.8' make
\r
251 +to omit such tests. The value of the environment variable is a
\r
252 +SP separated list of patterns that tells which tests to skip,
\r
253 +and either can match the "t[0-9]{4}" part to skip the whole
\r
254 +test, or t[0-9]{4} followed by ".$number" to say which
\r
255 +particular test to skip.
\r
257 +Note that some tests in the existing test suite rely on previous
\r
258 +test item, so you cannot arbitrarily disable one and expect the
\r
259 +remainder of test to check what the test originally was intended
\r
266 +The test files are named as:
\r
268 + tNNNN-commandname-details.sh
\r
270 +where N is a decimal digit.
\r
272 +First digit tells the family:
\r
274 + 0 - the absolute basics and global stuff
\r
275 + 1 - the basic commands concerning database
\r
276 + 2 - the basic commands concerning the working tree
\r
277 + 3 - the other basic commands (e.g. ls-files)
\r
278 + 4 - the diff commands
\r
279 + 5 - the pull and exporting commands
\r
280 + 6 - the revision tree commands (even e.g. merge-base)
\r
281 + 7 - the porcelainish commands concerning the working tree
\r
282 + 8 - the porcelainish commands concerning forensics
\r
283 + 9 - the git tools
\r
285 +Second digit tells the particular command we are testing.
\r
287 +Third digit (optionally) tells the particular switch or group of switches
\r
290 +If you create files under t/ directory (i.e. here) that is not
\r
291 +the top-level test script, never name the file to match the above
\r
292 +pattern. The Makefile here considers all such files as the
\r
293 +top-level test script and tries to run all of them. A care is
\r
294 +especially needed if you are creating a common test library
\r
295 +file, similar to test-lib.sh, because such a library file may
\r
296 +not be suitable for standalone execution.
\r
302 +The test script is written as a shell script. It should start
\r
303 +with the standard "#!/bin/sh" with copyright notices, and an
\r
304 +assignment to variable 'test_description', like this:
\r
308 + # Copyright (c) 2005 Junio C Hamano
\r
311 + test_description='xxx test (option --frotz)
\r
313 + This test registers the following structure in the cache
\r
314 + and tries to run git-ls-files with option --frotz.'
\r
317 +Source 'test-lib.sh'
\r
318 +--------------------
\r
320 +After assigning test_description, the test script should source
\r
321 +test-lib.sh like this:
\r
325 +This test harness library does the following things:
\r
327 + - If the script is invoked with command line argument --help
\r
328 + (or -h), it shows the test_description and exits.
\r
330 + - Creates an empty test directory with an empty .git/objects
\r
331 + database and chdir(2) into it. This directory is 't/trash directory'
\r
332 + if you must know, but I do not think you care.
\r
334 + - Defines standard test helper functions for your scripts to
\r
335 + use. These functions are designed to make all scripts behave
\r
336 + consistently when command line arguments --verbose (or -v),
\r
337 + --debug (or -d), and --immediate (or -i) is given.
\r
340 +End with test_done
\r
341 +------------------
\r
343 +Your script will be a sequence of tests, using helper functions
\r
344 +from the test harness library. At the end of the script, call
\r
348 +Test harness library
\r
349 +--------------------
\r
351 +There are a handful helper functions defined in the test harness
\r
352 +library for your script to use.
\r
354 + - test_expect_success <message> <script>
\r
356 + This takes two strings as parameter, and evaluates the
\r
357 + <script>. If it yields success, test is considered
\r
358 + successful. <message> should state what it is testing.
\r
362 + test_expect_success \
\r
363 + 'git-write-tree should be able to write an empty tree.' \
\r
364 + 'tree=$(git-write-tree)'
\r
366 + - test_expect_failure <message> <script>
\r
368 + This is NOT the opposite of test_expect_success, but is used
\r
369 + to mark a test that demonstrates a known breakage. Unlike
\r
370 + the usual test_expect_success tests, which say "ok" on
\r
371 + success and "FAIL" on failure, this will say "FIXED" on
\r
372 + success and "still broken" on failure. Failures from these
\r
373 + tests won't cause -i (immediate) to stop.
\r
375 + - test_debug <script>
\r
377 + This takes a single argument, <script>, and evaluates it only
\r
378 + when the test script is started with --debug command line
\r
379 + argument. This is primarily meant for use during the
\r
380 + development of a new test script.
\r
384 + Your test script must have test_done at the end. Its purpose
\r
385 + is to summarize successes and failures in the test script and
\r
386 + exit with an appropriate error code.
\r
390 + Make commit and tag names consistent by setting the author and
\r
391 + committer times to defined stated. Subsequent calls will
\r
392 + advance the times by a fixed amount.
\r
394 + - test_commit <message> [<filename> [<contents>]]
\r
396 + Creates a commit with the given message, committing the given
\r
397 + file with the given contents (default for both is to reuse the
\r
398 + message string), and adds a tag (again reusing the message
\r
399 + string as name). Calls test_tick to make the SHA-1s
\r
402 + - test_merge <message> <commit-or-tag>
\r
404 + Merges the given rev using the given message. Like test_commit,
\r
405 + creates a tag and calls test_tick before committing.
\r
407 +Tips for Writing Tests
\r
408 +----------------------
\r
410 +As with any programming projects, existing programs are the best
\r
411 +source of the information. However, do _not_ emulate
\r
412 +t0000-basic.sh when writing your tests. The test is special in
\r
413 +that it tries to validate the very core of GIT. For example, it
\r
414 +knows that there will be 256 subdirectories under .git/objects/,
\r
415 +and it knows that the object ID of an empty tree is a certain
\r
416 +40-byte string. This is deliberately done so in t0000-basic.sh
\r
417 +because the things the very basic core test tries to achieve is
\r
418 +to serve as a basis for people who are changing the GIT internal
\r
419 +drastically. For these people, after making certain changes,
\r
420 +not seeing failures from the basic test _is_ a failure. And
\r
421 +such drastic changes to the core GIT that even changes these
\r
422 +otherwise supposedly stable object IDs should be accompanied by
\r
423 +an update to t0000-basic.sh.
\r
425 +However, other tests that simply rely on basic parts of the core
\r
426 +GIT working properly should not have that level of intimate
\r
427 +knowledge of the core GIT internals. If all the test scripts
\r
428 +hardcoded the object IDs like t0000-basic.sh does, that defeats
\r
429 +the purpose of t0000-basic.sh, which is to isolate that level of
\r
430 +validation in one place. Your test also ends up needing
\r
431 +updating when such a change to the internal happens, so do _not_
\r
432 +do it and leave the low level of validation to t0000-basic.sh.
\r
433 diff --git a/test/aggregate-results.sh b/test/aggregate-results.sh
\r
434 new file mode 100755
\r
435 index 0000000..d5bab75
\r
437 +++ b/test/aggregate-results.sh
\r
449 + while read type value
\r
455 + fixed=$(($fixed + $value)) ;;
\r
457 + success=$(($success + $value)) ;;
\r
459 + failed=$(($failed + $value)) ;;
\r
461 + broken=$(($broken + $value)) ;;
\r
463 + total=$(($total + $value)) ;;
\r
468 +printf "%-8s%d\n" fixed $fixed
\r
469 +printf "%-8s%d\n" success $success
\r
470 +printf "%-8s%d\n" failed $failed
\r
471 +printf "%-8s%d\n" broken $broken
\r
472 +printf "%-8s%d\n" total $total
\r
473 diff --git a/test/t0000-basic.sh b/test/t0000-basic.sh
\r
474 new file mode 100755
\r
475 index 0000000..f4ca4fc
\r
477 +++ b/test/t0000-basic.sh
\r
481 +# Copyright (c) 2005 Junio C Hamano
\r
484 +test_description='Test the very basics part #1.
\r
486 +The rest of the test suite does not check the basic operation of git
\r
487 +plumbing commands to work very carefully. Their job is to concentrate
\r
488 +on tricky features that caused bugs in the past to detect regression.
\r
490 +This test runs very basic features, like registering things in cache,
\r
491 +writing tree, etc.
\r
493 +Note that this test *deliberately* hard-codes many expected object
\r
494 +IDs. When object ID computation changes, like in the previous case of
\r
495 +swapping compression and hashing order, the person who is making the
\r
496 +modification *should* take notice and update the test vectors here.
\r
499 +################################################################
\r
500 +# It appears that people try to run tests without building...
\r
505 + echo >&2 'You do not seem to have built git yet.'
\r
511 +################################################################
\r
512 +# git init has been done in an empty repository.
\r
513 +# make sure it is empty.
\r
515 +find .git/objects -type f -print >should-be-empty
\r
516 +test_expect_success \
\r
517 + '.git/objects should be empty after git init in an empty repo.' \
\r
518 + 'cmp -s /dev/null should-be-empty'
\r
520 +# also it should have 2 subdirectories; no fan-out anymore, pack, and info.
\r
521 +# 3 is counting "objects" itself
\r
522 +find .git/objects -type d -print >full-of-directories
\r
523 +test_expect_success \
\r
524 + '.git/objects should have 3 subdirectories.' \
\r
525 + 'test $(wc -l < full-of-directories) = 3'
\r
527 +################################################################
\r
529 +test_expect_success 'success is reported like this' '
\r
532 +test_expect_failure 'pretend we have a known breakage' '
\r
535 +test_expect_failure 'pretend we have fixed a known breakage' '
\r
538 +test_set_prereq HAVEIT
\r
540 +test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
\r
541 + test_have_prereq HAVEIT &&
\r
545 +test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
\r
548 +if test $haveit$donthaveit != yesyes
\r
550 + say "bug in test framework: prerequisite tags do not work reliably"
\r
554 +################################################################
\r
555 +# Basics of the basics
\r
557 +# updating a new file without --add should fail.
\r
558 +test_expect_success 'git update-index without --add should fail adding.' '
\r
559 + test_must_fail git update-index should-be-empty
\r
562 +# and with --add it should succeed, even if it is empty (it used to fail).
\r
563 +test_expect_success \
\r
564 + 'git update-index with --add should succeed.' \
\r
565 + 'git update-index --add should-be-empty'
\r
567 +test_expect_success \
\r
568 + 'writing tree out with git write-tree' \
\r
569 + 'tree=$(git write-tree)'
\r
571 +# we know the shape and contents of the tree and know the object ID for it.
\r
572 +test_expect_success \
\r
573 + 'validate object ID of a known tree.' \
\r
574 + 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
\r
577 +rm -f should-be-empty full-of-directories
\r
578 +test_expect_success 'git update-index without --remove should fail removing.' '
\r
579 + test_must_fail git update-index should-be-empty
\r
582 +test_expect_success \
\r
583 + 'git update-index with --remove should be able to remove.' \
\r
584 + 'git update-index --remove should-be-empty'
\r
586 +# Empty tree can be written with recent write-tree.
\r
587 +test_expect_success \
\r
588 + 'git write-tree should be able to write an empty tree.' \
\r
589 + 'tree=$(git write-tree)'
\r
591 +test_expect_success \
\r
592 + 'validate object ID of a known tree.' \
\r
593 + 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
\r
595 +# Various types of objects
\r
596 +# Some filesystems do not support symblic links; on such systems
\r
597 +# some expected values are different
\r
598 +mkdir path2 path3 path3/subp3
\r
599 +paths='path0 path2/file2 path3/file3 path3/subp3/file3'
\r
602 + echo "hello $p" >$p
\r
604 +if test_have_prereq SYMLINKS
\r
608 + ln -s "hello $p" ${p}sym
\r
611 + expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b
\r
612 + expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3
\r
613 + expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
\r
615 + expectfilter='grep -v sym'
\r
616 + expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
\r
617 + expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
\r
618 + expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f
\r
621 +test_expect_success \
\r
622 + 'adding various types of objects with git update-index --add.' \
\r
623 + 'find path* ! -type d -print | xargs git update-index --add'
\r
625 +# Show them and see that matches what we expect.
\r
626 +test_expect_success \
\r
627 + 'showing stage with git ls-files --stage' \
\r
628 + 'git ls-files --stage >current'
\r
630 +$expectfilter >expected <<\EOF
\r
631 +100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
\r
632 +120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
\r
633 +100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
\r
634 +120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
\r
635 +100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
\r
636 +120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
\r
637 +100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
\r
638 +120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
\r
640 +test_expect_success \
\r
641 + 'validate git ls-files output for a known tree.' \
\r
642 + 'test_cmp expected current'
\r
644 +test_expect_success \
\r
645 + 'writing tree out with git write-tree.' \
\r
646 + 'tree=$(git write-tree)'
\r
647 +test_expect_success \
\r
648 + 'validate object ID for a known tree.' \
\r
649 + 'test "$tree" = "$expectedtree"'
\r
651 +test_expect_success \
\r
652 + 'showing tree with git ls-tree' \
\r
653 + 'git ls-tree $tree >current'
\r
654 +cat >expected <<\EOF
\r
655 +100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
\r
656 +120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
\r
657 +040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
\r
658 +040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
\r
660 +test_expect_success SYMLINKS \
\r
661 + 'git ls-tree output for a known tree.' \
\r
662 + 'test_cmp expected current'
\r
664 +# This changed in ls-tree pathspec change -- recursive does
\r
665 +# not show tree nodes anymore.
\r
666 +test_expect_success \
\r
667 + 'showing tree with git ls-tree -r' \
\r
668 + 'git ls-tree -r $tree >current'
\r
669 +$expectfilter >expected <<\EOF
\r
670 +100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
\r
671 +120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
\r
672 +100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
\r
673 +120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
\r
674 +100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
\r
675 +120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
\r
676 +100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
\r
677 +120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
\r
679 +test_expect_success \
\r
680 + 'git ls-tree -r output for a known tree.' \
\r
681 + 'test_cmp expected current'
\r
683 +# But with -r -t we can have both.
\r
684 +test_expect_success \
\r
685 + 'showing tree with git ls-tree -r -t' \
\r
686 + 'git ls-tree -r -t $tree >current'
\r
687 +cat >expected <<\EOF
\r
688 +100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
\r
689 +120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
\r
690 +040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
\r
691 +100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
\r
692 +120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
\r
693 +040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
\r
694 +100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
\r
695 +120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
\r
696 +040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
\r
697 +100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
\r
698 +120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
\r
700 +test_expect_success SYMLINKS \
\r
701 + 'git ls-tree -r output for a known tree.' \
\r
702 + 'test_cmp expected current'
\r
704 +test_expect_success \
\r
705 + 'writing partial tree out with git write-tree --prefix.' \
\r
706 + 'ptree=$(git write-tree --prefix=path3)'
\r
707 +test_expect_success \
\r
708 + 'validate object ID for a known tree.' \
\r
709 + 'test "$ptree" = "$expectedptree1"'
\r
711 +test_expect_success \
\r
712 + 'writing partial tree out with git write-tree --prefix.' \
\r
713 + 'ptree=$(git write-tree --prefix=path3/subp3)'
\r
714 +test_expect_success \
\r
715 + 'validate object ID for a known tree.' \
\r
716 + 'test "$ptree" = "$expectedptree2"'
\r
718 +cat >badobjects <<EOF
\r
719 +100644 blob 1000000000000000000000000000000000000000 dir/file1
\r
720 +100644 blob 2000000000000000000000000000000000000000 dir/file2
\r
721 +100644 blob 3000000000000000000000000000000000000000 dir/file3
\r
722 +100644 blob 4000000000000000000000000000000000000000 dir/file4
\r
723 +100644 blob 5000000000000000000000000000000000000000 dir/file5
\r
727 +test_expect_success \
\r
728 + 'put invalid objects into the index.' \
\r
729 + 'git update-index --index-info < badobjects'
\r
731 +test_expect_success 'writing this tree without --missing-ok.' '
\r
732 + test_must_fail git write-tree
\r
735 +test_expect_success \
\r
736 + 'writing this tree with --missing-ok.' \
\r
737 + 'git write-tree --missing-ok'
\r
740 +################################################################
\r
742 +test_expect_success \
\r
743 + 'git read-tree followed by write-tree should be idempotent.' \
\r
744 + 'git read-tree $tree &&
\r
745 + test -f .git/index &&
\r
746 + newtree=$(git write-tree) &&
\r
747 + test "$newtree" = "$tree"'
\r
749 +$expectfilter >expected <<\EOF
\r
750 +:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
\r
751 +:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
\r
752 +:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
\r
753 +:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
\r
754 +:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
\r
755 +:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
\r
756 +:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
\r
757 +:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
\r
759 +test_expect_success \
\r
760 + 'validate git diff-files output for a know cache/work tree state.' \
\r
761 + 'git diff-files >current && diff >/dev/null -b current expected'
\r
763 +test_expect_success \
\r
764 + 'git update-index --refresh should succeed.' \
\r
765 + 'git update-index --refresh'
\r
767 +test_expect_success \
\r
768 + 'no diff after checkout and git update-index --refresh.' \
\r
769 + 'git diff-files >current && cmp -s current /dev/null'
\r
771 +################################################################
\r
773 +test_expect_success \
\r
774 + 'git commit-tree records the correct tree in a commit.' \
\r
775 + 'commit0=$(echo NO | git commit-tree $P) &&
\r
776 + tree=$(git show --pretty=raw $commit0 |
\r
777 + sed -n -e "s/^tree //p" -e "/^author /q") &&
\r
778 + test "z$tree" = "z$P"'
\r
780 +test_expect_success \
\r
781 + 'git commit-tree records the correct parent in a commit.' \
\r
782 + 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
\r
783 + parent=$(git show --pretty=raw $commit1 |
\r
784 + sed -n -e "s/^parent //p" -e "/^author /q") &&
\r
785 + test "z$commit0" = "z$parent"'
\r
787 +test_expect_success \
\r
788 + 'git commit-tree omits duplicated parent in a commit.' \
\r
789 + 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
\r
790 + parent=$(git show --pretty=raw $commit2 |
\r
791 + sed -n -e "s/^parent //p" -e "/^author /q" |
\r
793 + test "z$commit0" = "z$parent" &&
\r
794 + numparent=$(git show --pretty=raw $commit2 |
\r
795 + sed -n -e "s/^parent //p" -e "/^author /q" |
\r
797 + test $numparent = 1'
\r
799 +test_expect_success 'update-index D/F conflict' '
\r
801 + mv path2 path0 &&
\r
803 + git update-index --add --replace path2 path0/file2 &&
\r
804 + numpath0=$(git ls-files path0 | wc -l) &&
\r
805 + test $numpath0 = 1
\r
808 +test_expect_success SYMLINKS 'absolute path works as expected' '
\r
810 + ln -s ../.git first/.git &&
\r
812 + ln -s ../first second/other &&
\r
814 + dir="$(cd .git; pwd -P)" &&
\r
815 + dir2=third/../second/other/.git &&
\r
816 + test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
\r
817 + file="$dir"/index &&
\r
818 + test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
\r
820 + test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
\r
821 + ln -s ../first/file .git/syml &&
\r
822 + sym="$(cd first; pwd -P)"/file &&
\r
823 + test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
\r
826 +test_expect_success 'very long name in the index handled sanely' '
\r
829 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
\r
830 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
\r
831 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
\r
835 + git update-index --add path4 &&
\r
837 + git ls-files -s path4 |
\r
838 + sed -e "s/ .*/ /" |
\r
841 + ) | git update-index --index-info &&
\r
842 + len=$(git ls-files "a*" | wc -c) &&
\r
847 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
848 new file mode 100644
\r
849 index 0000000..afd3053
\r
851 +++ b/test/test-lib.sh
\r
855 +# Copyright (c) 2005 Junio C Hamano
\r
858 +# if --tee was passed, write the output not only to the terminal, but
\r
859 +# additionally to the file test-results/$BASENAME.out, too.
\r
860 +case "$GIT_TEST_TEE_STARTED, $* " in
\r
862 + # do not redirect again
\r
864 +*' --tee '*|*' --va'*)
\r
865 + mkdir -p test-results
\r
866 + BASE=test-results/$(basename "$0" .sh)
\r
867 + (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
\r
868 + echo $? > $BASE.exit) | tee $BASE.out
\r
869 + test "$(cat $BASE.exit)" = 0
\r
874 +# Keep the original TERM for say_color
\r
875 +ORIGINAL_TERM=$TERM
\r
877 +# For repeatability, reset the environment to known value.
\r
883 +export LANG LC_ALL PAGER TERM TZ
\r
888 +unset AUTHOR_EMAIL
\r
890 +unset COMMIT_AUTHOR_EMAIL
\r
891 +unset COMMIT_AUTHOR_NAME
\r
893 +unset GIT_ALTERNATE_OBJECT_DIRECTORIES
\r
894 +unset GIT_AUTHOR_DATE
\r
895 +GIT_AUTHOR_EMAIL=author@example.com
\r
896 +GIT_AUTHOR_NAME='A U Thor'
\r
897 +unset GIT_COMMITTER_DATE
\r
898 +GIT_COMMITTER_EMAIL=committer@example.com
\r
899 +GIT_COMMITTER_NAME='C O Mitter'
\r
900 +unset GIT_DIFF_OPTS
\r
902 +unset GIT_WORK_TREE
\r
903 +unset GIT_EXTERNAL_DIFF
\r
904 +unset GIT_INDEX_FILE
\r
905 +unset GIT_OBJECT_DIRECTORY
\r
906 +unset GIT_CEILING_DIRECTORIES
\r
907 +unset SHA1_FILE_DIRECTORIES
\r
908 +unset SHA1_FILE_DIRECTORY
\r
909 +GIT_MERGE_VERBOSITY=5
\r
910 +export GIT_MERGE_VERBOSITY
\r
911 +export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
\r
912 +export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
\r
914 +GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
\r
916 +# Protect ourselves from common misconfiguration to export
\r
917 +# CDPATH into the environment
\r
920 +case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
\r
922 + echo "* warning: Some tests will not work if GIT_TRACE" \
\r
923 + "is set as to trace on STDERR ! *"
\r
924 + echo "* warning: Please set GIT_TRACE to something" \
\r
925 + "other than 1, 2 or true ! *"
\r
931 +# A regexp to match 5 and 40 hexdigits
\r
932 +_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
\r
933 +_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
\r
935 +# Each test should start with something like this, after copyright notices:
\r
937 +# test_description='Description of this test...
\r
938 +# This test checks if command xyzzy does the right thing...
\r
941 +[ "x$ORIGINAL_TERM" != "xdumb" ] && (
\r
942 + TERM=$ORIGINAL_TERM &&
\r
945 + tput bold >/dev/null 2>&1 &&
\r
946 + tput setaf 1 >/dev/null 2>&1 &&
\r
947 + tput sgr0 >/dev/null 2>&1
\r
951 +while test "$#" -ne 0
\r
954 + -d|--d|--de|--deb|--debu|--debug)
\r
955 + debug=t; shift ;;
\r
956 + -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
\r
957 + immediate=t; shift ;;
\r
958 + -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
\r
959 + GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
\r
960 + -h|--h|--he|--hel|--help)
\r
962 + -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
\r
963 + verbose=t; shift ;;
\r
964 + -q|--q|--qu|--qui|--quie|--quiet)
\r
965 + quiet=t; shift ;;
\r
967 + with_dashes=t; shift ;;
\r
973 + --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
\r
974 + valgrind=t; verbose=t; shift ;;
\r
976 + shift ;; # was handled already
\r
978 + root=$(expr "z$1" : 'z[^=]*=\(.*\)')
\r
981 + echo "error: unknown test option '$1'" >&2; exit 1 ;;
\r
985 +if test -n "$color"; then
\r
988 + TERM=$ORIGINAL_TERM
\r
991 + error) tput bold; tput setaf 1;; # bold red
\r
992 + skip) tput bold; tput setaf 2;; # bold green
\r
993 + pass) tput setaf 2;; # green
\r
994 + info) tput setaf 3;; # brown
\r
995 + *) test -n "$quiet" && return;;
\r
998 + printf "* %s" "$*"
\r
1005 + test -z "$1" && test -n "$quiet" && return
\r
1012 + say_color error "error: $*"
\r
1018 + say_color info "$*"
\r
1021 +test "${test_description}" != "" ||
\r
1022 +error "Test script did not set test_description."
\r
1024 +if test "$help" = "t"
\r
1026 + echo "$test_description"
\r
1031 +if test "$verbose" = "t"
\r
1035 + exec 4>/dev/null 3>/dev/null
\r
1046 + if test -n "$GIT_EXIT_OK"
\r
1050 + echo >&5 "FATAL: Unexpected exit with code $code"
\r
1058 +# The semantics of the editor variables are that of invoking
\r
1059 +# sh -c "$EDITOR \"$@\"" files ...
\r
1061 +# If our trash directory contains shell metacharacters, they will be
\r
1062 +# interpreted if we just set $EDITOR directly, so do a little dance with
\r
1063 +# environment variables to work around this.
\r
1065 +# In particular, quoting isn't enough, as the path may contain the same quote
\r
1066 +# that we're using.
\r
1067 +test_set_editor () {
\r
1068 + FAKE_EDITOR="$1"
\r
1069 + export FAKE_EDITOR
\r
1070 + EDITOR='"$FAKE_EDITOR"'
\r
1074 +test_decode_color () {
\r
1075 + sed -e 's/.\[1m/<WHITE>/g' \
\r
1076 + -e 's/.\[31m/<RED>/g' \
\r
1077 + -e 's/.\[32m/<GREEN>/g' \
\r
1078 + -e 's/.\[33m/<YELLOW>/g' \
\r
1079 + -e 's/.\[34m/<BLUE>/g' \
\r
1080 + -e 's/.\[35m/<MAGENTA>/g' \
\r
1081 + -e 's/.\[36m/<CYAN>/g' \
\r
1082 + -e 's/.\[m/<RESET>/g'
\r
1086 + perl -pe 'y/Q/\000/'
\r
1094 + sed -e 's/$/Q/' | tr Q '\015'
\r
1098 + tr '\015' Q | sed -e 's/Q$//'
\r
1102 + if test -z "${test_tick+set}"
\r
1104 + test_tick=1112911993
\r
1106 + test_tick=$(($test_tick + 60))
\r
1108 + GIT_COMMITTER_DATE="$test_tick -0700"
\r
1109 + GIT_AUTHOR_DATE="$test_tick -0700"
\r
1110 + export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
\r
1113 +# Call test_commit with the arguments "<message> [<file> [<contents>]]"
\r
1115 +# This will commit a file with the given contents and the given commit
\r
1116 +# message. It will also add a tag with <message> as name.
\r
1118 +# Both <file> and <contents> default to <message>.
\r
1121 + file=${2:-"$1.t"}
\r
1122 + echo "${3-$1}" > "$file" &&
\r
1123 + git add "$file" &&
\r
1125 + git commit -m "$1" &&
\r
1129 +# Call test_merge with the arguments "<message> <commit>", where <commit>
\r
1130 +# can be a tag pointing to the commit-to-merge.
\r
1134 + git merge -m "$1" "$2" &&
\r
1138 +# This function helps systems where core.filemode=false is set.
\r
1139 +# Use it instead of plain 'chmod +x' to set or unset the executable bit
\r
1140 +# of a file in the working directory and add it to the index.
\r
1144 + git update-index --add "--chmod=$@"
\r
1147 +# Use test_set_prereq to tell that a particular prerequisite is available.
\r
1148 +# The prerequisite can later be checked for in two ways:
\r
1150 +# - Explicitly using test_have_prereq.
\r
1152 +# - Implicitly by specifying the prerequisite tag in the calls to
\r
1153 +# test_expect_{success,failure,code}.
\r
1155 +# The single parameter is the prerequisite tag (a simple word, in all
\r
1156 +# capital letters by convention).
\r
1158 +test_set_prereq () {
\r
1159 + satisfied="$satisfied$1 "
\r
1163 +test_have_prereq () {
\r
1164 + case $satisfied in
\r
1166 + : yes, have it ;;
\r
1172 +# You are not expected to call test_ok_ and test_failure_ directly, use
\r
1173 +# the text_expect_* functions instead.
\r
1176 + test_success=$(($test_success + 1))
\r
1177 + say_color "" " ok $test_count: $@"
\r
1180 +test_failure_ () {
\r
1181 + test_failure=$(($test_failure + 1))
\r
1182 + say_color error "FAIL $test_count: $1"
\r
1184 + echo "$@" | sed -e 's/^/ /'
\r
1185 + test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
\r
1188 +test_known_broken_ok_ () {
\r
1189 + test_fixed=$(($test_fixed+1))
\r
1190 + say_color "" " FIXED $test_count: $@"
\r
1193 +test_known_broken_failure_ () {
\r
1194 + test_broken=$(($test_broken+1))
\r
1195 + say_color skip " still broken $test_count: $@"
\r
1199 + test "$debug" = "" || eval "$1"
\r
1203 + eval >&3 2>&4 "$1"
\r
1209 + test_count=$(($test_count+1))
\r
1211 + for skp in $GIT_SKIP_TESTS
\r
1213 + case $this_test.$test_count in
\r
1218 + if test -z "$to_skip" && test -n "$prereq" &&
\r
1219 + ! test_have_prereq "$prereq"
\r
1223 + case "$to_skip" in
\r
1225 + say_color skip >&3 "skipping test: $@"
\r
1226 + say_color skip "skip $test_count: $1"
\r
1235 +test_expect_failure () {
\r
1236 + test "$#" = 3 && { prereq=$1; shift; } || prereq=
\r
1237 + test "$#" = 2 ||
\r
1238 + error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
\r
1239 + if ! test_skip "$@"
\r
1241 + say >&3 "checking known breakage: $2"
\r
1243 + if [ "$?" = 0 -a "$eval_ret" = 0 ]
\r
1245 + test_known_broken_ok_ "$1"
\r
1247 + test_known_broken_failure_ "$1"
\r
1253 +test_expect_success () {
\r
1254 + test "$#" = 3 && { prereq=$1; shift; } || prereq=
\r
1255 + test "$#" = 2 ||
\r
1256 + error "bug in the test script: not 2 or 3 parameters to test-expect-success"
\r
1257 + if ! test_skip "$@"
\r
1259 + say >&3 "expecting success: $2"
\r
1261 + if [ "$?" = 0 -a "$eval_ret" = 0 ]
\r
1265 + test_failure_ "$@"
\r
1271 +test_expect_code () {
\r
1272 + test "$#" = 4 && { prereq=$1; shift; } || prereq=
\r
1273 + test "$#" = 3 ||
\r
1274 + error "bug in the test script: not 3 or 4 parameters to test-expect-code"
\r
1275 + if ! test_skip "$@"
\r
1277 + say >&3 "expecting exit code $1: $3"
\r
1279 + if [ "$?" = 0 -a "$eval_ret" = "$1" ]
\r
1283 + test_failure_ "$@"
\r
1289 +# test_external runs external test scripts that provide continuous
\r
1290 +# test output about their progress, and succeeds/fails on
\r
1291 +# zero/non-zero exit code. It outputs the test output on stdout even
\r
1292 +# in non-verbose mode, and announces the external script with "* run
\r
1293 +# <n>: ..." before running it. When providing relative paths, keep in
\r
1294 +# mind that all scripts run in "trash directory".
\r
1295 +# Usage: test_external description command arguments...
\r
1296 +# Example: test_external 'Perl API' perl ../path/to/test.pl
\r
1297 +test_external () {
\r
1298 + test "$#" = 4 && { prereq=$1; shift; } || prereq=
\r
1299 + test "$#" = 3 ||
\r
1300 + error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
\r
1303 + if ! test_skip "$descr" "$@"
\r
1305 + # Announce the script to reduce confusion about the
\r
1306 + # test output that follows.
\r
1307 + say_color "" " run $test_count: $descr ($*)"
\r
1308 + # Run command; redirect its stderr to &4 as in
\r
1309 + # test_run_, but keep its stdout on our stdout even in
\r
1310 + # non-verbose mode.
\r
1314 + test_ok_ "$descr"
\r
1316 + test_failure_ "$descr" "$@"
\r
1321 +# Like test_external, but in addition tests that the command generated
\r
1322 +# no output on stderr.
\r
1323 +test_external_without_stderr () {
\r
1324 + # The temporary file has no (and must have no) security
\r
1326 + tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
\r
1327 + stderr="$tmp/git-external-stderr.$$.tmp"
\r
1328 + test_external "$@" 4> "$stderr"
\r
1329 + [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
\r
1330 + descr="no stderr: $1"
\r
1332 + say >&3 "expecting no stderr from previous command"
\r
1333 + if [ ! -s "$stderr" ]; then
\r
1335 + test_ok_ "$descr"
\r
1337 + if [ "$verbose" = t ]; then
\r
1338 + output=`echo; echo Stderr is:; cat "$stderr"`
\r
1342 + # rm first in case test_failure exits.
\r
1344 + test_failure_ "$descr" "$@" "$output"
\r
1348 +# This is not among top-level (test_expect_success | test_expect_failure)
\r
1349 +# but is a prefix that can be used in the test script, like:
\r
1351 +# test_expect_success 'complain and die' '
\r
1352 +# do something &&
\r
1353 +# do something else &&
\r
1354 +# test_must_fail git checkout ../outerspace
\r
1357 +# Writing this as "! git checkout ../outerspace" is wrong, because
\r
1358 +# the failure could be due to a segv. We want a controlled failure.
\r
1360 +test_must_fail () {
\r
1362 + test $? -gt 0 -a $? -le 129 -o $? -gt 192
\r
1365 +# test_cmp is a helper function to compare actual and expected output.
\r
1366 +# You can use it like:
\r
1368 +# test_expect_success 'foo works' '
\r
1369 +# echo expected >expected &&
\r
1371 +# test_cmp expected actual
\r
1374 +# This could be written as either "cmp" or "diff -u", but:
\r
1375 +# - cmp's output is not nearly as easy to read as diff -u
\r
1376 +# - not all diff versions understand "-u"
\r
1379 + $GIT_TEST_CMP "$@"
\r
1382 +# Most tests can use the created repository, but some may need to create more.
\r
1383 +# Usage: test_create_repo <directory>
\r
1384 +test_create_repo () {
\r
1385 + test "$#" = 1 ||
\r
1386 + error "bug in the test script: not 1 parameter to test-create-repo"
\r
1389 + mkdir -p "$repo"
\r
1390 + cd "$repo" || error "Cannot setup test environment"
\r
1391 + "$GIT_EXEC_PATH/git-init" "--template=$TEST_DIRECTORY/../templates/blt/" >&3 2>&4 ||
\r
1392 + error "cannot run git init -- have you built things yet?"
\r
1393 + mv .git/hooks .git/hooks-disabled
\r
1399 + test_results_dir="$TEST_DIRECTORY/test-results"
\r
1400 + mkdir -p "$test_results_dir"
\r
1401 + test_results_path="$test_results_dir/${0%.sh}-$$"
\r
1403 + echo "total $test_count" >> $test_results_path
\r
1404 + echo "success $test_success" >> $test_results_path
\r
1405 + echo "fixed $test_fixed" >> $test_results_path
\r
1406 + echo "broken $test_broken" >> $test_results_path
\r
1407 + echo "failed $test_failure" >> $test_results_path
\r
1408 + echo "" >> $test_results_path
\r
1410 + if test "$test_fixed" != 0
\r
1412 + say_color pass "fixed $test_fixed known breakage(s)"
\r
1414 + if test "$test_broken" != 0
\r
1416 + say_color error "still have $test_broken known breakage(s)"
\r
1417 + msg="remaining $(($test_count-$test_broken)) test(s)"
\r
1419 + msg="$test_count test(s)"
\r
1421 + case "$test_failure" in
\r
1423 + say_color pass "passed all $msg"
\r
1425 + test -d "$remove_trash" &&
\r
1426 + cd "$(dirname "$remove_trash")" &&
\r
1427 + rm -rf "$(basename "$remove_trash")"
\r
1432 + say_color error "failed $test_failure among $msg"
\r
1438 +# Test the binaries we have just built. The tests are kept in
\r
1439 +# t/ subdirectory and are run in 'trash directory' subdirectory.
\r
1440 +TEST_DIRECTORY=$(pwd)
\r
1441 +if test -n "$valgrind"
\r
1443 + make_symlink () {
\r
1445 + test "$1" = "$(readlink "$2")" || {
\r
1446 + # be super paranoid
\r
1447 + if mkdir "$2".lock
\r
1450 + ln -s "$1" "$2" &&
\r
1453 + while test -d "$2".lock
\r
1455 + say "Waiting for lock on $2."
\r
1462 + make_valgrind_symlink () {
\r
1463 + # handle only executables
\r
1464 + test -x "$1" || return
\r
1466 + base=$(basename "$1")
\r
1467 + symlink_target=$TEST_DIRECTORY/../$base
\r
1468 + # do not override scripts
\r
1469 + if test -x "$symlink_target" &&
\r
1470 + test ! -d "$symlink_target" &&
\r
1471 + test "#!" != "$(head -c 2 < "$symlink_target")"
\r
1473 + symlink_target=../valgrind.sh
\r
1477 + symlink_target=../unprocessed-script
\r
1479 + # create the link, or replace it if it is out of date
\r
1480 + make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
\r
1483 + # override all git executables in TEST_DIRECTORY/..
\r
1484 + GIT_VALGRIND=$TEST_DIRECTORY/valgrind
\r
1485 + mkdir -p "$GIT_VALGRIND"/bin
\r
1486 + for file in $TEST_DIRECTORY/../git* $TEST_DIRECTORY/../test-*
\r
1488 + make_valgrind_symlink $file
\r
1492 + for path in $PATH
\r
1494 + ls "$path"/git-* 2> /dev/null |
\r
1497 + make_valgrind_symlink "$file"
\r
1501 + PATH=$GIT_VALGRIND/bin:$PATH
\r
1502 + GIT_EXEC_PATH=$GIT_VALGRIND/bin
\r
1503 + export GIT_VALGRIND
\r
1504 +elif test -n "$GIT_TEST_INSTALLED" ; then
\r
1505 + GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
\r
1506 + error "Cannot run git from $GIT_TEST_INSTALLED."
\r
1507 + PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH
\r
1508 + GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
\r
1509 +else # normal case, use ../bin-wrappers only unless $with_dashes:
\r
1510 + git_bin_dir="$TEST_DIRECTORY/../bin-wrappers"
\r
1511 + if ! test -x "$git_bin_dir/git" ; then
\r
1512 + if test -z "$with_dashes" ; then
\r
1513 + say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
\r
1517 + PATH="$git_bin_dir:$PATH"
\r
1518 + GIT_EXEC_PATH=$TEST_DIRECTORY/..
\r
1519 + if test -n "$with_dashes" ; then
\r
1520 + PATH="$TEST_DIRECTORY/..:$PATH"
\r
1523 +GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
\r
1525 +GIT_CONFIG_NOSYSTEM=1
\r
1526 +GIT_CONFIG_NOGLOBAL=1
\r
1527 +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL
\r
1529 +. ../GIT-BUILD-OPTIONS
\r
1531 +GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git
\r
1532 +export GITPERLLIB
\r
1533 +test -d ../templates/blt || {
\r
1534 + error "You haven't built things yet, have you?"
\r
1537 +if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON"
\r
1539 + GITPYTHONLIB="$(pwd)/../git_remote_helpers/build/lib"
\r
1540 + export GITPYTHONLIB
\r
1541 + test -d ../git_remote_helpers/build || {
\r
1542 + error "You haven't built git_remote_helpers yet, have you?"
\r
1546 +if ! test -x ../test-chmtime; then
\r
1547 + echo >&2 'You need to build test-chmtime:'
\r
1548 + echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
\r
1552 +# Test repository
\r
1553 +test="trash directory.$(basename "$0" .sh)"
\r
1554 +test -n "$root" && test="$root/$test"
\r
1556 +/*) TRASH_DIRECTORY="$test" ;;
\r
1557 + *) TRASH_DIRECTORY="$TEST_DIRECTORY/$test" ;;
\r
1559 +test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
\r
1560 +rm -fr "$test" || {
\r
1562 + echo >&5 "FATAL: Cannot prepare test area"
\r
1566 +test_create_repo "$test"
\r
1567 +# Use -P to resolve symlinks in our working directory so that the cwd
\r
1568 +# in subprocesses like git equals our $PWD (for pathname comparisons).
\r
1569 +cd -P "$test" || exit 1
\r
1571 +this_test=${0##*/}
\r
1572 +this_test=${this_test%%-*}
\r
1573 +for skp in $GIT_SKIP_TESTS
\r
1576 + for skp in $GIT_SKIP_TESTS
\r
1578 + case "$this_test" in
\r
1583 + case "$to_skip" in
\r
1585 + say_color skip >&3 "skipping test $this_test altogether"
\r
1586 + say_color skip "skip all tests in $this_test"
\r
1591 +# Provide an implementation of the 'yes' utility
\r
1606 +# Fix some commands on Windows
\r
1607 +case $(uname -s) in
\r
1609 + # Windows has its own (incompatible) sort and find
\r
1611 + /usr/bin/sort "$@"
\r
1614 + /usr/bin/find "$@"
\r
1619 + # git sees Windows-style pwd
\r
1623 + # no POSIX permissions
\r
1624 + # backslashes in pathspec are converted to '/'
\r
1625 + # exec does not inherit the PID
\r
1628 + test_set_prereq POSIXPERM
\r
1629 + test_set_prereq BSLASHPSPEC
\r
1630 + test_set_prereq EXECKEEPSPID
\r
1634 +test -z "$NO_PERL" && test_set_prereq PERL
\r
1635 +test -z "$NO_PYTHON" && test_set_prereq PYTHON
\r
1637 +# test whether the filesystem supports symbolic links
\r
1638 +ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
\r