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

Test suite

From
Petr Baudis <pasky@ucw.cz>
Date
May 11, 2005, 22:40 UTC
Message-ID
<20050511224044.GI22686@pasky.ji.cz>
In-Reply-To
<7vd5rxquo5.fsf@assigned-by-dhcp.cox.net>

Dear diary, on Thu, May 12, 2005 at 12:12:10AM CEST, I got a letter where Junio C Hamano <junkio@cox.net> told me that...

> I've added test subdirectory and two tests to check the above
> problems are fixed.

I'd prefer introduction of the infrastructure for this in a separate commit. I'll focus on it here; I will have a look at the checkout-cache stuff tomorrow.

> Created: t/t0000.sh (mode:100755)
> --- /dev/null
> +++ b/t/t0000.sh
I'd prefer some better name for this. What about testlib.sh?
Show 5 quoted lines
> @@ -0,0 +1,38 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2005 Junio C Hamano
> +#
A short description here would be nice.
> +case "${verbose+set}" in
> +set)	say= ;;
> +*)	say=: ;;
> +esac
Perhaps set $verbose if -v was passed or something.

Looking at how you use it, I wouldn't run the command at all if not verbose.

Show 8 quoted lines
> Created: t/t1000-checkout-cache.sh (mode:100755)
> --- /dev/null
> +++ b/t/t1000-checkout-cache.sh
> @@ -0,0 +1,42 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2005 Junio C Hamano
> +#

I think each test in the suite should have a short summary of its focus in the top comment.

> +. ./t0000.sh
> +git-init-db 2>/dev/null || exit

I'd do this in testlib.sh (you might well blast it away and redo it when testing init-db).

Show 6 quoted lines
> +echo >&2 "* checkout-cache sans -f"
> +git-checkout-cache -a
> +case "$?" in
> +0)	echo >&2 "*** bug: should not have succeeded." ;;
> +*)	echo >&2 "*** ok: failed as expected." ;;
> +esac
And this essentially repeats all over and over.
What about something like
cmdtest "sans -f" git-checkout-cache -a
Show 7 quoted lines
> +if test -f path0 && test -d path1 && test -f path1/file1
> +then
> +	echo >&2 "*** ok: checked out correctly."
> +else
> +	echo >&2 "*** bug: checkout failed."
> +	exit 1
> +fi
We might get a good function for this later too, for now I'd propose
if test -f path0 && test -d path1 && test -f path1/file1; then
	testok "checkout"
else
	testfail "checkout" # non-fatal test failure
	testfatal "checkout" # fatal test failure, die right away
fi
And at the end the script, you should do
exit $teststatus
which is set to non-zero anytime testfail was invoked.
Show 12 quoted lines
> Created: t/t1001-checkout-cache.sh (mode:100755)
> --- /dev/null
> +++ b/t/t1001-checkout-cache.sh
> @@ -0,0 +1,64 @@
> +show_files() {
> +	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 /'
> +	git-ls-files --stage |
> +	sed -e 's/^\([0-9]*\) [0-9a-f]* [0-3] /ca: \1 /'
> +	git-ls-tree -r "$1" |
> +	sed -e 's/^\([0-9]*\)	[^ ]*	[0-9a-f]*	/tr: \1 /'
> +}
Ugh. I think a comment would be suitable here. ;-)
Show 5 quoted lines
> +mkdir path0
> +date >path0/file0
> +git-update-cache --add path0/file0
> +echo >&2 "* initial state: one file under one directory"
> +tree1=$(git-write-tree)

cmdtest --capture-stdout "one file under one directory" git-write-tree tree1=$(cat $teststdout)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 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.