From 46d98476cfcd6820e316f254615cf1ae43584ddb Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 1 Sep 2012 19:08:42 +0100 Subject: t3300-*.sh: Fix a TAP parse error At present, running the t3300-*.sh test on cygwin looks like: $ cd t $ ./t3300-funny-names.sh ok 1 - setup # passed all 1 test(s) 1..1 # SKIP Your filesystem does not allow tabs in filenames $ Unfortunately, this is not valid TAP output, which prove notes as follows: $ prove --exec sh t3300-funny-names.sh t3300-funny-names.sh .. All 1 subtests passed Test Summary Report ------------------- t3300-funny-names.sh (Wstat: 0 Tests: 1 Failed: 0) Parse errors: No plan found in TAP output Files=1, Tests=1, 2 wallclock secs ( 0.05 usr 0.00 sys + \ 0.90 cusr 0.49 csys = 1.43 CPU) Result: FAIL $ This is due to the 'trailing_plan' having a 'skip_directive' attached to it. This is not allowed by the TAP grammar, which only allows a 'leading_plan' to be followed by an optional 'skip_directive'. (see perldoc TAP::Parser::Grammar). A trailing_plan is one that appears in the TAP output after one or more test status lines (that start 'not '? 'ok ' ...), whereas a leading_plan must appear before all test status lines (if any). In practice, this means that the test script cannot contain a use of the 'skip all' facility: skip_all='Some reason to skip *all* tests in this file' test_done after having already executed one or more tests with (for example) 'test_expect_success'. Unfortunately, this is exactly what this test script is doing. The first 'setup' test is actually used to determine if the test prerequisite is satisfied by the filesystem (ie does it allow tabs in filenames?). In order to fix the parse errors, place the code to determine the test prerequisite at the top level of the script, prior to the first test, rather than as a parameter to test_expect_success. This allows us to correctly use 'skip_all', thus: $ ./t3300-funny-names.sh # passed all 0 test(s) 1..0 # SKIP Your filesystem does not allow tabs in filenames $ $ prove --exec sh t3300-funny-names.sh t3300-funny-names.sh .. skipped: Your filesystem does not \ allow tabs in filenames Files=1, Tests=0, 2 wallclock secs ( 0.02 usr 0.03 sys + \ 0.84 cusr 0.41 csys = 1.29 CPU) Result: NOTESTS $ Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/t3300-funny-names.sh | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 't') diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 1f35e55ee3..7480d6e7c2 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -11,6 +11,16 @@ tree, index, and tree objects. . ./test-lib.sh +HT=' ' + +echo 2>/dev/null > "Name with an${HT}HT" +if ! test -f "Name with an${HT}HT" +then + # since FAT/NTFS does not allow tabs in filenames, skip this test + skip_all='Your filesystem does not allow tabs in filenames' + test_done +fi + p0='no-funny' p1='tabs ," (dq) and spaces' p2='just space' @@ -23,21 +33,9 @@ test_expect_success 'setup' ' EOF { cat "$p0" >"$p1" || :; } && - { echo "Foo Bar Baz" >"$p2" || :; } && - - if test -f "$p1" && cmp "$p0" "$p1" - then - test_set_prereq TABS_IN_FILENAMES - fi + { echo "Foo Bar Baz" >"$p2" || :; } ' -if ! test_have_prereq TABS_IN_FILENAMES -then - # since FAT/NTFS does not allow tabs in filenames, skip this test - skip_all='Your filesystem does not allow tabs in filenames' - test_done -fi - test_expect_success 'setup: populate index and tree' ' git update-index --add "$p0" "$p2" && t0=$(git write-tree) -- cgit v1.2.3 From bb8eb64ef7154dce7d4870f134561729e68ca8c5 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 1 Sep 2012 19:10:01 +0100 Subject: t3902-*.sh: Skip all tests rather than each test Each test in this file is skipped if the TABS_IN_FILENAMES test prerequisite is set. Use the 'skip_all' facility at the head of the file to skip all of the tests instead. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/t3902-quoted.sh | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 't') diff --git a/t/t3902-quoted.sh b/t/t3902-quoted.sh index 534ee08a44..892f567844 100755 --- a/t/t3902-quoted.sh +++ b/t/t3902-quoted.sh @@ -16,9 +16,8 @@ echo foo 2>/dev/null > "Name and an${HT}HT" if ! test -f "Name and an${HT}HT" then # FAT/NTFS does not allow tabs in filenames - say 'Your filesystem does not allow tabs in filenames' -else - test_set_prereq TABS_IN_FILENAMES + skip_all='Your filesystem does not allow tabs in filenames' + test_done fi for_each_name () { @@ -31,7 +30,7 @@ for_each_name () { done } -test_expect_success TABS_IN_FILENAMES 'setup' ' +test_expect_success 'setup' ' mkdir "$FN" && for_each_name "echo initial >\"\$name\"" && @@ -45,7 +44,7 @@ test_expect_success TABS_IN_FILENAMES 'setup' ' ' -test_expect_success TABS_IN_FILENAMES 'setup expected files' ' +test_expect_success 'setup expected files' ' cat >expect.quoted <<\EOF && Name "Name and a\nLF" @@ -75,74 +74,74 @@ With SP in it EOF ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from ls-files' ' +test_expect_success 'check fully quoted output from ls-files' ' git ls-files >current && test_cmp expect.quoted current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from diff-files' ' +test_expect_success 'check fully quoted output from diff-files' ' git diff --name-only >current && test_cmp expect.quoted current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from diff-index' ' +test_expect_success 'check fully quoted output from diff-index' ' git diff --name-only HEAD >current && test_cmp expect.quoted current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from diff-tree' ' +test_expect_success 'check fully quoted output from diff-tree' ' git diff --name-only HEAD^ HEAD >current && test_cmp expect.quoted current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from ls-tree' ' +test_expect_success 'check fully quoted output from ls-tree' ' git ls-tree --name-only -r HEAD >current && test_cmp expect.quoted current ' -test_expect_success TABS_IN_FILENAMES 'setting core.quotepath' ' +test_expect_success 'setting core.quotepath' ' git config --bool core.quotepath false ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from ls-files' ' +test_expect_success 'check fully quoted output from ls-files' ' git ls-files >current && test_cmp expect.raw current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from diff-files' ' +test_expect_success 'check fully quoted output from diff-files' ' git diff --name-only >current && test_cmp expect.raw current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from diff-index' ' +test_expect_success 'check fully quoted output from diff-index' ' git diff --name-only HEAD >current && test_cmp expect.raw current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from diff-tree' ' +test_expect_success 'check fully quoted output from diff-tree' ' git diff --name-only HEAD^ HEAD >current && test_cmp expect.raw current ' -test_expect_success TABS_IN_FILENAMES 'check fully quoted output from ls-tree' ' +test_expect_success 'check fully quoted output from ls-tree' ' git ls-tree --name-only -r HEAD >current && test_cmp expect.raw current -- cgit v1.2.3 From 69915d88bca0cb6837c68ca09b702ad051f207e7 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 1 Sep 2012 19:10:57 +0100 Subject: t4016-*.sh: Skip all tests rather than each test Each test in this file is skipped if the TABS_IN_FILENAMES test prerequisite is set. Use the 'skip_all' facility at the head of the file to skip all of the tests instead. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/t4016-diff-quote.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 't') diff --git a/t/t4016-diff-quote.sh b/t/t4016-diff-quote.sh index 97b81778cb..cd543ecc54 100755 --- a/t/t4016-diff-quote.sh +++ b/t/t4016-diff-quote.sh @@ -13,14 +13,12 @@ P1='pathname with HT' P2='pathname with SP' P3='pathname with LF' -if : 2>/dev/null >"$P1" && test -f "$P1" && rm -f "$P1" -then - test_set_prereq TABS_IN_FILENAMES -else - say 'Your filesystem does not allow tabs in filenames' -fi +echo 2>/dev/null >"$P1" && test -f "$P1" && rm -f "$P1" || { + skip_all='Your filesystem does not allow tabs in filenames' + test_done +} -test_expect_success TABS_IN_FILENAMES setup ' +test_expect_success setup ' echo P0.0 >"$P0.0" && echo P0.1 >"$P0.1" && echo P0.2 >"$P0.2" && @@ -40,7 +38,7 @@ test_expect_success TABS_IN_FILENAMES setup ' : ' -test_expect_success TABS_IN_FILENAMES 'setup expected files' ' +test_expect_success 'setup expected files' ' cat >expect <<\EOF rename pathname.1 => "Rpathname\twith HT.0" (100%) rename pathname.3 => "Rpathname\nwith LF.0" (100%) @@ -52,12 +50,12 @@ cat >expect <<\EOF EOF ' -test_expect_success TABS_IN_FILENAMES 'git diff --summary -M HEAD' ' +test_expect_success 'git diff --summary -M HEAD' ' git diff --summary -M HEAD >actual && test_cmp expect actual ' -test_expect_success TABS_IN_FILENAMES 'git diff --numstat -M HEAD' ' +test_expect_success 'git diff --numstat -M HEAD' ' cat >expect <<-\EOF && 0 0 pathname.1 => "Rpathname\twith HT.0" 0 0 pathname.3 => "Rpathname\nwith LF.0" @@ -71,7 +69,7 @@ test_expect_success TABS_IN_FILENAMES 'git diff --numstat -M HEAD' ' test_cmp expect actual ' -test_expect_success TABS_IN_FILENAMES 'git diff --stat -M HEAD' ' +test_expect_success 'git diff --stat -M HEAD' ' cat >expect <<-\EOF && pathname.1 => "Rpathname\twith HT.0" | 0 pathname.3 => "Rpathname\nwith LF.0" | 0 -- cgit v1.2.3 From 1c0cc7563b079e17f84cf93e5b735ec9fa4ad11a Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 1 Sep 2012 19:11:49 +0100 Subject: test-lib.sh: Fix some shell coding style violations Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/test-lib.sh | 60 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 't') diff --git a/t/test-lib.sh b/t/test-lib.sh index bb4f8865b2..007d7b20d8 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -100,12 +100,12 @@ unset CDPATH unset GREP_OPTIONS case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in - 1|2|true) - echo "* warning: Some tests will not work if GIT_TRACE" \ - "is set as to trace on STDERR ! *" - echo "* warning: Please set GIT_TRACE to something" \ - "other than 1, 2 or true ! *" - ;; +1|2|true) + echo "* warning: Some tests will not work if GIT_TRACE" \ + "is set as to trace on STDERR ! *" + echo "* warning: Please set GIT_TRACE to something" \ + "other than 1, 2 or true ! *" + ;; esac # Convenience @@ -172,17 +172,23 @@ do esac done -if test -n "$color"; then +if test -n "$color" +then say_color () { ( TERM=$ORIGINAL_TERM export TERM case "$1" in - error) tput bold; tput setaf 1;; # bold red - skip) tput bold; tput setaf 2;; # bold green - pass) tput setaf 2;; # green - info) tput setaf 3;; # brown - *) test -n "$quiet" && return;; + error) + tput bold; tput setaf 1;; # bold red + skip) + tput bold; tput setaf 2;; # bold green + pass) + tput setaf 2;; # green + info) + tput setaf 3;; # brown + *) + test -n "$quiet" && return;; esac shift printf "%s" "$*" @@ -298,7 +304,8 @@ test_run_ () { then test_eval_ "$test_cleanup" fi - if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then + if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE" + then echo "" fi return "$eval_ret" @@ -346,7 +353,8 @@ test_at_end_hook_ () { test_done () { GIT_EXIT_OK=t - if test -z "$HARNESS_ACTIVE"; then + if test -z "$HARNESS_ACTIVE" + then test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" mkdir -p "$test_results_dir" test_results_path="$test_results_dir/${0%.sh}-$$.counts" @@ -377,7 +385,8 @@ test_done () { # Maybe print SKIP message [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all" - if test $test_external_has_tap -eq 0; then + if test $test_external_has_tap -eq 0 + then say_color pass "# passed all $msg" say "1..$test_count$skip_all" fi @@ -391,7 +400,8 @@ test_done () { exit 0 ;; *) - if test $test_external_has_tap -eq 0; then + if test $test_external_has_tap -eq 0 + then say_color error "# failed $test_failure among $msg" say "1..$test_count" fi @@ -471,22 +481,26 @@ then PATH=$GIT_VALGRIND/bin:$PATH GIT_EXEC_PATH=$GIT_VALGRIND/bin export GIT_VALGRIND -elif test -n "$GIT_TEST_INSTALLED" ; then +elif test -n "$GIT_TEST_INSTALLED" +then GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) || error "Cannot run git from $GIT_TEST_INSTALLED." PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH} else # normal case, use ../bin-wrappers only unless $with_dashes: git_bin_dir="$GIT_BUILD_DIR/bin-wrappers" - if ! test -x "$git_bin_dir/git" ; then - if test -z "$with_dashes" ; then + if ! test -x "$git_bin_dir/git" + then + if test -z "$with_dashes" + then say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH" fi with_dashes=t fi PATH="$git_bin_dir:$PATH" GIT_EXEC_PATH=$GIT_BUILD_DIR - if test -n "$with_dashes" ; then + if test -n "$with_dashes" + then PATH="$GIT_BUILD_DIR:$PATH" fi fi @@ -521,7 +535,8 @@ then } fi -if ! test -x "$GIT_BUILD_DIR"/test-chmtime; then +if ! test -x "$GIT_BUILD_DIR"/test-chmtime +then echo >&2 'You need to build test-chmtime:' echo >&2 'Run "make test-chmtime" in the source (toplevel) directory' exit 1 @@ -544,7 +559,8 @@ rm -fr "$test" || { HOME="$TRASH_DIRECTORY" export HOME -if test -z "$TEST_NO_CREATE_REPO"; then +if test -z "$TEST_NO_CREATE_REPO" +then test_create_repo "$test" else mkdir -p "$test" -- cgit v1.2.3 From bf4b7219322d007f3ebd2a002114956d025e4703 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 1 Sep 2012 19:13:19 +0100 Subject: test-lib.sh: Add check for invalid use of 'skip_all' facility The 'skip_all' facility cannot be used after one or more tests have been executed using (for example) 'test_expect_success'. To do so results in invalid TAP output, which leads to 'prove' complaining of "Parse errors: No plan found in TAP output". Add a check for such invalid usage and abort the test with an error message to alert the test author. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/test-lib.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't') diff --git a/t/test-lib.sh b/t/test-lib.sh index 007d7b20d8..7f4cb67c0f 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -383,6 +383,10 @@ test_done () { case "$test_failure" in 0) # Maybe print SKIP message + if test -n "$skip_all" && test $test_count -gt 0 + then + error "Can't use skip_all after running some tests" + fi [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all" if test $test_external_has_tap -eq 0 -- cgit v1.2.3 From d87bd7c15beb688294cf4adb1b719dc4e413c58f Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 1 Sep 2012 19:26:21 +0100 Subject: test-lib.sh: Suppress the "passed all ..." message if no tests run If a test script issues a test_done without executing any tests, for example when using the 'skip_all' facility, the output looks something like this: $ ./t9159-git-svn-no-parent-mergeinfo.sh # passed all 0 test(s) 1..0 # SKIP skipping git svn tests, svn not found $ The "passed all 0 test(s)" comment line, while correct, looks a little strange. Add a check to suppress this message if no tests have actually been run. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/test-lib.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/test-lib.sh b/t/test-lib.sh index 7f4cb67c0f..600ed835ee 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -391,7 +391,10 @@ test_done () { if test $test_external_has_tap -eq 0 then - say_color pass "# passed all $msg" + if test $test_count -gt 0 + then + say_color pass "# passed all $msg" + fi say "1..$test_count$skip_all" fi -- cgit v1.2.3