1a461896aSEd Maste# 2a461896aSEd Maste# Copyright (c) 2017 Kyle Evans <kevans91@ksu.edu> 3a461896aSEd Maste# All rights reserved. 4a461896aSEd Maste# 5a461896aSEd Maste# Redistribution and use in source and binary forms, with or without 6a461896aSEd Maste# modification, are permitted provided that the following conditions 7a461896aSEd Maste# are met: 8a461896aSEd Maste# 1. Redistributions of source code must retain the above copyright 9a461896aSEd Maste# notice, this list of conditions and the following disclaimer. 10a461896aSEd Maste# 2. Redistributions in binary form must reproduce the above copyright 11a461896aSEd Maste# notice, this list of conditions and the following disclaimer in the 12a461896aSEd Maste# documentation and/or other materials provided with the distribution. 13a461896aSEd Maste# 14a461896aSEd Maste# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15a461896aSEd Maste# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16a461896aSEd Maste# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17a461896aSEd Maste# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18a461896aSEd Maste# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19a461896aSEd Maste# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20a461896aSEd Maste# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21a461896aSEd Maste# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22a461896aSEd Maste# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23a461896aSEd Maste# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24a461896aSEd Maste# POSSIBILITY OF SUCH DAMAGE. 25a461896aSEd Maste# 26a461896aSEd Maste# $FreeBSD$ 27a461896aSEd Maste 2822c00e3bSEnji Cooper# What grep(1) are we working with? 2922c00e3bSEnji Cooper# - 0 : bsdgrep 3022c00e3bSEnji Cooper# - 1 : gnu grep 2.51 (base) 3122c00e3bSEnji Cooper# - 2 : gnu grep (ports) 3222c00e3bSEnji CooperGREP_TYPE_BSD=0 3322c00e3bSEnji CooperGREP_TYPE_GNU_FREEBSD=1 3422c00e3bSEnji CooperGREP_TYPE_GNU=2 3522c00e3bSEnji CooperGREP_TYPE_UNKNOWN=3 3622c00e3bSEnji Cooper 3722c00e3bSEnji Coopergrep_type() 3822c00e3bSEnji Cooper{ 3922c00e3bSEnji Cooper local grep_version=$(grep --version) 4022c00e3bSEnji Cooper 4122c00e3bSEnji Cooper case "$grep_version" in 4222c00e3bSEnji Cooper *"BSD grep"*) 4322c00e3bSEnji Cooper return $GREP_TYPE_BSD 4422c00e3bSEnji Cooper ;; 4522c00e3bSEnji Cooper *"GNU grep"*) 4622c00e3bSEnji Cooper case "$grep_version" in 4722c00e3bSEnji Cooper *2.5.1-FreeBSD*) 4822c00e3bSEnji Cooper return $GREP_TYPE_GNU_FREEBSD 4922c00e3bSEnji Cooper ;; 5022c00e3bSEnji Cooper *) 5122c00e3bSEnji Cooper return $GREP_TYPE_GNU 5222c00e3bSEnji Cooper ;; 5322c00e3bSEnji Cooper esac 5422c00e3bSEnji Cooper ;; 5522c00e3bSEnji Cooper esac 5622c00e3bSEnji Cooper atf_fail "unknown grep type: $grep_version" 5722c00e3bSEnji Cooper} 5822c00e3bSEnji Cooper 59a461896aSEd Masteatf_test_case grep_r_implied 60a461896aSEd Mastegrep_r_implied_body() 61a461896aSEd Maste{ 6222c00e3bSEnji Cooper grep_type 6322c00e3bSEnji Cooper if [ $? -ne $GREP_TYPE_BSD ]; then 6422c00e3bSEnji Cooper atf_skip "this test only works with bsdgrep(1)" 6522c00e3bSEnji Cooper fi 6622c00e3bSEnji Cooper 67a461896aSEd Maste (cd "$(atf_get_srcdir)" && grep -r --exclude="*.out" -e "test" .) > d_grep_r_implied.out 68a461896aSEd Maste 69a461896aSEd Maste atf_check -s exit:0 -x \ 70a461896aSEd Maste "(cd $(atf_get_srcdir) && grep -r --exclude=\"*.out\" -e \"test\") | diff d_grep_r_implied.out -" 71a461896aSEd Maste} 72a461896aSEd Maste 73a461896aSEd Masteatf_test_case rgrep 74a461896aSEd Mastergrep_head() 75a461896aSEd Maste{ 76a461896aSEd Maste atf_set "require.progs" "rgrep" 77a461896aSEd Maste} 78a461896aSEd Mastergrep_body() 79a461896aSEd Maste{ 80*80c5ef10SEnji Cooper atf_check -o save:d_grep_r_implied.out grep -r --exclude="*.out" -e "test" "$(atf_get_srcdir)" 81a461896aSEd Maste atf_check -o file:d_grep_r_implied.out rgrep --exclude="*.out" -e "test" "$(atf_get_srcdir)" 82a461896aSEd Maste} 83a461896aSEd Maste 84a461896aSEd Masteatf_init_test_cases() 85a461896aSEd Maste{ 86a461896aSEd Maste atf_add_test_case grep_r_implied 87a461896aSEd Maste atf_add_test_case rgrep 88a461896aSEd Maste} 89