Git 2.23
[gitweb.git] / t / t7811-grep-open.sh
index fcfc56ea61d708a95a85624440fe56b52fedef62..d1ebfd88c7a9a92a956b92347c4193c6b1d08701 100755 (executable)
@@ -51,19 +51,18 @@ test_expect_success SIMPLEPAGER 'git grep -O' '
        grep.h
        EOF
        echo grep.h >expect.notless &&
-       >empty &&
 
        PATH=.:$PATH git grep -O GREP_PATTERN >out &&
        {
                test_cmp expect.less pager-args ||
                test_cmp expect.notless pager-args
        } &&
-       test_cmp empty out
+       test_must_be_empty out
 '
 
 test_expect_success 'git grep -O --cached' '
        test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg &&
-       grep open-files-in-pager msg
+       test_i18ngrep open-files-in-pager msg
 '
 
 test_expect_success 'git grep -O --no-index' '
@@ -72,7 +71,6 @@ test_expect_success 'git grep -O --no-index' '
        grep.h
        untracked
        EOF
-       >empty &&
 
        (
                GIT_PAGER='\''printf "%s\n" >pager-args'\'' &&
@@ -80,14 +78,15 @@ test_expect_success 'git grep -O --no-index' '
                git grep --no-index -O GREP_PATTERN >out
        ) &&
        test_cmp expect pager-args &&
-       test_cmp empty out
+       test_must_be_empty out
 '
 
 test_expect_success 'setup: fake "less"' '
-       cat >less <<-\EOF
+       cat >less <<-\EOF &&
        #!/bin/sh
        printf "%s\n" "$@" >actual
        EOF
+       chmod +x less
 '
 
 test_expect_success 'git grep -O jumps to line in less' '
@@ -95,20 +94,18 @@ test_expect_success 'git grep -O jumps to line in less' '
        +/*GREP_PATTERN
        grep.h
        EOF
-       >empty &&
 
        GIT_PAGER=./less git grep -O GREP_PATTERN >out &&
        test_cmp expect actual &&
-       test_cmp empty out
+       test_must_be_empty out &&
+
+       git grep -O./less GREP_PATTERN >out2 &&
+       test_cmp expect actual &&
+       test_must_be_empty out2
 '
 
 test_expect_success 'modified file' '
        rm -f actual &&
-       cat >less <<-\EOF &&
-       #!/bin/sh
-       printf "%s\n" "$@" >actual
-       EOF
-       chmod +x $less &&
        cat >expect <<-\EOF &&
        +/*enum grep_pat_token
        grep.h
@@ -122,21 +119,29 @@ test_expect_success 'modified file' '
        test_when_finished "git checkout HEAD unrelated" &&
        GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
        test_cmp expect actual &&
-       test_cmp empty out
+       test_must_be_empty out
+'
+
+test_expect_success 'copes with color settings' '
+       rm -f actual &&
+       echo grep.h >expect &&
+       test_config color.grep always &&
+       test_config color.grep.filename yellow &&
+       test_config color.grep.separator green &&
+       git grep -O'\''printf "%s\n" >actual'\'' GREP_AND &&
+       test_cmp expect actual
 '
 
 test_expect_success 'run from subdir' '
        rm -f actual &&
        echo grep.c >expect &&
-       >empty &&
 
        (
                cd subdir &&
                export GIT_PAGER &&
                GIT_PAGER='\''printf "%s\n" >../args'\'' &&
                git grep -O "enum grep_pat_token" >../out &&
-               GIT_PAGER="pwd >../dir; :" &&
-               git grep -O "enum grep_pat_token" >../out2
+               git grep -O"pwd >../dir; :" "enum grep_pat_token" >../out2
        ) &&
        case $(cat dir) in
        *subdir)
@@ -147,8 +152,8 @@ test_expect_success 'run from subdir' '
                ;;
        esac &&
        test_cmp expect args &&
-       test_cmp empty out &&
-       test_cmp empty out2
+       test_must_be_empty out &&
+       test_must_be_empty out2
 '
 
 test_done