Imported Upstream version 2.27.0
[platform/upstream/git.git] / t / t7810-grep.sh
index 2e1bb61..991d5bd 100755 (executable)
@@ -72,6 +72,11 @@ test_expect_success setup '
        # Still a no-op.
        function dummy() {}
        EOF
+       if test_have_prereq FUNNYNAMES
+       then
+               echo unusual >"\"unusual\" pathname" &&
+               echo unusual >"t/nested \"unusual\" pathname"
+       fi &&
        git add . &&
        test_tick &&
        git commit -m initial
@@ -412,7 +417,7 @@ do
                test_cmp expected actual
        '
 
-       test_expect_success !PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
+       test_expect_success !FAIL_PREREQS,!PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
                test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
        '
 
@@ -481,6 +486,48 @@ do
                git grep --count -h -e b $H -- ab >actual &&
                test_cmp expected actual
        '
+
+       test_expect_success FUNNYNAMES "grep $L should quote unusual pathnames" '
+               cat >expected <<-EOF &&
+               ${HC}"\"unusual\" pathname":unusual
+               ${HC}"t/nested \"unusual\" pathname":unusual
+               EOF
+               git grep unusual $H >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success FUNNYNAMES "grep $L in subdir should quote unusual relative pathnames" '
+               cat >expected <<-EOF &&
+               ${HC}"nested \"unusual\" pathname":unusual
+               EOF
+               (
+                       cd t &&
+                       git grep unusual $H
+               ) >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success FUNNYNAMES "grep -z $L with unusual pathnames" '
+               cat >expected <<-EOF &&
+               ${HC}"unusual" pathname:unusual
+               ${HC}t/nested "unusual" pathname:unusual
+               EOF
+               git grep -z unusual $H >actual &&
+               tr "\0" ":" <actual >actual-replace-null &&
+               test_cmp expected actual-replace-null
+       '
+
+       test_expect_success FUNNYNAMES "grep -z $L in subdir with unusual relative pathnames" '
+               cat >expected <<-EOF &&
+               ${HC}nested "unusual" pathname:unusual
+               EOF
+               (
+                       cd t &&
+                       git grep -z unusual $H
+               ) >actual &&
+               tr "\0" ":" <actual >actual-replace-null &&
+               test_cmp expected actual-replace-null
+       '
 done
 
 cat >expected <<EOF
@@ -1234,7 +1281,7 @@ test_expect_success PCRE 'grep --perl-regexp pattern' '
        test_cmp expected actual
 '
 
-test_expect_success !PCRE 'grep --perl-regexp pattern errors without PCRE' '
+test_expect_success !FAIL_PREREQS,!PCRE 'grep --perl-regexp pattern errors without PCRE' '
        test_must_fail git grep --perl-regexp "foo.*bar"
 '
 
@@ -1249,7 +1296,7 @@ test_expect_success LIBPCRE2 "grep -P with (*NO_JIT) doesn't error out" '
 
 '
 
-test_expect_success !PCRE 'grep -P pattern errors without PCRE' '
+test_expect_success !FAIL_PREREQS,!PCRE 'grep -P pattern errors without PCRE' '
        test_must_fail git grep -P "foo.*bar"
 '