They are equivalents and the former still exists, so as long as the
only change this commit makes are to rewrite test_i18ngrep to
test_grep, there won't be any new bug, even if there still are
callers of test_i18ngrep remaining in the tree, or when merged to
other topics that add new uses of test_i18ngrep.
This patch was produced more or less with
    git grep -l -e 'test_i18ngrep ' 't/t[0-9][0-9][0-9][0-9]-*.sh' |
    xargs perl -p -i -e 's/test_i18ngrep /test_grep /'
and a good way to sanity check the result yourself is to run the
above in a checkout of c4603c1c (test framework: further deprecate
test_i18ngrep, 2023-10-31) and compare the resulting working tree
contents with the result of applying this patch to the same commit.
You'll see that test_i18ngrep in a few t/lib-*.sh files corrected,
in addition to the manual reproduction.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
		
	
		
			
				
	
	
		
			160 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			160 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/sh
 | 
						|
 | 
						|
test_description='git grep --open-files-in-pager
 | 
						|
'
 | 
						|
 | 
						|
TEST_PASSES_SANITIZE_LEAK=true
 | 
						|
. ./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
 | 
						|
	} &&
 | 
						|
	test_must_be_empty out
 | 
						|
'
 | 
						|
 | 
						|
test_expect_success 'git grep -O --cached' '
 | 
						|
	test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg &&
 | 
						|
	test_grep open-files-in-pager msg
 | 
						|
'
 | 
						|
 | 
						|
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 &&
 | 
						|
	test_must_be_empty out
 | 
						|
'
 | 
						|
 | 
						|
test_expect_success 'setup: fake "less"' '
 | 
						|
	cat >less <<-\EOF &&
 | 
						|
	#!/bin/sh
 | 
						|
	printf "%s\n" "$@" >actual
 | 
						|
	EOF
 | 
						|
	chmod +x less
 | 
						|
'
 | 
						|
 | 
						|
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 &&
 | 
						|
	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 >expect <<-\EOF &&
 | 
						|
	+/*enum grep_pat_token
 | 
						|
	grep.h
 | 
						|
	revision.c
 | 
						|
	subdir/grep.c
 | 
						|
	unrelated
 | 
						|
	EOF
 | 
						|
 | 
						|
	test_when_finished "git reset --hard" &&
 | 
						|
	echo "enum grep_pat_token" >unrelated &&
 | 
						|
	GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
 | 
						|
	test_cmp expect actual &&
 | 
						|
	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 &&
 | 
						|
 | 
						|
	(
 | 
						|
		cd subdir &&
 | 
						|
		export GIT_PAGER &&
 | 
						|
		GIT_PAGER='\''printf "%s\n" >../args'\'' &&
 | 
						|
		git grep -O "enum grep_pat_token" >../out &&
 | 
						|
		git grep -O"pwd >../dir; :" "enum grep_pat_token" >../out2
 | 
						|
	) &&
 | 
						|
	case $(cat dir) in
 | 
						|
	*subdir)
 | 
						|
		: good
 | 
						|
		;;
 | 
						|
	*)
 | 
						|
		false
 | 
						|
		;;
 | 
						|
	esac &&
 | 
						|
	test_cmp expect args &&
 | 
						|
	test_must_be_empty out &&
 | 
						|
	test_must_be_empty out2
 | 
						|
'
 | 
						|
 | 
						|
test_done
 |