xref: /freebsd/usr.bin/grep/tests/grep_freebsd_test.sh (revision 22c00e3b850fa93bd6979d6c9b8297c05f0bdf84)
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
28*22c00e3bSEnji Cooper# What grep(1) are we working with?
29*22c00e3bSEnji Cooper# - 0 : bsdgrep
30*22c00e3bSEnji Cooper# - 1 : gnu grep 2.51 (base)
31*22c00e3bSEnji Cooper# - 2 : gnu grep (ports)
32*22c00e3bSEnji CooperGREP_TYPE_BSD=0
33*22c00e3bSEnji CooperGREP_TYPE_GNU_FREEBSD=1
34*22c00e3bSEnji CooperGREP_TYPE_GNU=2
35*22c00e3bSEnji CooperGREP_TYPE_UNKNOWN=3
36*22c00e3bSEnji Cooper
37*22c00e3bSEnji Coopergrep_type()
38*22c00e3bSEnji Cooper{
39*22c00e3bSEnji Cooper	local grep_version=$(grep --version)
40*22c00e3bSEnji Cooper
41*22c00e3bSEnji Cooper	case "$grep_version" in
42*22c00e3bSEnji Cooper	*"BSD grep"*)
43*22c00e3bSEnji Cooper		return $GREP_TYPE_BSD
44*22c00e3bSEnji Cooper		;;
45*22c00e3bSEnji Cooper	*"GNU grep"*)
46*22c00e3bSEnji Cooper		case "$grep_version" in
47*22c00e3bSEnji Cooper		*2.5.1-FreeBSD*)
48*22c00e3bSEnji Cooper			return $GREP_TYPE_GNU_FREEBSD
49*22c00e3bSEnji Cooper			;;
50*22c00e3bSEnji Cooper		*)
51*22c00e3bSEnji Cooper			return $GREP_TYPE_GNU
52*22c00e3bSEnji Cooper			;;
53*22c00e3bSEnji Cooper		esac
54*22c00e3bSEnji Cooper		;;
55*22c00e3bSEnji Cooper	esac
56*22c00e3bSEnji Cooper	atf_fail "unknown grep type: $grep_version"
57*22c00e3bSEnji Cooper}
58*22c00e3bSEnji Cooper
59a461896aSEd Masteatf_test_case grep_r_implied
60a461896aSEd Mastegrep_r_implied_body()
61a461896aSEd Maste{
62*22c00e3bSEnji Cooper	grep_type
63*22c00e3bSEnji Cooper	if [ $? -ne $GREP_TYPE_BSD ]; then
64*22c00e3bSEnji Cooper		atf_skip "this test only works with bsdgrep(1)"
65*22c00e3bSEnji Cooper	fi
66*22c00e3bSEnji 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{
80a461896aSEd Maste	grep -r --exclude="*.out" -e "test" "$(atf_get_srcdir)" > d_grep_r_implied.out
81a461896aSEd Maste
82a461896aSEd Maste	atf_check -o file:d_grep_r_implied.out rgrep --exclude="*.out" -e "test" "$(atf_get_srcdir)"
83a461896aSEd Maste}
84a461896aSEd Maste
85a461896aSEd Masteatf_init_test_cases()
86a461896aSEd Maste{
87a461896aSEd Maste	atf_add_test_case grep_r_implied
88a461896aSEd Maste	atf_add_test_case rgrep
89a461896aSEd Maste}
90