1*11be35a1SLionel Sambuc# $NetBSD: t_grep.sh,v 1.2 2013/05/17 15:39:17 christos Exp $ 2*11be35a1SLionel Sambuc# 3*11be35a1SLionel Sambuc# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. 4*11be35a1SLionel Sambuc# All rights reserved. 5*11be35a1SLionel Sambuc# 6*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 7*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 8*11be35a1SLionel Sambuc# are met: 9*11be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 10*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 11*11be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 12*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 13*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 14*11be35a1SLionel Sambuc# 15*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16*11be35a1SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17*11be35a1SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18*11be35a1SLionel Sambuc# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19*11be35a1SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*11be35a1SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*11be35a1SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*11be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*11be35a1SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*11be35a1SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*11be35a1SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE. 26*11be35a1SLionel Sambuc# 27*11be35a1SLionel Sambuc 28*11be35a1SLionel Sambucatf_test_case basic 29*11be35a1SLionel Sambucbasic_head() 30*11be35a1SLionel Sambuc{ 31*11be35a1SLionel Sambuc atf_set "descr" "Checks basic functionality" 32*11be35a1SLionel Sambuc} 33*11be35a1SLionel Sambucbasic_body() 34*11be35a1SLionel Sambuc{ 35*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_basic.out" -x \ 36*11be35a1SLionel Sambuc 'jot 10000 | grep 123' 37*11be35a1SLionel Sambuc} 38*11be35a1SLionel Sambuc 39*11be35a1SLionel Sambucatf_test_case binary 40*11be35a1SLionel Sambucbinary_head() 41*11be35a1SLionel Sambuc{ 42*11be35a1SLionel Sambuc atf_set "descr" "Checks handling of binary files" 43*11be35a1SLionel Sambuc} 44*11be35a1SLionel Sambucbinary_body() 45*11be35a1SLionel Sambuc{ 46*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep $(uname) /bin/sh 47*11be35a1SLionel Sambuc} 48*11be35a1SLionel Sambuc 49*11be35a1SLionel Sambucatf_test_case recurse 50*11be35a1SLionel Sambucrecurse_head() 51*11be35a1SLionel Sambuc{ 52*11be35a1SLionel Sambuc atf_set "descr" "Checks recursive searching" 53*11be35a1SLionel Sambuc} 54*11be35a1SLionel Sambucrecurse_body() 55*11be35a1SLionel Sambuc{ 56*11be35a1SLionel Sambuc mkdir -p recurse/a/f recurse/d 57*11be35a1SLionel Sambuc echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish 58*11be35a1SLionel Sambuc echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish 59*11be35a1SLionel Sambuc 60*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" grep -r haddock recurse 61*11be35a1SLionel Sambuc} 62*11be35a1SLionel Sambuc 63*11be35a1SLionel Sambucatf_test_case recurse_symlink 64*11be35a1SLionel Sambucrecurse_symlink_head() 65*11be35a1SLionel Sambuc{ 66*11be35a1SLionel Sambuc atf_set "descr" "Checks symbolic link recursion" 67*11be35a1SLionel Sambuc} 68*11be35a1SLionel Sambucrecurse_symlink_body() 69*11be35a1SLionel Sambuc{ 70*11be35a1SLionel Sambuc mkdir -p test/c/d 71*11be35a1SLionel Sambuc (cd test/c/d && ln -s ../d .) 72*11be35a1SLionel Sambuc echo "Test string" > test/c/match 73*11be35a1SLionel Sambuc 74*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_recurse_symlink.out" \ 75*11be35a1SLionel Sambuc -e file:"$(atf_get_srcdir)/d_recurse_symlink.err" \ 76*11be35a1SLionel Sambuc grep -r string test 77*11be35a1SLionel Sambuc} 78*11be35a1SLionel Sambuc 79*11be35a1SLionel Sambucatf_test_case word_regexps 80*11be35a1SLionel Sambucword_regexps_head() 81*11be35a1SLionel Sambuc{ 82*11be35a1SLionel Sambuc atf_set "descr" "Checks word-regexps" 83*11be35a1SLionel Sambuc} 84*11be35a1SLionel Sambucword_regexps_body() 85*11be35a1SLionel Sambuc{ 86*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_word_regexps.out" \ 87*11be35a1SLionel Sambuc grep -w separated $(atf_get_srcdir)/d_input 88*11be35a1SLionel Sambuc} 89*11be35a1SLionel Sambuc 90*11be35a1SLionel Sambucatf_test_case begin_end 91*11be35a1SLionel Sambucbegin_end_head() 92*11be35a1SLionel Sambuc{ 93*11be35a1SLionel Sambuc atf_set "descr" "Checks handling of line beginnings and ends" 94*11be35a1SLionel Sambuc} 95*11be35a1SLionel Sambucbegin_end_body() 96*11be35a1SLionel Sambuc{ 97*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_begin_end_a.out" \ 98*11be35a1SLionel Sambuc grep ^Front "$(atf_get_srcdir)/d_input" 99*11be35a1SLionel Sambuc 100*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_begin_end_b.out" \ 101*11be35a1SLionel Sambuc grep ending$ "$(atf_get_srcdir)/d_input" 102*11be35a1SLionel Sambuc} 103*11be35a1SLionel Sambuc 104*11be35a1SLionel Sambucatf_test_case ignore_case 105*11be35a1SLionel Sambucignore_case_head() 106*11be35a1SLionel Sambuc{ 107*11be35a1SLionel Sambuc atf_set "descr" "Checks ignore-case option" 108*11be35a1SLionel Sambuc} 109*11be35a1SLionel Sambucignore_case_body() 110*11be35a1SLionel Sambuc{ 111*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_ignore_case.out" \ 112*11be35a1SLionel Sambuc grep -i Upper "$(atf_get_srcdir)/d_input" 113*11be35a1SLionel Sambuc} 114*11be35a1SLionel Sambuc 115*11be35a1SLionel Sambucatf_test_case invert 116*11be35a1SLionel Sambucinvert_head() 117*11be35a1SLionel Sambuc{ 118*11be35a1SLionel Sambuc atf_set "descr" "Checks selecting non-matching lines with -v option" 119*11be35a1SLionel Sambuc} 120*11be35a1SLionel Sambucinvert_body() 121*11be35a1SLionel Sambuc{ 122*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_invert.out" \ 123*11be35a1SLionel Sambuc grep -v fish "$(atf_get_srcdir)/d_invert.in" 124*11be35a1SLionel Sambuc} 125*11be35a1SLionel Sambuc 126*11be35a1SLionel Sambucatf_test_case whole_line 127*11be35a1SLionel Sambucwhole_line_head() 128*11be35a1SLionel Sambuc{ 129*11be35a1SLionel Sambuc atf_set "descr" "Checks whole-line matching with -x flag" 130*11be35a1SLionel Sambuc} 131*11be35a1SLionel Sambucwhole_line_body() 132*11be35a1SLionel Sambuc{ 133*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_whole_line.out" \ 134*11be35a1SLionel Sambuc grep -x matchme "$(atf_get_srcdir)/d_input" 135*11be35a1SLionel Sambuc} 136*11be35a1SLionel Sambuc 137*11be35a1SLionel Sambucatf_test_case negative 138*11be35a1SLionel Sambucnegative_head() 139*11be35a1SLionel Sambuc{ 140*11be35a1SLionel Sambuc atf_set "descr" "Checks handling of files with no matches" 141*11be35a1SLionel Sambuc} 142*11be35a1SLionel Sambucnegative_body() 143*11be35a1SLionel Sambuc{ 144*11be35a1SLionel Sambuc atf_check -s ne:0 grep "not a hope in hell" "$(atf_get_srcdir)/d_input" 145*11be35a1SLionel Sambuc} 146*11be35a1SLionel Sambuc 147*11be35a1SLionel Sambucatf_test_case context 148*11be35a1SLionel Sambuccontext_head() 149*11be35a1SLionel Sambuc{ 150*11be35a1SLionel Sambuc atf_set "descr" "Checks displaying context with -A, -B and -C flags" 151*11be35a1SLionel Sambuc} 152*11be35a1SLionel Sambuccontext_body() 153*11be35a1SLionel Sambuc{ 154*11be35a1SLionel Sambuc cp $(atf_get_srcdir)/d_context_*.* . 155*11be35a1SLionel Sambuc 156*11be35a1SLionel Sambuc atf_check -o file:d_context_a.out grep -C2 bamboo d_context_a.in 157*11be35a1SLionel Sambuc atf_check -o file:d_context_b.out grep -A3 tilt d_context_a.in 158*11be35a1SLionel Sambuc atf_check -o file:d_context_c.out grep -B4 Whig d_context_a.in 159*11be35a1SLionel Sambuc atf_check -o file:d_context_d.out grep -C1 pig d_context_a.in d_context_b.in 160*11be35a1SLionel Sambuc} 161*11be35a1SLionel Sambuc 162*11be35a1SLionel Sambucatf_test_case file_exp 163*11be35a1SLionel Sambucfile_exp_head() 164*11be35a1SLionel Sambuc{ 165*11be35a1SLionel Sambuc atf_set "descr" "Checks reading expressions from file" 166*11be35a1SLionel Sambuc} 167*11be35a1SLionel Sambucfile_exp_body() 168*11be35a1SLionel Sambuc{ 169*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_file_exp.out" -x \ 170*11be35a1SLionel Sambuc 'jot 21 -1 1.00 | grep -f '"$(atf_get_srcdir)"'/d_file_exp.in' 171*11be35a1SLionel Sambuc} 172*11be35a1SLionel Sambuc 173*11be35a1SLionel Sambucatf_test_case egrep 174*11be35a1SLionel Sambucegrep_head() 175*11be35a1SLionel Sambuc{ 176*11be35a1SLionel Sambuc atf_set "descr" "Checks matching special characters with egrep" 177*11be35a1SLionel Sambuc} 178*11be35a1SLionel Sambucegrep_body() 179*11be35a1SLionel Sambuc{ 180*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_egrep.out" \ 181*11be35a1SLionel Sambuc egrep '\?|\*$$' "$(atf_get_srcdir)/d_input" 182*11be35a1SLionel Sambuc} 183*11be35a1SLionel Sambuc 184*11be35a1SLionel Sambucatf_test_case zgrep 185*11be35a1SLionel Sambuczgrep_head() 186*11be35a1SLionel Sambuc{ 187*11be35a1SLionel Sambuc atf_set "descr" "Checks handling of gzipped files with zgrep" 188*11be35a1SLionel Sambuc} 189*11be35a1SLionel Sambuczgrep_body() 190*11be35a1SLionel Sambuc{ 191*11be35a1SLionel Sambuc cp "$(atf_get_srcdir)/d_input" . 192*11be35a1SLionel Sambuc gzip d_input || atf_fail "gzip failed" 193*11be35a1SLionel Sambuc 194*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_zgrep.out" zgrep -h line d_input.gz 195*11be35a1SLionel Sambuc} 196*11be35a1SLionel Sambuc 197*11be35a1SLionel Sambucatf_test_case nonexistent 198*11be35a1SLionel Sambucnonexistent_head() 199*11be35a1SLionel Sambuc{ 200*11be35a1SLionel Sambuc atf_set "descr" "Checks that -s flag suppresses error" \ 201*11be35a1SLionel Sambuc "messages about nonexistent files" 202*11be35a1SLionel Sambuc} 203*11be35a1SLionel Sambucnonexistent_body() 204*11be35a1SLionel Sambuc{ 205*11be35a1SLionel Sambuc atf_check -s ne:0 grep -s foobar nonexistent 206*11be35a1SLionel Sambuc} 207*11be35a1SLionel Sambuc 208*11be35a1SLionel Sambucatf_test_case context2 209*11be35a1SLionel Sambuccontext2_head() 210*11be35a1SLionel Sambuc{ 211*11be35a1SLionel Sambuc atf_set "descr" "Checks displaying context with -z flag" 212*11be35a1SLionel Sambuc} 213*11be35a1SLionel Sambuccontext2_body() 214*11be35a1SLionel Sambuc{ 215*11be35a1SLionel Sambuc printf "haddock\000cod\000plaice\000" > test1 216*11be35a1SLionel Sambuc printf "mackeral\000cod\000crab\000" > test2 217*11be35a1SLionel Sambuc 218*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_context2_a.out" \ 219*11be35a1SLionel Sambuc grep -z -A1 cod test1 test2 220*11be35a1SLionel Sambuc 221*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_context2_b.out" \ 222*11be35a1SLionel Sambuc grep -z -B1 cod test1 test2 223*11be35a1SLionel Sambuc 224*11be35a1SLionel Sambuc atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \ 225*11be35a1SLionel Sambuc grep -z -C1 cod test1 test2 226*11be35a1SLionel Sambuc} 227*11be35a1SLionel Sambuc 228*11be35a1SLionel Sambucatf_init_test_cases() 229*11be35a1SLionel Sambuc{ 230*11be35a1SLionel Sambuc atf_add_test_case basic 231*11be35a1SLionel Sambuc atf_add_test_case binary 232*11be35a1SLionel Sambuc atf_add_test_case recurse 233*11be35a1SLionel Sambuc atf_add_test_case recurse_symlink 234*11be35a1SLionel Sambuc atf_add_test_case word_regexps 235*11be35a1SLionel Sambuc atf_add_test_case begin_end 236*11be35a1SLionel Sambuc atf_add_test_case ignore_case 237*11be35a1SLionel Sambuc atf_add_test_case invert 238*11be35a1SLionel Sambuc atf_add_test_case whole_line 239*11be35a1SLionel Sambuc atf_add_test_case negative 240*11be35a1SLionel Sambuc atf_add_test_case context 241*11be35a1SLionel Sambuc atf_add_test_case file_exp 242*11be35a1SLionel Sambuc atf_add_test_case egrep 243*11be35a1SLionel Sambuc atf_add_test_case zgrep 244*11be35a1SLionel Sambuc atf_add_test_case nonexistent 245*11be35a1SLionel Sambuc atf_add_test_case context2 246*11be35a1SLionel Sambuc} 247