git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Test suite

From
Junio C Hamano <junkio@cox.net>
Date
May 12, 2005, 00:01 UTC
Message-ID
<7vu0l9nwgx.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<20050511224044.GI22686@pasky.ji.cz>

Commit 1da683e1247046796a094c4917bc0c4591530272 Author Junio C Hamano <junkio@cox.net>, Wed May 11 16:59:35 2005 -0700 Committer Junio C Hamano <junkio@cox.net>, Wed May 11 16:59:35 2005 -0700

Test suite: infrastructure and examples.

This adds the test suite infrastructure with two example tests. The current git-checkout-cache the example tests would fail this test and will be corrected in a separate patch.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
Created: t/t1000-checkout-cache.sh (mode:100755)
--- /dev/null
+++ b/t/t1000-checkout-cache.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Junio C Hamano
+#
+
+. ./test-lib.sh
+test_description "$@" 'git-checkout-cache test.
+
+This test registers the following filesystem structure in the
+cache:
+
+    path0       - a file
+    path1/file1 - a file in a directory
+
+And then tries to checkout in a work tree that has the following:
+
+    path0/file0 - a file in a directory
+    path1       - a file
+
+The git-checkout-cache command should fail when attempting to checkout
+path0, finding it is occupied by a directory, and path1/file1, finding
+path1 is occupied by a non-directory.  With "-f" flag, it should remove
+the conflicting paths and succeed.
+'
+
+date >path0
+mkdir path1
+date >path1/file1
+git-update-cache --add path0 path1/file1
+test_debug 'git-ls-files --stage'
+
+rm -fr path0 path1
+mkdir path0
+date >path0/file0
+date >path1
+test_debug 'git-ls-files --stage'
+test_debug 'find path*'
+
+test_expect_failure 'git-checkout-cache -a'
+test_debug 'find path*'
+
+test_expect_success 'git-checkout-cache -f -a'
+test_debug 'find path*'
+
+if test -f path0 && test -d path1 && test -f path1/file1
+then
+	test_ok "checkout successful"
+else
+	test_failure "checkout failed"
+fi
+
+test_done
+
+
Created: t/t1001-checkout-cache.sh (mode:100755)
--- /dev/null
+++ b/t/t1001-checkout-cache.sh
@@ -0,0 +1,76 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Junio C Hamano
+#
+
+. ./test-lib.sh
+test_description "$@" 'git-checkout-cache test.
+
+This test registers the following filesystem structure in the cache:
+
+    path0/file0	- a file in a directory
+    path1/file1 - a file in a directory
+
+and attempts to check it out when the work tree has:
+
+    path0/file0 - a file in a directory
+    path1       - a symlink pointing at "path0"
+
+Checkout cache should fail to extract path1/file1 because the leading
+path path1 is occupied by a non-directory.  With "-f" it should remove
+the symlink path1 and create directory path1 and file path1/file1.
+'
+
+show_files() {
+	# show filesystem files, just [-dl] for type and name
+	find path? -ls |
+	sed -e 's/^[0-9]* * [0-9]* * \([-bcdl]\)[^ ]* *[0-9]* *[^ ]* *[^ ]* *[0-9]* [A-Z][a-z][a-z] [0-9][0-9] [^ ]* /fs: \1 /'
+	# what's in the cache, just mode and name
+	git-ls-files --stage |
+	sed -e 's/^\([0-9]*\) [0-9a-f]* [0-3] /ca: \1 /'
+	# what's in the tree, just mode and name.
+	git-ls-tree -r "$1" |
+	sed -e 's/^\([0-9]*\)	[^ ]*	[0-9a-f]*	/tr: \1 /'
+}
+
+mkdir path0
+date >path0/file0
+git-update-cache --add path0/file0
+tree1=$(git-write-tree)
+test_debug 'show_files $tree1'
+
+mkdir path1
+date >path1/file1
+git-update-cache --add path1/file1
+tree2=$(git-write-tree)
+test_debug 'show_files $tree2'
+
+rm -fr path1
+git-read-tree -m $tree1
+git-checkout-cache -f -a
+test_debug 'show_files $tree1'
+
+ln -s path0 path1
+git-update-cache --add path1
+tree3=$(git-write-tree)
+test_debug 'show_files $tree3'
+
+# Morten says "Got that?" here.
+# Test begins.
+
+git-read-tree $tree2
+test_expect_success 'git-checkout-cache -f -a'
+test_debug show_files $tree2
+
+if test ! -h path0 && test -d path0 &&
+   test ! -h path1 && test -d path1 &&
+   test ! -h path0/file0 && test -f path0/file0 &&
+   test ! -h path1/file1 && test -f path1/file1
+then
+    test_ok "checked out correctly."
+else
+    test_failure "did not check out correctly."
+fi
+
+test_done
+
Created: t/test-lib.sh (mode:100755)
--- /dev/null
+++ b/t/test-lib.sh
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Junio C Hamano
+#
+
+# For repeatability, reset the environment to known value.
+export LANG C
+export TZ UTC
+unset AUTHOR_DATE
+unset AUTHOR_EMAIL
+unset AUTHOR_NAME
+unset COMMIT_AUTHOR_EMAIL
+unset COMMIT_AUTHOR_NAME
+unset GIT_ALTERNATE_OBJECT_DIRECTORIES
+unset GIT_AUTHOR_DATE
+unset GIT_AUTHOR_EMAIL
+unset GIT_AUTHOR_NAME
+unset GIT_COMMITTER_EMAIL
+unset GIT_COMMITTER_NAME
+unset GIT_DIFF_OPTS
+unset GIT_DIR
+unset GIT_EXTERNAL_DIFF
+unset GIT_INDEX_FILE
+unset GIT_OBJECT_DIRECTORY
+unset SHA1_FILE_DIRECTORIES
+unset SHA1_FILE_DIRECTORY
+
+# Each test should start with something like this, after copyright notices:
+#
+# . ./testlib.sh
+# test_description "$@" 'Description of this test...
+# This test checks if command xyzzy does the right thing...
+# '
+#
+
+test_description () {
+	while case "$#" in 0) break;; esac
+	do
+		case "$1" in
+		-d|--d|--de|--deb|--debu|--debug)
+			debug=t; shift ;;
+		-h|--h|--he|--hel|--help)
+			eval echo '"$'$#'"'
+			exit 0
+			;;
+		*)
+			break ;;
+		esac
+	done
+	test_failure=0
+}
+
+say () {
+	echo "* $*"
+}
+
+test_debug () {
+	case "$debug" in '') ;; ?*) eval "$*" ;; esac
+}
+
+test_ok () {
+	echo "* $*";
+}
+
+test_failure () {
+	echo "* $*";
+	test_failure=1;
+}
+
+test_expect_failure () {
+	say "expecting failure: $1"
+	eval "$1"
+	case $? in
+	0)	test_failure "did not fail as expected" ;;
+	*) 	test_ok "failed as expected" ;;
+	esac
+}
+
+test_expect_success () {
+	say "expecting success: $1"
+	eval "$1"
+	case $? in
+	0) 	test_ok "succeeded as expected" ;;
+	*)	test_failure "did not succeed as expected" ;;
+	esac
+}
+
+test_done () {
+	case "$test_failure" in
+	0)	exit 0 ;;
+	'')	echo "*** test script did not start with test_description";
+		exit 2 ;;
+	*)	exit 1 ;;
+	esac
+}
+
+# Test the binaries we have just built.  The tests are kept in
+# t/ subdirectory and are run in test-repo subdirectory.
+PATH=$(pwd)/..:$PATH
+
+# Test repository
+test=test-repo
+rm -fr "$test"
+mkdir "$test"
+cd "$test"
+git-init-db 2>/dev/null || error "cannot run git-init-db"
------------------------------------------------
Previous: Petr BaudisNext: Petr Baudis
Message 11 of 19 in “"git-checkout-cache -f -a" failure”
  1. Morten WelinderMay 9, 2005
  2. Junio C HamanoMay 10, 2005
  3. Morten WelinderMay 10, 2005
  4. Junio C HamanoMay 10, 2005
  5. Petr BaudisMay 10, 2005
  6. Junio C HamanoMay 11, 2005
  7. Morten WelinderMay 11, 2005
  8. Junio C HamanoMay 11, 2005
  9. Junio C HamanoMay 11, 2005
  10. Test suitePetr Baudis, May 11, 2005
  11. Test suiteJunio C Hamano, May 12, 2005
  12. Petr BaudisMay 12, 2005
  13. Junio C HamanoMay 12, 2005
  14. Fix git-diff-files for symlinks.Junio C Hamano, May 12, 2005
  15. 0/3 Core GIT fixes and additions.Junio C Hamano, May 13, 2005
  16. checkout-cache fixJunio C Hamano, May 12, 2005
  17. Petr BaudisMay 12, 2005
  18. Junio C HamanoMay 12, 2005
  19. Junio C HamanoMay 11, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.