Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/t/README
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-04-29 01:49:55 +0300
committerJunio C Hamano <gitster@pobox.com>2020-04-29 01:49:55 +0300
commitb07c72100f88315d6abef235cee7428fca0886b5 (patch)
tree909cf1aa4165308fb4d53ccb7669997ba76c0470 /t/README
parent28ba5a7b27b8a16e44b760196fb09a016c6713d6 (diff)
parent7cc112dc95fd75ba230ad424de622c9d1c1a8b73 (diff)
Merge branch 'jc/doc-test-leaving-early'
Document the recommended way to abort a failing test early (e.g. by exiting a loop), which is to say "return 1". * jc/doc-test-leaving-early: t/README: suggest how to leave test early with failure
Diffstat (limited to 't/README')
-rw-r--r--t/README35
1 files changed, 35 insertions, 0 deletions
diff --git a/t/README b/t/README
index d12efcd3a4..13747f1344 100644
--- a/t/README
+++ b/t/README
@@ -547,6 +547,41 @@ Here are the "do's:"
reports "ok" or "not ok" to the end user running the tests. Under
--verbose, they are shown to help debug the tests.
+ - Be careful when you loop
+
+ You may need to verify multiple things in a loop, but the
+ following does not work correctly:
+
+ test_expect_success 'test three things' '
+ for i in one two three
+ do
+ test_something "$i"
+ done &&
+ test_something_else
+ '
+
+ Because the status of the loop itself is the exit status of the
+ test_something in the last round, the loop does not fail when
+ "test_something" for "one" or "two" fails. This is not what you
+ want.
+
+ Instead, you can break out of the loop immediately when you see a
+ failure. Because all test_expect_* snippets are executed inside
+ a function, "return 1" can be used to fail the test immediately
+ upon a failure:
+
+ test_expect_success 'test three things' '
+ for i in one two three
+ do
+ test_something "$i" || return 1
+ done &&
+ test_something_else
+ '
+
+ Note that we still &&-chain the loop to propagate failures from
+ earlier commands.
+
+
And here are the "don'ts:"
- Don't exit() within a <script> part.