Re: [PATCH 1/2] t7002: set test prerequisite "external-grep" if supported

4 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 1/2] t7002: set test prerequisite "external-grep" if supported

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:58

Junio C Hamano [off-list ref] writes:
Nguyễn Thái Ngọc Duy  [off-list ref] writes:
quoted
Add another test to set prerequisite "external-grep" if the current
build supports external grep. This can be used to skip external grep
only tests on builds that do not support this optimization.
Thanks.  We seem to spell our prerequistes in a single-word, all-caps, so
I'll change this new one to EXTGREP in both [1/2] and [2/2].
Sorry, but I had this "Sheesh, why didn't I think of that earlier before
wasting Nguyễn's time" moment.

Why don't we just test what we _want to_ test?  After all what a67e281
(grep: do not do external grep on skip-worktree entries, 2009-12-30)
wanted to make sure was this:

    "git grep" (without --cached) should grep from the index for paths
    that are marked as skip-worktree.

So how about writing some string that does not appear in the version in
the index in the work tree file, and run "git grep" to make sure it
doesn't find it?

Yes, some implementations/builds of "git grep" may not even try to cheat
and run external grep and for them the test _should_ succeed (but your
logic to check with ce_skip_worktree() in grep_cache() may be broken by
later patch while you are looking the other way), and some will try to
cheat and the fix was about not letting them.

So by writing the test to check the desired outcome, instead of writing it
for the particular implementation of using external grep optimization, you
will catch both kinds of breakages.

Perhaps something like this (untested, of course)?

test_expect_success 'strings in work tree files are not found for skip-wt paths' '
	no="no such string in the index" &&
	test_must_fail git grep -e "$no" --cached file &&
	git update-index --skip-worktree file &&
	echo "$no" >file &&
	test_must_fail git grep -e "$no" file &&
	git update-index --no-skip-worktree file &&
	git grep -e "$no" file
'

Re: [PATCH 1/2] t7002: set test prerequisite "external-grep" if supported

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:47:58

On 1/7/10, Junio C Hamano [off-list ref] wrote:
 So by writing the test to check the desired outcome, instead of writing it
 for the particular implementation of using external grep optimization, you
 will catch both kinds of breakages.

 Perhaps something like this (untested, of course)?

 test_expect_success 'strings in work tree files are not found for skip-wt paths' '
        no="no such string in the index" &&
        test_must_fail git grep -e "$no" --cached file &&
        git update-index --skip-worktree file &&
        echo "$no" >file &&
        test_must_fail git grep -e "$no" file &&
        git update-index --no-skip-worktree file &&
        git grep -e "$no" file
 '
Very well reasoned. I'd say go for it!

Tested-by: me
-- 
Duy

Re: [PATCH 1/2] t7002: set test prerequisite "external-grep" if supported

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:47:58

Nguyen Thai Ngoc Duy schrieb:
On 1/7/10, Junio C Hamano [off-list ref] wrote:
quoted
 So by writing the test to check the desired outcome, instead of writing it
 for the particular implementation of using external grep optimization, you
 will catch both kinds of breakages.

 Perhaps something like this (untested, of course)?

 test_expect_success 'strings in work tree files are not found for skip-wt paths' '
        no="no such string in the index" &&
        test_must_fail git grep -e "$no" --cached file &&
        git update-index --skip-worktree file &&
        echo "$no" >file &&
        test_must_fail git grep -e "$no" file &&
        git update-index --no-skip-worktree file &&
        git grep -e "$no" file
 '
Very well reasoned. I'd say go for it!

Tested-by: me
The test is not quite complete. Not only do you want to test that the
worktree file is not looked at, but that the index version is used:


test_expect_success 'for skip-wt paths, strings are found in index, not in
worktree' '
	yes="this string is in the index" &&
	no="no such string in the index" &&
	echo "$yes" >file &&
	git update-index file &&
	echo "$no" >file &&
	git grep -e "$yes" --cached file &&
	test_must_fail git grep -e "$no" --cached file &&
	git update-index --skip-worktree file &&
	git grep -e "$yes" file &&
	test_must_fail git grep -e "$no" file &&
	git update-index --no-skip-worktree file &&
	test_must_fail git grep -e "$yes" file &&
	git grep -e "$no" file
'

Just as untested... ;)

-- Hannes

Re: [PATCH 1/2] t7002: set test prerequisite "external-grep" if supported

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:47:58

On 1/7/10, Johannes Sixt [off-list ref] wrote:
Nguyen Thai Ngoc Duy schrieb:
quoted
On 1/7/10, Junio C Hamano [off-list ref] wrote:
 >>  So by writing the test to check the desired outcome, instead of writing it
 >>  for the particular implementation of using external grep optimization, you
 >>  will catch both kinds of breakages.
 >>
 >>  Perhaps something like this (untested, of course)?
 >>
 >>  test_expect_success 'strings in work tree files are not found for skip-wt paths' '
 >>         no="no such string in the index" &&
 >>         test_must_fail git grep -e "$no" --cached file &&
 >>         git update-index --skip-worktree file &&
 >>         echo "$no" >file &&
 >>         test_must_fail git grep -e "$no" file &&
 >>         git update-index --no-skip-worktree file &&
 >>         git grep -e "$no" file
 >>  '
 >>
 >
 > Very well reasoned. I'd say go for it!
 >
 > Tested-by: me


The test is not quite complete. Not only do you want to test that the
 worktree file is not looked at, but that the index version is used:


 test_expect_success 'for skip-wt paths, strings are found in index, not in
 worktree' '
        yes="this string is in the index" &&

        no="no such string in the index" &&

        echo "$yes" >file &&
        git update-index file &&
        echo "$no" >file &&
        git grep -e "$yes" --cached file &&

        test_must_fail git grep -e "$no" --cached file &&
        git update-index --skip-worktree file &&

        git grep -e "$yes" file &&

        test_must_fail git grep -e "$no" file &&
        git update-index --no-skip-worktree file &&

        test_must_fail git grep -e "$yes" file &&

        git grep -e "$no" file
 '
Can we get rid of preparing $yes and do "grep -e foo file" instead?
There are lots of foo from setup test. It's not as strict as your test
because foo is also in worktree. But we have $no for testing worktree
already.
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help