{"thread":{"id":"13747","subject":"[PATCH] t/test-lib.sh: add test_external and test_external_without_stderr","startedAt":"2008-05-31T23:36:15Z","lastAt":"2008-06-03T00:59:38Z","messageCount":3,"participants":["Lea Wiemann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"78256","messageId":"1212276975-27428-1-git-send-email-LeWiemann@gmail.com","threadId":"13747","inReplyTo":null,"subject":"[PATCH] t/test-lib.sh: add test_external and test_external_without_stderr","fromName":"Lea Wiemann","fromEmail":"lewiemann@gmail.com","sentAt":"2008-05-31T23:36:15Z","receivedAt":"2008-05-31T23:36:15Z","isPatch":true,"sender":{"key":"lewiemann@gmail.com","avatar":null},"body":"This is for running external test scripts in other programming\nlanguages that provide continuous output about their tests.  Using\ntest_expect_success (like \"test_expect_success 'description' 'perl\ntest-script.pl'\") doesn't suffice here because test_expect_success\neats stdout in non-verbose mode, which is not fixable without major\nfile descriptor trickery.\n\nSigned-off-by: Lea Wiemann <LeWiemann@gmail.com>\n---\n t/test-lib.sh |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 58 insertions(+), 0 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 7a8bd27..99b63da 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -302,6 +302,64 @@ test_expect_code () {\n \techo >&3 \"\"\n }\n \n+# test_external runs external test scripts that provide continuous\n+# test output about their progress, and succeeds/fails on\n+# zero/non-zero exit code.  It outputs the test output on stdout even\n+# in non-verbose mode, and announces the external script with \"* run\n+# <n>: ...\" before running it.  When providing relative paths, keep in\n+# mind that all scripts run in \"trash directory\".\n+# Usage: test_external description command arguments...\n+# Example: test_external 'Perl API' perl ../path/to/test.pl\n+test_external () {\n+\ttest \"$#\" -eq 3 ||\n+\terror >&5 \"bug in the test script: not 3 parameters to test_external\"\n+\tdescr=\"$1\"\n+\tshift\n+\tif ! test_skip \"$descr\" \"$@\"\n+\tthen\n+\t\t# Announce the script to reduce confusion about the\n+\t\t# test output that follows.\n+\t\tsay_color \"\" \" run $(expr \"$test_count\" + 1): $descr ($*)\"\n+\t\t# Run command; redirect its stderr to &4 as in\n+\t\t# test_run_, but keep its stdout on our stdout even in\n+\t\t# non-verbose mode.\n+\t\t\"$@\" 2>&4\n+\t\tif [ \"$?\" = 0 ]\n+\t\tthen\n+\t\t\ttest_ok_ \"$descr\"\n+\t\telse\n+\t\t\ttest_failure_ \"$descr\" \"$@\"\n+\t  \tfi\n+\tfi\n+}\n+\n+# Like test_external, but in addition tests that the command generated\n+# no output on stderr.\n+test_external_without_stderr () {\n+\t# The temporary file has no (and must have no) security\n+\t# implications.\n+\ttmp=\"$TMPDIR\"; if [ -z \"$tmp\" ]; then tmp=/tmp; fi\n+\tstderr=\"$tmp/git-external-stderr.$$.tmp\"\n+\ttest_external \"$@\" 4> \"$stderr\"\n+\t[ -f \"$stderr\" ] || eror \"Internal error: $stderr disappeared.\"\n+\tdescr=\"no stderr: $1\"\n+\tshift\n+\tsay >&3 \"expecting no stderr from previous command\"\n+\tif [ ! -s \"$stderr\" ]; then\n+\t\trm \"$stderr\"\n+\t\ttest_ok_ \"$descr\"\n+\telse\n+\t\tif [ \"$verbose\" = t ]; then\t    \t\n+\t\t    output=`echo; echo Stderr is:; cat \"$stderr\"`\n+\t\telse\n+\t\t    output=\n+\t\tfi\n+\t\t# rm first in case test_failure exits.\n+\t\trm \"$stderr\"\n+\t\ttest_failure_ \"$descr\" \"$@\" \"$output\"\n+        fi\n+}\n+\n # This is not among top-level (test_expect_success | test_expect_failure)\n # but is a prefix that can be used in the test script, like:\n #\n-- \n1.5.5.GIT\n"},{"id":"78257","messageId":"4841E20B.1040109@gmail.com","threadId":"13747","inReplyTo":"1212276975-27428-1-git-send-email-LeWiemann@gmail.com","subject":"Re: [PATCH] t/test-lib.sh: add test_external and test_external_without_stderr","fromName":"Lea Wiemann","fromEmail":"lewiemann@gmail.com","sentAt":"2008-05-31T23:40:59Z","receivedAt":"2008-05-31T23:40:59Z","isPatch":true,"sender":{"key":"lewiemann@gmail.com","avatar":null},"body":"Lea Wiemann wrote:\n> Subject: [PATCH] t/test-lib.sh: add test_external and test_external_without_stderr\n\nYikes, hit send-email too early again. :(  Anyways, I just wanted to say \nthat I've tested both functions for both the success and failure case \n(with my first version of a Git.pm test suite, written with Test::More, \nwhich I'll post later when it's finished).\n\n-- Lea\n"},{"id":"78448","messageId":"4844977A.60003@gmail.com","threadId":"13747","inReplyTo":"1212276975-27428-1-git-send-email-LeWiemann@gmail.com","subject":"Re: [PATCH] t/test-lib.sh: add test_external and test_external_without_stderr","fromName":"Lea Wiemann","fromEmail":"lewiemann@gmail.com","sentAt":"2008-06-03T00:59:38Z","receivedAt":"2008-06-03T00:59:38Z","isPatch":true,"sender":{"key":"lewiemann@gmail.com","avatar":null},"body":"Lea Wiemann wrote:\n> [PATCH] t/test-lib.sh: add test_external and test_external_without_stderr\n\nPlease don't merge this patch or the \"test suite for Git.pm\" patch -- \nI'll rather stay on my branch for now so I can easily rebase and change \nthings.  Comments are still welcome, of course.\n\n-- Lea\n"}]}