2010-06-12 18:36:51 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git grep --open-files-in-pager
|
|
|
|
'
|
|
|
|
|
2021-10-22 10:55:41 +02:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2010-06-12 18:36:51 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
. "$TEST_DIRECTORY"/lib-pager.sh
|
|
|
|
unset PAGER GIT_PAGER
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
test_commit initial grep.h "
|
|
|
|
enum grep_pat_token {
|
|
|
|
GREP_PATTERN,
|
|
|
|
GREP_PATTERN_HEAD,
|
|
|
|
GREP_PATTERN_BODY,
|
|
|
|
GREP_AND,
|
|
|
|
GREP_OPEN_PAREN,
|
|
|
|
GREP_CLOSE_PAREN,
|
|
|
|
GREP_NOT,
|
|
|
|
GREP_OR,
|
|
|
|
};" &&
|
|
|
|
|
|
|
|
test_commit add-user revision.c "
|
|
|
|
}
|
|
|
|
if (seen_dashdash)
|
|
|
|
read_pathspec_from_stdin(revs, &sb, prune);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
|
|
|
|
{
|
|
|
|
append_grep_pattern(&revs->grep_filter, ptn, \"command line\", 0, what);
|
|
|
|
" &&
|
|
|
|
|
|
|
|
mkdir subdir &&
|
|
|
|
test_commit subdir subdir/grep.c "enum grep_pat_token" &&
|
|
|
|
|
|
|
|
test_commit uninteresting unrelated "hello, world" &&
|
|
|
|
|
|
|
|
echo GREP_PATTERN >untracked
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success SIMPLEPAGER 'git grep -O' '
|
|
|
|
cat >$less <<-\EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
printf "%s\n" "$@" >pager-args
|
|
|
|
EOF
|
|
|
|
chmod +x $less &&
|
|
|
|
cat >expect.less <<-\EOF &&
|
|
|
|
+/*GREP_PATTERN
|
|
|
|
grep.h
|
|
|
|
EOF
|
|
|
|
echo grep.h >expect.notless &&
|
|
|
|
|
|
|
|
PATH=.:$PATH git grep -O GREP_PATTERN >out &&
|
|
|
|
{
|
|
|
|
test_cmp expect.less pager-args ||
|
|
|
|
test_cmp expect.notless pager-args
|
|
|
|
} &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 23:57:25 +02:00
|
|
|
test_must_be_empty out
|
2010-06-12 18:36:51 +02:00
|
|
|
'
|
|
|
|
|
2011-04-14 23:36:14 +02:00
|
|
|
test_expect_success 'git grep -O --cached' '
|
2010-06-12 18:36:51 +02:00
|
|
|
test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg &&
|
2011-04-14 23:36:14 +02:00
|
|
|
test_i18ngrep open-files-in-pager msg
|
2010-06-12 18:36:51 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git grep -O --no-index' '
|
|
|
|
rm -f expect.less pager-args out &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
grep.h
|
|
|
|
untracked
|
|
|
|
EOF
|
|
|
|
|
|
|
|
(
|
|
|
|
GIT_PAGER='\''printf "%s\n" >pager-args'\'' &&
|
|
|
|
export GIT_PAGER &&
|
|
|
|
git grep --no-index -O GREP_PATTERN >out
|
|
|
|
) &&
|
|
|
|
test_cmp expect pager-args &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 23:57:25 +02:00
|
|
|
test_must_be_empty out
|
2010-06-12 18:36:51 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup: fake "less"' '
|
2010-06-21 19:37:14 +02:00
|
|
|
cat >less <<-\EOF &&
|
2010-06-12 18:36:51 +02:00
|
|
|
#!/bin/sh
|
|
|
|
printf "%s\n" "$@" >actual
|
|
|
|
EOF
|
2010-06-21 19:37:14 +02:00
|
|
|
chmod +x less
|
2010-06-12 18:36:51 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git grep -O jumps to line in less' '
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
+/*GREP_PATTERN
|
|
|
|
grep.h
|
|
|
|
EOF
|
|
|
|
|
|
|
|
GIT_PAGER=./less git grep -O GREP_PATTERN >out &&
|
|
|
|
test_cmp expect actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 23:57:25 +02:00
|
|
|
test_must_be_empty out &&
|
2010-06-12 18:39:46 +02:00
|
|
|
|
|
|
|
git grep -O./less GREP_PATTERN >out2 &&
|
|
|
|
test_cmp expect actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 23:57:25 +02:00
|
|
|
test_must_be_empty out2
|
2010-06-12 18:36:51 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified file' '
|
|
|
|
rm -f actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
+/*enum grep_pat_token
|
|
|
|
grep.h
|
|
|
|
revision.c
|
|
|
|
subdir/grep.c
|
|
|
|
unrelated
|
|
|
|
EOF
|
|
|
|
|
2021-10-22 10:55:41 +02:00
|
|
|
test_when_finished "git reset --hard" &&
|
2010-06-12 18:36:51 +02:00
|
|
|
echo "enum grep_pat_token" >unrelated &&
|
|
|
|
GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
|
|
|
|
test_cmp expect actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 23:57:25 +02:00
|
|
|
test_must_be_empty out
|
2010-06-12 18:36:51 +02:00
|
|
|
'
|
|
|
|
|
2010-07-03 04:55:06 +02:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2010-06-12 18:36:51 +02:00
|
|
|
test_expect_success 'run from subdir' '
|
|
|
|
rm -f actual &&
|
|
|
|
echo grep.c >expect &&
|
|
|
|
|
|
|
|
(
|
|
|
|
cd subdir &&
|
|
|
|
export GIT_PAGER &&
|
|
|
|
GIT_PAGER='\''printf "%s\n" >../args'\'' &&
|
|
|
|
git grep -O "enum grep_pat_token" >../out &&
|
2010-06-12 18:39:46 +02:00
|
|
|
git grep -O"pwd >../dir; :" "enum grep_pat_token" >../out2
|
2010-06-12 18:36:51 +02:00
|
|
|
) &&
|
|
|
|
case $(cat dir) in
|
|
|
|
*subdir)
|
|
|
|
: good
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
false
|
|
|
|
;;
|
|
|
|
esac &&
|
|
|
|
test_cmp expect args &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 23:57:25 +02:00
|
|
|
test_must_be_empty out &&
|
|
|
|
test_must_be_empty out2
|
2010-06-12 18:36:51 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|