git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] grep: do not segfault when -f is used

From
MKMatt Kraai <kraai@ftbfs.org>
Date
Oct 16, 2009, 13:39 UTC
Message-ID
<20091016133908.GA3172@ftbfs.org>
In-Reply-To
<4AD84C2F.5000809@viscovery.net>
On Fri, Oct 16, 2009 at 12:34:23PM +0200, Johannes Sixt wrote:
Show 6 quoted lines
> Matt Kraai schrieb:
> > +test_expect_success 'grep should not segfault with -f' '
> > +        test_must_fail git grep -f /dev/null
> > +'
> 
> there must be a better way to test whether grep -f behaves correctly.
How about the following test cases instead?
test_expect_success 'grep -f, non-existent file' '
	test_must_fail git grep -f patterns
'

cat >expected <<EOF file:foo mmap bar file:foo_mmap bar file:foo_mmap bar mmap file:foo mmap bar_mmap file:foo_mmap bar mmap baz EOF

cat >pattern <<EOF mmap EOF

test_expect_success 'grep -f, one pattern' '
	git grep -f pattern >actual &&
	test_cmp expected actual
'

cat >expected <<EOF file:foo mmap bar file:foo_mmap bar file:foo_mmap bar mmap file:foo mmap bar_mmap file:foo_mmap bar mmap baz t/a/v:vvv t/v:vvv v:vvv EOF

cat >patterns <<EOF mmap vvv EOF

test_expect_success 'grep -f, multiple patterns' '
	git grep -f patterns >actual &&
	test_cmp expected actual
'

cat >expected <<EOF file:foo mmap bar file:foo_mmap bar file:foo_mmap bar mmap file:foo mmap bar_mmap file:foo_mmap bar mmap baz t/a/v:vvv t/v:vvv v:vvv EOF

cat >patterns <<EOF
mmap
vvv
EOF
test_expect_success 'grep -f, ignore empty lines' '
	git grep -f patterns >actual &&
	test_cmp expected actual
'
-- 
Matt Kraai                                           http://ftbfs.org/
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 6 in “grep: do not segfault when -f is used”
  1. grep: do not segfault when -f is usedMatt Kraai, Oct 16, 2009
  2. Johannes SixtOct 16, 2009
  3. Matt KraaiOct 16, 2009
  4. Johannes SixtOct 16, 2009
  5. grep: do not segfault when -f is usedMatt Kraai, Oct 16, 2009
  6. Junio C HamanoOct 17, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.