test-lib: add the test_pause convenience function

Since 781f76b15 (test-lib: redirect stdin of tests) you can't simply put a "bash &&" into a test for debugging purposes anymore. Instead you'll have to use "bash <&6 >&3 2>&4". As that invocation is not that easy to remember add the test_pause convenience function. It invokes "$SHELL_PATH" to provide a sane shell for the user. This function also checks if the -v flag is given and will error out if that is not the case instead of letting the test hang until ^D is pressed. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Jan 17, 2012 at 22:04 UTC c4d2539af751ed394ee68c02fe688e75c647c5fe
2 files changed +26
t/README
+13
@@ -548,6 +548,19 @@ library for your script to use.
548 ...
549 '
550
551 + - test_pause
552 +
553 + This command is useful for writing and debugging tests and must be
554 + removed before submitting. It halts the execution of the test and
555 + spawns a shell in the trash directory. Exit the shell to continue
556 + the test. Example:
557 +
558 + test_expect_success 'test' '
559 + git do-something >actual &&
560 + test_pause &&
561 + test_cmp expected actual
562 + '
563 +
564 Prerequisites
565 -------------
566
t/test-lib.sh
+13
@@ -329,6 +329,19 @@ test_tick () {
329 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
330 }
331
332 +# Stop execution and start a shell. This is useful for debugging tests and
333 +# only makes sense together with "-v".
334 +#
335 +# Be sure to remove all invocations of this command before submitting.
336 +
337 +test_pause () {
338 + if test "$verbose" = t; then
339 + "$SHELL_PATH" <&6 >&3 2>&4
340 + else
341 + error >&5 "test_pause requires --verbose"
342 + fi
343 +}
344 +
345 # Call test_commit with the arguments "<message> [<file> [<contents>]]"
346 #
347 # This will commit a file with the given contents and the given commit