From owner-svn-src-stable@freebsd.org Wed Aug 16 01:45:54 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A38C5DDD72B; Wed, 16 Aug 2017 01:45:54 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7FFEA69D3E; Wed, 16 Aug 2017 01:45:54 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7G1jrLa062483; Wed, 16 Aug 2017 01:45:53 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7G1jrLW062479; Wed, 16 Aug 2017 01:45:53 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201708160145.v7G1jrLW062479@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 16 Aug 2017 01:45:53 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/11/usr.bin/grep: . tests X-SVN-Commit-Revision: 322564 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Aug 2017 01:45:54 -0000 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) {