Date: Wed, 16 Aug 2017 01:45:53 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r322564 - in stable/11/usr.bin/grep: . tests Message-ID: <201708160145.v7G1jrLW062479@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Wed Aug 16 01:45:53 2017 New Revision: 322564 URL: https://svnweb.freebsd.org/changeset/base/322564 Log: bsdgrep: Use implied working directory for -r if no directories are passed MFC r317050: bsdgrep: for -r, use the working directory if none specified This is more sensible than the previous behaviour of grepping stdin, and matches newer GNU grep behaviour. MFC r317300 (ngie): Only expect :grep_r_implied to pass with bsdgrep(1) The test fails with gnu grep from base and ports. MFC r319002 (ngie): :rgrep : use atf-check to check the exit code/save the output of grep -r instead of calling grep -r without it, and saving the output to a file This ensures that any errors thrown via grep -r are caught, not lost, and uses existing atf-sh idioms for saving files. PR: 216307 Approved by: emaste (mentor, blanket MFC) Relnotes: yes Added: stable/11/usr.bin/grep/tests/grep_freebsd_test.sh - copied, changed from r317050, head/usr.bin/grep/tests/grep_freebsd_test.sh Modified: stable/11/usr.bin/grep/grep.c stable/11/usr.bin/grep/tests/Makefile stable/11/usr.bin/grep/util.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/grep/grep.c ============================================================================== --- stable/11/usr.bin/grep/grep.c Wed Aug 16 01:27:48 2017 (r322563) +++ stable/11/usr.bin/grep/grep.c Wed Aug 16 01:45:53 2017 (r322564) @@ -739,7 +739,7 @@ main(int argc, char *argv[]) if ((aargc == 0 || aargc == 1) && !Hflag) hflag = true; - if (aargc == 0) + if (aargc == 0 && dirbehave != DIR_RECURSE) exit(!procfile("-")); if (dirbehave == DIR_RECURSE) Modified: stable/11/usr.bin/grep/tests/Makefile ============================================================================== --- stable/11/usr.bin/grep/tests/Makefile Wed Aug 16 01:27:48 2017 (r322563) +++ stable/11/usr.bin/grep/tests/Makefile Wed Aug 16 01:45:53 2017 (r322564) @@ -2,6 +2,7 @@ PACKAGE= tests +ATF_TESTS_SH+= grep_freebsd_test NETBSD_ATF_TESTS_SH= grep_test ${PACKAGE}FILES+= d_basic.out Copied and modified: stable/11/usr.bin/grep/tests/grep_freebsd_test.sh (from r317050, head/usr.bin/grep/tests/grep_freebsd_test.sh) ============================================================================== --- head/usr.bin/grep/tests/grep_freebsd_test.sh Mon Apr 17 13:22:39 2017 (r317050, copy source) +++ stable/11/usr.bin/grep/tests/grep_freebsd_test.sh Wed Aug 16 01:45:53 2017 (r322564) @@ -25,11 +25,45 @@ # # $FreeBSD$ +# What grep(1) are we working with? +# - 0 : bsdgrep +# - 1 : gnu grep 2.51 (base) +# - 2 : gnu grep (ports) +GREP_TYPE_BSD=0 +GREP_TYPE_GNU_FREEBSD=1 +GREP_TYPE_GNU=2 +GREP_TYPE_UNKNOWN=3 + +grep_type() +{ + local grep_version=$(grep --version) + + case "$grep_version" in + *"BSD grep"*) + return $GREP_TYPE_BSD + ;; + *"GNU grep"*) + case "$grep_version" in + *2.5.1-FreeBSD*) + return $GREP_TYPE_GNU_FREEBSD + ;; + *) + return $GREP_TYPE_GNU + ;; + esac + ;; + esac + atf_fail "unknown grep type: $grep_version" +} + atf_test_case grep_r_implied grep_r_implied_body() { - (cd "$(atf_get_srcdir)" && grep -r -e "test" < /dev/null) || - atf_skip "Implied working directory is not supported with your version of grep(1)" + grep_type + if [ $? -ne $GREP_TYPE_BSD ]; then + atf_skip "this test only works with bsdgrep(1)" + fi + (cd "$(atf_get_srcdir)" && grep -r --exclude="*.out" -e "test" .) > d_grep_r_implied.out atf_check -s exit:0 -x \ @@ -43,8 +77,7 @@ rgrep_head() } rgrep_body() { - grep -r --exclude="*.out" -e "test" "$(atf_get_srcdir)" > d_grep_r_implied.out - + atf_check -o save:d_grep_r_implied.out grep -r --exclude="*.out" -e "test" "$(atf_get_srcdir)" atf_check -o file:d_grep_r_implied.out rgrep --exclude="*.out" -e "test" "$(atf_get_srcdir)" } Modified: stable/11/usr.bin/grep/util.c ============================================================================== --- stable/11/usr.bin/grep/util.c Wed Aug 16 01:27:48 2017 (r322563) +++ stable/11/usr.bin/grep/util.c Wed Aug 16 01:45:53 2017 (r322564) @@ -109,6 +109,7 @@ grep_tree(char **argv) FTSENT *p; int c, fts_flags; bool ok; + const char *wd[] = { ".", NULL }; c = fts_flags = 0; @@ -126,7 +127,9 @@ grep_tree(char **argv) fts_flags |= FTS_NOSTAT | FTS_NOCHDIR; - if (!(fts = fts_open(argv, fts_flags, NULL))) + fts = fts_open((argv[0] == NULL) ? + __DECONST(char * const *, wd) : argv, fts_flags, NULL); + if (fts == NULL) err(2, "fts_open"); while ((p = fts_read(fts)) != NULL) { switch (p->fts_info) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708160145.v7G1jrLW062479>