From: Jonathan Nieder Date: Sun, 31 Oct 2010 07:33:50 +0000 (-0500) Subject: test-lib: introduce test_line_count to measure files X-Git-Tag: v1.7.4-rc0~116^2~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fb3340a6a7a956debcac92cd21cbcaea0928048e;p=git.git test-lib: introduce test_line_count to measure files Some tests check their output with code like the following: test "$(git ls-files -u B | wc -l)" -eq 3 || { echo "BAD: should have left stages for B" return 1 } The verbose failure condition is used because test, unlike diff, does not print any useful information about the nature of the failure when it fails. Introduce a test_line_count function to help. If used like git ls-files -u B >output && test_line_count -eq 3 output it will produce output like test_line_count: line count for output !-eq 3 100644 b023018cabc396e7692c70bbf5784a93d3f738ab 2 hi.c 100644 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 3 hi.c on failure. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- diff --git a/t/README b/t/README index 2aceb67c7..1a78982da 100644 --- a/t/README +++ b/t/README @@ -500,6 +500,10 @@ library for your script to use. file. This behaves like "cmp" but produces more helpful output when the test is run with "-v" option. + - test_line_count (= | -lt | -ge | ...) + + Check whether a file has the length it is expected to. + - test_path_is_file [] test_path_is_dir [] test_path_is_missing [] diff --git a/t/test-lib.sh b/t/test-lib.sh index 87308f5a9..a417bdfed 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -598,6 +598,28 @@ test_path_is_missing () { fi } +# test_line_count checks that a file has the number of lines it +# ought to. For example: +# +# test_expect_success 'produce exactly one line of output' ' +# do something >output && +# test_line_count = 1 output +# ' +# +# is like "test $(wc -l