From: Ævar Arnfjörð Bjarmason Date: Fri, 2 Jul 2010 14:59:49 +0000 (+0000) Subject: t/README: Document the do's and don'ts of tests X-Git-Tag: v1.7.2-rc2~1^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/20873f45e7fe23a8530e643d2eea9566d57f2fd4 t/README: Document the do's and don'ts of tests Add a "Do's, don'ts & things to keep in mind" subsection to the "Writing Tests" documentation. Much of this is based on Junio C Hamano's "Test your stuff" section in <7vhbkj2kcr.fsf@alter.siamese.dyndns.org>. I turned it into a list of do's and don'ts to make it easier to skim it, and integrated my note that a TAP harness will get confused if you print "ok" or "not ok" at the beginning of a line. Thad had to be fixed in 335f87871fe5aa6b3fd55b2b4e80f16fe9681483 when TAP support was introduced. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- diff --git a/t/README b/t/README index 4079635879..e4816572f2 100644 --- a/t/README +++ b/t/README @@ -231,6 +231,84 @@ This test harness library does the following things: consistently when command line arguments --verbose (or -v), --debug (or -d), and --immediate (or -i) is given. +Do's, don'ts & things to keep in mind +------------------------------------- + +Here's a few examples of things you probably should and shouldn't do +when writing tests. + +Do: + + - Put as much code as possible inside test_expect_success and other + assertions. + + Even code that isn't a test per se, but merely some setup code + should be inside a test assertion if at all possible. Test scripts + should only have trivial code outside of their assertions. + + - Chain your test assertions + + Write test code like this: + + git merge foo && + git push bar && + test ... + + Instead of: + + git merge hla + git push gh + test ... + + That way all of the commands in your tests will succeed or fail. If + you must ignore the return value of something (e.g. the return + value of export is unportable) it's best to indicate so explicitly + with a semicolon: + + export HLAGH; + git merge hla && + git push gh && + test ... + +Don't: + + - exit() within a