]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/grep/tests/grep_freebsd_test.sh
THIS BRANCH IS OBSOLETE, PLEASE READ:
[FreeBSD/FreeBSD.git] / usr.bin / grep / tests / grep_freebsd_test.sh
1 #
2 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 #
4 # Copyright (c) 2017 Kyle Evans <kevans@FreeBSD.org>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 # $FreeBSD$
28
29 # What grep(1) are we working with?
30 # - 0 : bsdgrep
31 # - 1 : gnu grep 2.51 (base)
32 # - 2 : gnu grep (ports)
33 GREP_TYPE_BSD=0
34 GREP_TYPE_GNU_FREEBSD=1
35 GREP_TYPE_GNU=2
36 GREP_TYPE_UNKNOWN=3
37
38 grep_type()
39 {
40         local grep_version=$(grep --version)
41
42         case "$grep_version" in
43         *"BSD grep"*)
44                 return $GREP_TYPE_BSD
45                 ;;
46         *"GNU grep"*)
47                 case "$grep_version" in
48                 *2.5.1-FreeBSD*)
49                         return $GREP_TYPE_GNU_FREEBSD
50                         ;;
51                 *)
52                         return $GREP_TYPE_GNU
53                         ;;
54                 esac
55                 ;;
56         esac
57         atf_fail "unknown grep type: $grep_version"
58 }
59
60 atf_test_case grep_r_implied
61 grep_r_implied_body()
62 {
63         grep_type
64         if [ $? -ne $GREP_TYPE_BSD ]; then
65                 atf_skip "this test only works with bsdgrep(1)"
66         fi
67
68         (cd "$(atf_get_srcdir)" && grep -r --exclude="*.out" -e "test" .) > d_grep_r_implied.out
69
70         atf_check -s exit:0 -x \
71             "(cd $(atf_get_srcdir) && grep -r --exclude=\"*.out\" -e \"test\") | diff d_grep_r_implied.out -"
72 }
73
74 atf_test_case rgrep
75 rgrep_head()
76 {
77         atf_set "require.progs" "rgrep"
78 }
79 rgrep_body()
80 {
81         atf_check -o save:d_grep_r_implied.out grep -r --exclude="*.out" -e "test" "$(atf_get_srcdir)"
82         atf_check -o file:d_grep_r_implied.out rgrep --exclude="*.out" -e "test" "$(atf_get_srcdir)"
83 }
84
85 atf_test_case gnuext
86 gnuext_body()
87 {
88         grep_type
89         _type=$?
90         if [ $_type -eq $GREP_TYPE_GNU_FREEBSD ]; then
91                 atf_expect_fail "\\s and \\S are known to be buggy in base gnugrep"
92         fi
93
94         atf_check -o save:grep_alnum.out grep -o '[[:alnum:]]' /COPYRIGHT
95         atf_check -o file:grep_alnum.out grep -o '\w' /COPYRIGHT
96
97         atf_check -o save:grep_nalnum.out grep -o '[^[:alnum:]]' /COPYRIGHT
98         atf_check -o file:grep_nalnum.out grep -o '\W' /COPYRIGHT
99
100         atf_check -o save:grep_space.out grep -o '[[:space:]]' /COPYRIGHT
101         atf_check -o file:grep_space.out grep -o '\s' /COPYRIGHT
102
103         atf_check -o save:grep_nspace.out grep -o '[^[:space:]]' /COPYRIGHT
104         atf_check -o file:grep_nspace.out grep -o '\S' /COPYRIGHT
105
106 }
107
108 atf_init_test_cases()
109 {
110         atf_add_test_case grep_r_implied
111         atf_add_test_case rgrep
112         atf_add_test_case gnuext
113 }