Skip to content

Commit

Permalink
test-lib.sh: introduce test_commit() and test_merge() helpers
Browse files Browse the repository at this point in the history
Often we just need to add a commit with a given (short) name, that will
be tagged with the same name.  Now, relatively complicated graphs can be
constructed easily and in a clear fashion:

	test_commit A &&
	test_commit B &&
	git checkout A &&
	test_commit C &&
	test_merge D B

will construct this graph:

	A - B
	  \   \
	    C - D

For simplicity, files whose name is the lower case version of the commit
message (to avoid a warning about ambiguous names) will be committed, with
the corresponding commit messages as contents.

If you need to provide a different file/different contents, you can use
the more explicit form

	test_commit $MESSAGE $FILENAME $CONTENTS

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jan 29, 2009
1 parent 03af087 commit 0088496
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions t/README
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,24 @@ library for your script to use.
is to summarize successes and failures in the test script and
exit with an appropriate error code.

- test_tick

Make commit and tag names consistent by setting the author and
committer times to defined stated. Subsequent calls will
advance the times by a fixed amount.

- test_commit <message> [<filename> [<contents>]]

Creates a commit with the given message, committing the given
file with the given contents (default for both is to reuse the
message string), and adds a tag (again reusing the message
string as name). Calls test_tick to make the SHA-1s
reproducible.

- test_merge <message> <commit-or-tag>

Merges the given rev using the given message. Like test_commit,
creates a tag and calls test_tick before committing.

Tips for Writing Tests
----------------------
Expand Down
25 changes: 25 additions & 0 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ test_tick () {
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
}

# Call test_commit with the arguments "<message> [<file> [<contents>]]"
#
# This will commit a file with the given contents and the given commit
# message. It will also add a tag with <message> as name.
#
# Both <file> and <contents> default to <message>.

test_commit () {
file=${2:-$(echo "$1" | tr 'A-Z' 'a-z')}
echo "${3-$1}" > "$file" &&
git add "$file" &&
test_tick &&
git commit -m "$1" &&
git tag "$1"
}

# Call test_merge with the arguments "<message> <commit>", where <commit>
# can be a tag pointing to the commit-to-merge.

test_merge () {
test_tick &&
git merge -m "$1" "$2" &&
git tag "$1"
}

# You are not expected to call test_ok_ and test_failure_ directly, use
# the text_expect_* functions instead.

Expand Down

0 comments on commit 0088496

Please sign in to comment.