Blame tests/foad1

Packit 709fb3
#! /bin/sh
Packit 709fb3
# Test various combinations of command-line options.
Packit 709fb3
#
Packit 709fb3
# Copyright (C) 2001, 2006, 2009-2017 Free Software Foundation, Inc.
Packit 709fb3
#
Packit 709fb3
# Copying and distribution of this file, with or without modification,
Packit 709fb3
# are permitted in any medium without royalty provided the copyright
Packit 709fb3
# notice and this notice are preserved.
Packit 709fb3
#
Packit 709fb3
# This set of tests was started by Julian Foad.
Packit 709fb3
Packit 709fb3
. "${srcdir=.}/init.sh"; path_prepend_ ../src
Packit 709fb3
Packit 709fb3
failures=0
Packit 709fb3
Packit 709fb3
# grep_test INPUT EXPECTED_OUTPUT PATTERN_AND_OPTIONS...
Packit 709fb3
# Run "grep" with the given INPUT, pattern and options, and check that
Packit 709fb3
# the output is EXPECTED_OUTPUT.  If not, print a message and set 'failures'.
Packit 709fb3
# "/" represents a newline within INPUT and EXPECTED_OUTPUT.
Packit 709fb3
grep_test ()
Packit 709fb3
{
Packit 709fb3
  INPUT="$1"
Packit 709fb3
  EXPECT="$2"
Packit 709fb3
  shift 2
Packit 709fb3
  OUTPUT=$(printf %s "$INPUT" | tr "/" "\n" | grep "$@" | tr "\n" "/")
Packit 709fb3
  if test "$OUTPUT" != "$EXPECT" || test "$VERBOSE" = "yes"; then
Packit 709fb3
    echo "Testing:  grep $@"
Packit 709fb3
    test "$LC_ALL" != C && test "$LC_ALL" != "" && echo "  LC_ALL: \"$LC_ALL\""
Packit 709fb3
    echo "  input:  \"$INPUT\""
Packit 709fb3
    echo "  output: \"$OUTPUT\""
Packit 709fb3
  fi
Packit 709fb3
  if test "$OUTPUT" != "$EXPECT"; then
Packit 709fb3
    echo "  expect: \"$EXPECT\""
Packit 709fb3
    echo "FAIL"
Packit 709fb3
    failures=1
Packit 709fb3
  fi
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
Packit 709fb3
# Test "--only-matching" ("-o") option
Packit 709fb3
Packit 709fb3
# "-o" with "-i" should output an exact copy of the matching input text.
Packit 709fb3
grep_test "WordA/wordB/WORDC/" "Word/word/WORD/" "word" -o -i
Packit 709fb3
grep_test "WordA/wordB/WORDC/" "Word/word/WORD/" "Word" -o -i
Packit 709fb3
grep_test "WordA/wordB/WORDC/" "Word/word/WORD/" "WORD" -o -i
Packit 709fb3
Packit 709fb3
# Should display the line number (-n), octet offset (-b), or file name
Packit 709fb3
# (-H) of every match, not just of the first match on each input line.
Packit 709fb3
# Check it both with and without -i because of the separate code paths.
Packit 709fb3
# Also check what it does when lines of context are specified.
Packit 709fb3
grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n
Packit 709fb3
grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n -i
Packit 709fb3
grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n -3 2>/dev/null
Packit 709fb3
grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b
Packit 709fb3
grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b -i
Packit 709fb3
grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b -3 2>/dev/null
Packit 709fb3
grep_test "XwA YwB/ZwC/" "1:w/5:w/9:w/" "w" -F -o -b
Packit 709fb3
grep_test "XwA YwB/ZwC/" "1:w/5:w/9:w/" "w" -F -o -b -i
Packit 709fb3
grep_test "XwA YwB/ZwC/" "1:w/5:w/9:w/" "w" -F -o -b -3 2>/dev/null
Packit 709fb3
grep_test "wA wB/" "(standard input):wA/(standard input):wB/" "w." -o -H
Packit 709fb3
grep_test "wA wB/" "(standard input):wA/(standard input):wB/" "w." -o -H -i
Packit 709fb3
grep_test "wA wB/" "(standard input):wA/(standard input):wB/" "w." -o -H -3 2>/dev/null
Packit 709fb3
Packit 709fb3
# Combination of -h and -H
Packit 709fb3
grep_test "wA wB/" "wA wB/" "w."
Packit 709fb3
grep_test "wA wB/" "wA wB/" "w." -h
Packit 709fb3
grep_test "wA wB/" "wA wB/" "w." -H -h
Packit 709fb3
grep_test "wA wB/" "(standard input):wA wB/" "w." -H
Packit 709fb3
grep_test "wA wB/" "(standard input):wA wB/" "w." -h -H
Packit 709fb3
Packit 709fb3
# End of a previous match should not match a "start of ..." expression.
Packit 709fb3
grep_test "word_word/" "word_/" "^word_*" -o
Packit 709fb3
grep_test "wordword/" "word/" "\
Packit 709fb3
Packit 709fb3
Packit 709fb3
# Test "--color" option
Packit 709fb3
Packit 709fb3
CB="?[01;31m?[K"
Packit 709fb3
CE="?[m?[K"
Packit 709fb3
Packit 709fb3
# "--color" with "-i" should output an exact copy of the matching input text.
Packit 709fb3
grep_test "WordA/wordb/WORDC/" "${CB}Word${CE}A/${CB}word${CE}b/${CB}WORD${CE}C/" "word" --color=always -i
Packit 709fb3
grep_test "WordA/wordb/WORDC/" "${CB}Word${CE}A/${CB}word${CE}b/${CB}WORD${CE}C/" "Word" --color=always -i
Packit 709fb3
grep_test "WordA/wordb/WORDC/" "${CB}Word${CE}A/${CB}word${CE}b/${CB}WORD${CE}C/" "WORD" --color=always -i
Packit 709fb3
Packit 709fb3
# End of a previous match should not match a "start of ..." expression.
Packit 709fb3
grep_test "word_word/" "${CB}word_${CE}word/" "^word_*" --color=always
Packit 709fb3
grep_test "wordword/" "${CB}word${CE}word/" "\
Packit 709fb3
Packit 709fb3
Packit 709fb3
# Test combination of "-m" with "-A" and anchors.
Packit 709fb3
# Based on a report from Pavol Gono.
Packit 709fb3
grep_test "4/40/"  "4/40/"  "^4$" -m1 -A99
Packit 709fb3
grep_test "4/04/"  "4/04/"  "^4$" -m1 -A99
Packit 709fb3
grep_test "4/444/" "4/444/" "^4$" -m1 -A99
Packit 709fb3
grep_test "4/40/"  "4/40/"  "^4"  -m1 -A99
Packit 709fb3
grep_test "4/04/"  "4/04/"  "^4"  -m1 -A99
Packit 709fb3
grep_test "4/444/" "4/444/" "^4"  -m1 -A99
Packit 709fb3
grep_test "4/40/"  "4/40/"  "4$"  -m1 -A99
Packit 709fb3
grep_test "4/04/"  "4/04/"  "4$"  -m1 -A99
Packit 709fb3
grep_test "4/444/" "4/444/" "4$"  -m1 -A99
Packit 709fb3
Packit 709fb3
Packit 709fb3
# Test for "-F -w" bugs.  Thanks to Gordon Lack for these two.
Packit 709fb3
grep_test "A/CX/B/C/" "A/B/C/" -wF -e A -e B -e C
Packit 709fb3
grep_test "LIN7C 55327/" "" -wF -e 5327 -e 5532
Packit 709fb3
Packit 709fb3
# Test for non-empty matches following empty ones.
Packit 709fb3
grep_test 'xyz/' 'y/' -o 'y*'
Packit 709fb3
grep_test 'xyz/' "x${CB}y${CE}z/" --color=always 'y*'
Packit 709fb3
Packit 709fb3
# Test for increasing/decreasing-length word matches,
Packit 709fb3
# for independence from pattern order within the pattern list,
Packit 709fb3
# and for preferring the longest match at a given position.
Packit 709fb3
x0='a bb ccc dddd/'
Packit 709fb3
x1='dddd ccc bb a/'
Packit 709fb3
x2='bcd abcd abc bc bcd abc/'
Packit 709fb3
x3='bc abcd bc/'
Packit 709fb3
y0="a ${CB}bb${CE} ${CB}ccc${CE} dddd/"
Packit 709fb3
y1="dddd ${CB}ccc${CE} ${CB}bb${CE} a/"
Packit 709fb3
y2="bcd abcd abc ${CB}bc${CE} bcd abc/"
Packit 709fb3
y3="${CB}bc${CE} abcd ${CB}bc${CE}/"
Packit 709fb3
grep_test "$x0" "$y0" -E --color=always -e bb -e cc -e ccc
Packit 709fb3
grep_test "$x0" "$y0" -F --color=always -e bb -e cc -e ccc
Packit 709fb3
grep_test "$x0" "$y0" -E --color=always -e bb -e ccc -e cc
Packit 709fb3
grep_test "$x0" "$y0" -F --color=always -e bb -e ccc -e cc
Packit 709fb3
grep_test "$x0" "$y0" -E -w --color=always -e bb -e ccc
Packit 709fb3
grep_test "$x0" "$y0" -F -w --color=always -e bb -e ccc
Packit 709fb3
grep_test "$x0" "$y0" -E -w --color=always -e ccc -e bb
Packit 709fb3
grep_test "$x0" "$y0" -F -w --color=always -e ccc -e bb
Packit 709fb3
grep_test "$x1" "$y1" -E -w --color=always -e bb -e ccc
Packit 709fb3
grep_test "$x1" "$y1" -F -w --color=always -e bb -e ccc
Packit 709fb3
grep_test "$x1" "$y1" -E -w --color=always -e ccc -e bb
Packit 709fb3
grep_test "$x1" "$y1" -F -w --color=always -e ccc -e bb
Packit 709fb3
grep_test "$x2" "$y2" -E -w --color=always bc
Packit 709fb3
grep_test "$x2" "$y2" -F -w --color=always bc
Packit 709fb3
grep_test "$x3" "$y3" -E -w --color=always bc
Packit 709fb3
grep_test "$x3" "$y3" -F -w --color=always bc
Packit 709fb3
Packit 709fb3
# Bug#25655
Packit 709fb3
grep_test .tar/ .tar/ -e '\.tar' -e '\.tbz'
Packit 709fb3
grep_test .tar/ .tar/ -o -e '\.tar' -e 'tar'
Packit 709fb3
grep_test '$*.[^\/' '$*.[^\/' -o -e '\$\*\.\[\^\\' -e abc
Packit 709fb3
grep_test '$*.[^\/(+?{|/' '$*.[^\/(+?{|/' -o -E \
Packit 709fb3
          -e '\$\*\.\[\^\\' -e '\(\+\?\{\|'
Packit 709fb3
Packit 709fb3
# Skip the rest of the tests - known to fail. TAA.
Packit 709fb3
Exit $failures
Packit 709fb3
Packit 709fb3
# The rest of this file is meant to be executed under this locale.
Packit 709fb3
LC_ALL=cs_CZ.UTF-8; export LC_ALL
Packit 709fb3
# If the UTF-8 locale doesn't work, skip these tests silently.
Packit 709fb3
locale -k LC_CTYPE 2>/dev/null | grep -q "charmap.*UTF-8" || Exit $failures
Packit 709fb3
Packit 709fb3
# Test character class erroneously matching a '[' character.
Packit 709fb3
grep_test "[/" "" "[[:alpha:]]" -E
Packit 709fb3
Packit 709fb3
for mode in F G E; do
Packit 709fb3
  # Hint:  pipe the output of these tests in
Packit 709fb3
  #        "| LESS= LESSCHARSET=ascii less".
Packit 709fb3
  # LETTER N WITH TILDE is U+00F1 and U+00D1.
Packit 709fb3
  # LETTER Y WITH DIAERESIS is U+00FF and U+0178.
Packit 709fb3
  grep_test 'añÿb/AÑŸB/' 'ñÿ/ÑŸ/' 'ñÿ' -o -i -$mode
Packit 709fb3
  grep_test 'añÿb/AÑŸB/' 'ñÿ/ÑŸ/' 'ÑŸ' -o -i -$mode
Packit 709fb3
  grep_test 'añÿb/AÑŸB/' "a${CB}ñÿ${CE}b/A${CB}ÑŸ${CE}B/" 'ñÿ' --color=always -i -$mode
Packit 709fb3
  grep_test 'añÿb/AÑŸB/' "a${CB}ñÿ${CE}b/A${CB}ÑŸ${CE}B/" 'ÑŸ' --color=always -i -$mode
Packit 709fb3
Packit 709fb3
  # POSIX (about -i):  ... each character in the string is matched
Packit 709fb3
  # against the pattern, not only the character, but also its case
Packit 709fb3
  # counterpart (if any), shall be matched.
Packit 709fb3
  # The following were chosen because of their trickiness due to the
Packit 709fb3
  # differing UTF-8 octet length of their counterpart and to the
Packit 709fb3
  # non-reflexivity of their mapping.
Packit 709fb3
  # Beware of homographs!  Look carefully at the actual octets.
Packit 709fb3
Packit 709fb3
  # lc(U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE) = U+0069 LATIN SMALL LETTER I
Packit 709fb3
  grep_test 'aÄ°b/' "a${CB}Ä°${CE}b/" 'i' --color=always -i -$mode
Packit 709fb3
  grep_test 'aib/' ''               'Ä°' --color=always -i -$mode
Packit 709fb3
  grep_test 'aÄ°b/' ''               'I' --color=always -i -$mode
Packit 709fb3
  # uc(U+0131 LATIN SMALL LETTER DOTLESS I)          = U+0049 LATIN CAPITAL LETTER I
Packit 709fb3
  grep_test 'aıb/' "a${CB}ı${CE}b/" 'I' --color=always -i -$mode
Packit 709fb3
  grep_test 'aIb/' ''               'ı' --color=always -i -$mode
Packit 709fb3
  grep_test 'aıb/' ''               'i' --color=always -i -$mode
Packit 709fb3
  # uc(U+017F LATIN SMALL LETTER LONG S)             = U+0053 LATIN CAPITAL LETTER S
Packit 709fb3
  grep_test 'aſb/' "a${CB}ſ${CE}b/" 'S' --color=always -i -$mode
Packit 709fb3
  grep_test 'aSb/' ''               'Å¿' --color=always -i -$mode
Packit 709fb3
  grep_test 'aſb/' ''               's' --color=always -i -$mode
Packit 709fb3
  # uc(U+1FBE GREEK PROSGEGRAMMENI)                  = U+0399 GREEK CAPITAL LETTER IOTA
Packit 709fb3
  grep_test 'aιb/' "a${CB}ι${CE}b/" 'Ι' --color=always -i -$mode
Packit 709fb3
  grep_test 'aΙb/' ''               'ι' --color=always -i -$mode
Packit 709fb3
  grep_test 'aιb/' ''               'ι' --color=always -i -$mode
Packit 709fb3
  # lc(U+2126 OHM SIGN)                              = U+03C9 GREEK SMALL LETTER OMEGA
Packit 709fb3
  grep_test 'aΩb/' "a${CB}Ω${CE}b/" 'ω' --color=always -i -$mode
Packit 709fb3
  grep_test 'aωb/' ''               'Ω' --color=always -i -$mode
Packit 709fb3
  grep_test 'aΩb/' ''               'Ω' --color=always -i -$mode
Packit 709fb3
  # lc(U+212A KELVIN SIGN)                           = U+006B LATIN SMALL LETTER K
Packit 709fb3
  grep_test 'aKb/' "a${CB}K${CE}b/" 'k' --color=always -i -$mode
Packit 709fb3
  grep_test 'akb/' ''               'K' --color=always -i -$mode
Packit 709fb3
  grep_test 'aKb/' ''               'K' --color=always -i -$mode
Packit 709fb3
  # lc(U+212B ANGSTROM SIGN)                         = U+00E5 LATIN SMALL LETTER A WITH RING ABOVE
Packit 709fb3
  grep_test 'aâ„«b/' "a${CB}â„«${CE}b/" 'Ã¥' --color=always -i -$mode
Packit 709fb3
  grep_test 'aåb/' ''               'Å' --color=always -i -$mode
Packit 709fb3
  grep_test 'aâ„«b/' ''               'Ã…' --color=always -i -$mode
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
Packit 709fb3
# Any tests inserted right here will be performed under an UTF-8 locale.
Packit 709fb3
# Insert them before LC_ALL is set above to avoid this.
Packit 709fb3
# Leave this comment last.
Packit 709fb3
Packit 709fb3
Exit $failures