On Sat, Sep 03, 2022 at 11:26:18AM +0200, Roland Illig wrote: > Am 03.09.2022 um 11:06 schrieb Thomas Klausner: > > On Fri, Sep 02, 2022 at 07:08:23PM +0200, Thomas Klausner wrote: > > > I'd like the change the behaviour to match what GNU grep does. > > > > Since I saw only positive feedback, here's my proposed patch. > > Comments? > > The patch does not contain a test.
Added. Fails before, works after. > The brace style is BSD rather than GNU, which doesn't match the > surrounding brace style. Fixed. Thomas
? tests/usr.bin/grep/Atffile ? tests/usr.bin/grep/t_grep Index: external/gpl2/grep/dist/doc/grep.1 =================================================================== RCS file: /cvsroot/src/external/gpl2/grep/dist/doc/grep.1,v retrieving revision 1.2 diff -u -r1.2 grep.1 --- external/gpl2/grep/dist/doc/grep.1 10 Jan 2016 22:16:40 -0000 1.2 +++ external/gpl2/grep/dist/doc/grep.1 3 Sep 2022 16:50:48 -0000 @@ -2,7 +2,7 @@ .\" .\" grep man page .\"d Id: grep.1,v 1.23 2002/01/22 13:20:04 bero Exp -.TH GREP 1 "June 16 2003" "GNU Project" +.TH GREP 1 "September 3 2022" "GNU Project" .SH NAME grep, egrep, fgrep \- print lines matching a pattern .SH SYNOPSIS @@ -312,6 +312,11 @@ this is equivalent to the .B "\-d recurse" option. +If no +.IR FILE +is given, +.BR grep +searches the current working directory. .TP .BR "\fR \fP \-\^\-include=" PATTERN Recurse in directories only searching file matching Index: external/gpl2/grep/dist/src/grep.c =================================================================== RCS file: /cvsroot/src/external/gpl2/grep/dist/src/grep.c,v retrieving revision 1.4 diff -u -r1.4 grep.c --- external/gpl2/grep/dist/src/grep.c 28 Dec 2021 19:22:58 -0000 1.4 +++ external/gpl2/grep/dist/src/grep.c 3 Sep 2022 16:50:48 -0000 @@ -1764,10 +1764,14 @@ } else { - if (directories == RECURSE_DIRECTORIES) { - error (0, 0, _("warning: recursive search of stdin")); - } - status = grepfile ((char *) NULL, &stats_base); + if (directories == RECURSE_DIRECTORIES) + { + status = grepfile(".", &stats_base); + } + else + { + status = grepfile ((char *) NULL, &stats_base); + } } /* We register via atexit() to test stdout. */ Index: tests/usr.bin/grep/Makefile =================================================================== RCS file: /cvsroot/src/tests/usr.bin/grep/Makefile,v retrieving revision 1.1 diff -u -r1.1 Makefile --- tests/usr.bin/grep/Makefile 17 Mar 2012 16:33:13 -0000 1.1 +++ tests/usr.bin/grep/Makefile 3 Sep 2022 16:51:28 -0000 @@ -30,6 +30,7 @@ FILES+= d_invert.in FILES+= d_invert.out FILES+= d_recurse.out +FILES+= d_recurse_noarg.out FILES+= d_recurse_symlink.err FILES+= d_recurse_symlink.out FILES+= d_whole_line.out Index: tests/usr.bin/grep/d_recurse_noarg.out =================================================================== RCS file: tests/usr.bin/grep/d_recurse_noarg.out diff -N tests/usr.bin/grep/d_recurse_noarg.out --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/usr.bin/grep/d_recurse_noarg.out 3 Sep 2022 16:51:28 -0000 @@ -0,0 +1,2 @@ +./a/f/favourite-fish:haddock +./d/fish:haddock Index: tests/usr.bin/grep/t_grep.sh =================================================================== RCS file: /cvsroot/src/tests/usr.bin/grep/t_grep.sh,v retrieving revision 1.6 diff -u -r1.6 t_grep.sh --- tests/usr.bin/grep/t_grep.sh 30 Aug 2021 23:14:14 -0000 1.6 +++ tests/usr.bin/grep/t_grep.sh 3 Sep 2022 16:51:28 -0000 @@ -31,7 +31,7 @@ atf_set "descr" "Checks basic functionality" } basic_body() -{ +{ atf_check -o file:"$(atf_get_srcdir)/d_basic.out" -x \ 'jot 10000 | grep 123' } @@ -62,6 +62,20 @@ atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" -x "grep -r haddock recurse | sort" } +atf_test_case recurse_noarg +recurse_noarg_head() +{ + atf_set "descr" "Checks recursive searching without file argument" +} +recurse_noarg_body() +{ + mkdir -p recurse/a/f recurse/d + echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish + echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish + + atf_check -o file:"$(atf_get_srcdir)/d_recurse_noarg.out" -x "cd recurse && grep -r haddock | sort" +} + atf_test_case recurse_symlink recurse_symlink_head() { @@ -329,9 +343,10 @@ atf_init_test_cases() { - atf_add_test_case basic + atf_add_test_case basic atf_add_test_case binary atf_add_test_case recurse + atf_add_test_case recurse_noarg atf_add_test_case recurse_symlink atf_add_test_case word_regexps atf_add_test_case word_locale Index: distrib/sets/lists/tests/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/tests/mi,v retrieving revision 1.1219 diff -u -r1.1219 mi --- distrib/sets/lists/tests/mi 12 Aug 2022 10:49:17 -0000 1.1219 +++ distrib/sets/lists/tests/mi 3 Sep 2022 16:51:32 -0000 @@ -4749,6 +4749,7 @@ ./usr/tests/usr.bin/grep/d_invert.in tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/grep/d_invert.out tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/grep/d_recurse.out tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/grep/d_recurse_noarg.out tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/grep/d_recurse_symlink.err tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/grep/d_recurse_symlink.out tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/grep/d_whole_line.out tests-usr.bin-tests compattestfile,atf