@matheusbsbs / matheus-bagliano / commits / 008849689e
Fork 0

test-lib.sh: introduce test_commit() and test_merge() helpers

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>

Johannes Schindelin committed Jan 27, 2009 at 23:34 UTC 008849689e04e774aa7b194cd690405761e2383a
2 files changed +43
t/README
+18
@@ -212,6 +212,24 @@ library for your script to use.
212 is to summarize successes and failures in the test script and
213 exit with an appropriate error code.
214
215 + - test_tick
216 +
217 + Make commit and tag names consistent by setting the author and
218 + committer times to defined stated. Subsequent calls will
219 + advance the times by a fixed amount.
220 +
221 + - test_commit <message> [<filename> [<contents>]]
222 +
223 + Creates a commit with the given message, committing the given
224 + file with the given contents (default for both is to reuse the
225 + message string), and adds a tag (again reusing the message
226 + string as name). Calls test_tick to make the SHA-1s
227 + reproducible.
228 +
229 + - test_merge <message> <commit-or-tag>
230 +
231 + Merges the given rev using the given message. Like test_commit,
232 + creates a tag and calls test_tick before committing.
233
234 Tips for Writing Tests
235 ----------------------
t/test-lib.sh
+25
@@ -193,6 +193,31 @@ test_tick () {
193 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
194 }
195
196 +# Call test_commit with the arguments "<message> [<file> [<contents>]]"
197 +#
198 +# This will commit a file with the given contents and the given commit
199 +# message. It will also add a tag with <message> as name.
200 +#
201 +# Both <file> and <contents> default to <message>.
202 +
203 +test_commit () {
204 + file=${2:-$(echo "$1" | tr 'A-Z' 'a-z')}
205 + echo "${3-$1}" > "$file" &&
206 + git add "$file" &&
207 + test_tick &&
208 + git commit -m "$1" &&
209 + git tag "$1"
210 +}
211 +
212 +# Call test_merge with the arguments "<message> <commit>", where <commit>
213 +# can be a tag pointing to the commit-to-merge.
214 +
215 +test_merge () {
216 + test_tick &&
217 + git merge -m "$1" "$2" &&
218 + git tag "$1"
219 +}
220 +
221 # You are not expected to call test_ok_ and test_failure_ directly, use
222 # the text_expect_* functions instead.
223