1a461896aSEd Maste# 2f0fb94abSKyle Evans# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3f0fb94abSKyle Evans# 426e1c38fSKyle Evans# Copyright (c) 2017 Kyle Evans <kevans@FreeBSD.org> 5a461896aSEd Maste# 6a461896aSEd Maste# Redistribution and use in source and binary forms, with or without 7a461896aSEd Maste# modification, are permitted provided that the following conditions 8a461896aSEd Maste# are met: 9a461896aSEd Maste# 1. Redistributions of source code must retain the above copyright 10a461896aSEd Maste# notice, this list of conditions and the following disclaimer. 11a461896aSEd Maste# 2. Redistributions in binary form must reproduce the above copyright 12a461896aSEd Maste# notice, this list of conditions and the following disclaimer in the 13a461896aSEd Maste# documentation and/or other materials provided with the distribution. 14a461896aSEd Maste# 158433795dSKyle Evans# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 168433795dSKyle Evans# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 178433795dSKyle Evans# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 188433795dSKyle Evans# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 198433795dSKyle Evans# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208433795dSKyle Evans# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 218433795dSKyle Evans# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 228433795dSKyle Evans# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 238433795dSKyle Evans# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 248433795dSKyle Evans# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 258433795dSKyle Evans# SUCH DAMAGE. 26a461896aSEd Maste# 27a461896aSEd Maste# $FreeBSD$ 28a461896aSEd Maste 2922c00e3bSEnji Cooper# What grep(1) are we working with? 3022c00e3bSEnji Cooper# - 0 : bsdgrep 3122c00e3bSEnji Cooper# - 1 : gnu grep 2.51 (base) 3222c00e3bSEnji Cooper# - 2 : gnu grep (ports) 3322c00e3bSEnji CooperGREP_TYPE_BSD=0 3422c00e3bSEnji CooperGREP_TYPE_GNU_FREEBSD=1 3522c00e3bSEnji CooperGREP_TYPE_GNU=2 3622c00e3bSEnji CooperGREP_TYPE_UNKNOWN=3 3722c00e3bSEnji Cooper 3822c00e3bSEnji Coopergrep_type() 3922c00e3bSEnji Cooper{ 4022c00e3bSEnji Cooper local grep_version=$(grep --version) 4122c00e3bSEnji Cooper 4222c00e3bSEnji Cooper case "$grep_version" in 4322c00e3bSEnji Cooper *"BSD grep"*) 4422c00e3bSEnji Cooper return $GREP_TYPE_BSD 4522c00e3bSEnji Cooper ;; 4622c00e3bSEnji Cooper *"GNU grep"*) 4722c00e3bSEnji Cooper case "$grep_version" in 4822c00e3bSEnji Cooper *2.5.1-FreeBSD*) 4922c00e3bSEnji Cooper return $GREP_TYPE_GNU_FREEBSD 5022c00e3bSEnji Cooper ;; 5122c00e3bSEnji Cooper *) 5222c00e3bSEnji Cooper return $GREP_TYPE_GNU 5322c00e3bSEnji Cooper ;; 5422c00e3bSEnji Cooper esac 5522c00e3bSEnji Cooper ;; 5622c00e3bSEnji Cooper esac 5722c00e3bSEnji Cooper atf_fail "unknown grep type: $grep_version" 5822c00e3bSEnji Cooper} 5922c00e3bSEnji Cooper 60a461896aSEd Masteatf_test_case grep_r_implied 61a461896aSEd Mastegrep_r_implied_body() 62a461896aSEd Maste{ 6322c00e3bSEnji Cooper grep_type 6422c00e3bSEnji Cooper if [ $? -ne $GREP_TYPE_BSD ]; then 6522c00e3bSEnji Cooper atf_skip "this test only works with bsdgrep(1)" 6622c00e3bSEnji Cooper fi 6722c00e3bSEnji Cooper 68a461896aSEd Maste (cd "$(atf_get_srcdir)" && grep -r --exclude="*.out" -e "test" .) > d_grep_r_implied.out 69a461896aSEd Maste 70a461896aSEd Maste atf_check -s exit:0 -x \ 71a461896aSEd Maste "(cd $(atf_get_srcdir) && grep -r --exclude=\"*.out\" -e \"test\") | diff d_grep_r_implied.out -" 72a461896aSEd Maste} 73a461896aSEd Maste 74a461896aSEd Masteatf_test_case rgrep 75a461896aSEd Mastergrep_head() 76a461896aSEd Maste{ 77a461896aSEd Maste atf_set "require.progs" "rgrep" 78a461896aSEd Maste} 79a461896aSEd Mastergrep_body() 80a461896aSEd Maste{ 8180c5ef10SEnji Cooper atf_check -o save:d_grep_r_implied.out grep -r --exclude="*.out" -e "test" "$(atf_get_srcdir)" 82a461896aSEd Maste atf_check -o file:d_grep_r_implied.out rgrep --exclude="*.out" -e "test" "$(atf_get_srcdir)" 83a461896aSEd Maste} 84a461896aSEd Maste 85*aef64c62SKyle Evansatf_test_case gnuext 86*aef64c62SKyle Evansgnuext_body() 87*aef64c62SKyle Evans{ 88*aef64c62SKyle Evans grep_type 89*aef64c62SKyle Evans _type=$? 90*aef64c62SKyle Evans if [ $_type -eq $GREP_TYPE_BSD ]; then 91*aef64c62SKyle Evans atf_expect_fail "this test requires GNU extensions in regex(3)" 92*aef64c62SKyle Evans elif [ $_type -eq $GREP_TYPE_GNU_FREEBSD ]; then 93*aef64c62SKyle Evans atf_expect_fail "\\s and \\S are known to be buggy in base gnugrep" 94*aef64c62SKyle Evans fi 95*aef64c62SKyle Evans 96*aef64c62SKyle Evans atf_check -o save:grep_alnum.out grep -o '[[:alnum:]]' /COPYRIGHT 97*aef64c62SKyle Evans atf_check -o file:grep_alnum.out grep -o '\w' /COPYRIGHT 98*aef64c62SKyle Evans 99*aef64c62SKyle Evans atf_check -o save:grep_nalnum.out grep -o '[^[:alnum:]]' /COPYRIGHT 100*aef64c62SKyle Evans atf_check -o file:grep_nalnum.out grep -o '\W' /COPYRIGHT 101*aef64c62SKyle Evans 102*aef64c62SKyle Evans atf_check -o save:grep_space.out grep -o '[[:space:]]' /COPYRIGHT 103*aef64c62SKyle Evans atf_check -o file:grep_space.out grep -o '\s' /COPYRIGHT 104*aef64c62SKyle Evans 105*aef64c62SKyle Evans atf_check -o save:grep_nspace.out grep -o '[^[:space:]]' /COPYRIGHT 106*aef64c62SKyle Evans atf_check -o file:grep_nspace.out grep -o '\S' /COPYRIGHT 107*aef64c62SKyle Evans 108*aef64c62SKyle Evans} 109*aef64c62SKyle Evans 110a461896aSEd Masteatf_init_test_cases() 111a461896aSEd Maste{ 112a461896aSEd Maste atf_add_test_case grep_r_implied 113a461896aSEd Maste atf_add_test_case rgrep 114*aef64c62SKyle Evans atf_add_test_case gnuext 115a461896aSEd Maste} 116