1 #!/bin/bash 2 # 3 # 4 # This file and its contents are supplied under the terms of the 5 # Common Development and Distribution License ("CDDL"), version 1.0. 6 # You may only use this file in accordance with the terms of version 7 # 1.0 of the CDDL. 8 # 9 # A full copy of the text of the CDDL should have accompanied this 10 # source. A copy is of the CDDL is also available via the Internet 11 # at http://www.illumos.org/license/CDDL. 12 # 13 14 # 15 # Copyright 2010 Chris Love. All rights reserved. 16 # 17 18 19 # 20 # Test cases for 'tail', some based on CoreUtils test cases (validated 21 # with legacy Solaris 'tail' and/or xpg4 'tail') 22 # 23 PROG=/usr/bin/tail 24 25 case $1 in 26 -x) 27 PROG=/usr/xpg4/bin/tail 28 ;; 29 -o) 30 PROG=$2 31 ;; 32 -?) 33 echo "Usage: tailtests.sh [-x][-o <override tail executable>]" 34 exit 1 35 ;; 36 esac 37 38 echo "Using $PROG" 39 40 o=`echo -e "bcd"` 41 a=`echo -e "abcd" | $PROG +2c` 42 [[ "$a" != "$o" ]] && echo "Fail test 1 - $a" 43 44 o=`echo -e ""` 45 a=`echo "abcd" | $PROG +8c` 46 [[ "$a" != "$o" ]] && echo "Fail test 2 - $a" 47 48 o=`echo -e "abcd"` 49 a=`echo "abcd" | $PROG -9c` 50 [[ "$a" != "$o" ]] && echo "Fail test 3 - $a" 51 52 o=`echo -e "x"` 53 a=`echo -e "x" | $PROG -1l` 54 [[ "$a" != "x" ]] && echo "Fail test 4 - $a" 55 56 o=`echo -e "\n"` 57 a=`echo -e "x\ny\n" | $PROG -1l` 58 [[ "$a" != "$o" ]] && echo "Fail test 5 - $a" 59 60 o=`echo -e "y\n"` 61 a=`echo -e "x\ny\n" | $PROG -2l` 62 [[ "$a" != "$o" ]] && echo "Fail test 6 - $a" 63 64 o=`echo -e "y"` 65 a=`echo -e "x\ny" | $PROG -1l` 66 [[ "$a" != "$o" ]] && echo "Fail test 7 - $a" 67 68 o=`echo -e "x\ny\n"` 69 a=`echo -e "x\ny\n" | $PROG +1l` 70 [[ "$a" != "$o" ]] && echo "Fail test 8 - $a" 71 72 o=`echo -e "y\n"` 73 a=`echo -e "x\ny\n" | $PROG +2l` 74 [[ "$a" != "$o" ]] && echo "Fail test 9 - $a" 75 76 o=`echo -e "x"` 77 a=`echo -e "x" | $PROG -1` 78 [[ "$a" != "$o" ]] && echo "Fail test 10 - $a" 79 80 o=`echo -e "\n"` 81 a=`echo -e "x\ny\n" | $PROG -1` 82 [[ "$a" != "$o" ]] && echo "Fail test 11 - $a" 83 84 o=`echo -e "y\n"` 85 a=`echo -e "x\ny\n" | $PROG -2` 86 [[ "$a" != "$o" ]] && echo "Fail test 12 - $a" 87 88 o=`echo -e "y"` 89 a=`echo -e "x\ny" | $PROG -1` 90 [[ "$a" != "$o" ]] && echo "Fail test 13 - $a" 91 92 o=`echo -e "x\ny\n"` 93 a=`echo -e "x\ny\n" | $PROG +1` 94 [[ "$a" != "$o" ]] && echo "Fail test 14 - $a" 95 96 o=`echo -e "y\n"` 97 a=`echo -e "x\ny\n" | $PROG +2` 98 [[ "$a" != "$o" ]] && echo "Fail test 15 - $a" 99 100 # For compatibility with Legacy Solaris tail this should also work as '+c' 101 o=`echo -e "yyz"` 102 a=`echo -e "xyyyyyyyyyyz" | $PROG +10c` 103 [[ "$a" != "$o" ]] && echo "Fail test 16 - $a" 104 105 o=`echo -e "yyz"` 106 a=`echo -e "xyyyyyyyyyyz" | $PROG +c` 107 [[ "$a" != "$o" ]] && echo "Fail test 16a - $a" 108 109 110 # For compatibility with Legacy Solaris tail this should also work as '+l' 111 o=`echo -e "y\ny\nz"` 112 a=`echo -e "x\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\nz" | $PROG +10l` 113 [[ "$a" != "$o" ]] && echo "Fail test 17 - $a" 114 115 o=`echo -e "y\ny\nz"` 116 a=`echo -e "x\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\nz" | $PROG +l` 117 [[ "$a" != "$o" ]] && echo "Fail test 17a - $a" 118 119 120 # For compatibility with Legacy Solaris tail this should also work as '-l' 121 o=`echo -e "y\ny\ny\ny\ny\ny\ny\ny\ny\nz"` 122 a=`echo -e "x\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\nz" | $PROG -10l` 123 [[ "$a" != "$o" ]] && echo "Fail test 18 - $a" 124 125 o=`echo -e "y\ny\ny\ny\ny\ny\ny\ny\ny\nz"` 126 a=`echo -e "x\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\nz" | $PROG -l` 127 [[ "$a" != "$o" ]] && echo "Fail test 18a - $a" 128 129 o=`echo -e "c\nb\na"` 130 a=`echo -e "a\nb\nc" | $PROG -r` 131 [[ "$a" != "$o" ]] && echo "Fail test 19 - $a" 132 133 134 echo "Completed" 135 136 exit 0 137 138 # Template for additional test cases 139 #o=`echo -e ""` 140 #a=`echo -e "" | $PROG ` 141 #[[ "$a" != "$o" ]] && echo "Fail test - $a"