xref: /titanic_41/usr/src/cmd/tail/tests/tailtests.sh (revision 7535ae1914017b0e648abd7a139aca709fa82be3)
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#
23PROG=/usr/bin/tail
24
25case $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	;;
36esac
37
38echo "Using $PROG"
39
40o=`echo -e "bcd"`
41a=`echo -e "abcd" | $PROG +2c`
42[[ "$a" != "$o" ]] && echo "Fail test 1 - $a"
43
44o=`echo -e ""`
45a=`echo "abcd" | $PROG +8c`
46[[ "$a" != "$o" ]] && echo "Fail test 2 - $a"
47
48o=`echo -e "abcd"`
49a=`echo "abcd" | $PROG -9c`
50[[ "$a" != "$o" ]] && echo "Fail test 3 - $a"
51
52o=`echo -e "x"`
53a=`echo -e "x" | $PROG -1l`
54[[ "$a" != "x" ]] && echo "Fail test 4 - $a"
55
56o=`echo -e "\n"`
57a=`echo -e "x\ny\n" | $PROG -1l`
58[[ "$a" != "$o" ]] && echo "Fail test 5 - $a"
59
60o=`echo -e "y\n"`
61a=`echo -e "x\ny\n" | $PROG -2l`
62[[ "$a" != "$o" ]] && echo "Fail test 6 - $a"
63
64o=`echo -e "y"`
65a=`echo -e "x\ny" | $PROG -1l`
66[[ "$a" != "$o" ]] && echo "Fail test 7 - $a"
67
68o=`echo -e "x\ny\n"`
69a=`echo -e "x\ny\n" | $PROG +1l`
70[[ "$a" != "$o" ]] && echo "Fail test 8 - $a"
71
72o=`echo -e "y\n"`
73a=`echo -e "x\ny\n" | $PROG +2l`
74[[ "$a" != "$o" ]] && echo "Fail test 9 - $a"
75
76o=`echo -e "x"`
77a=`echo -e "x" | $PROG -1`
78[[ "$a" != "$o" ]] && echo "Fail test 10 - $a"
79
80o=`echo -e "\n"`
81a=`echo -e "x\ny\n" | $PROG -1`
82[[ "$a" != "$o" ]] && echo "Fail test 11 - $a"
83
84o=`echo -e "y\n"`
85a=`echo -e "x\ny\n" | $PROG -2`
86[[ "$a" != "$o" ]] && echo "Fail test 12 - $a"
87
88o=`echo -e "y"`
89a=`echo -e "x\ny" | $PROG -1`
90[[ "$a" != "$o" ]] && echo "Fail test 13 - $a"
91
92o=`echo -e "x\ny\n"`
93a=`echo -e "x\ny\n" | $PROG +1`
94[[ "$a" != "$o" ]] && echo "Fail test 14 - $a"
95
96o=`echo -e "y\n"`
97a=`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'
101o=`echo -e "yyz"`
102a=`echo -e "xyyyyyyyyyyz" | $PROG +10c`
103[[ "$a" != "$o" ]] && echo "Fail test 16 - $a"
104
105o=`echo -e "yyz"`
106a=`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'
111o=`echo -e "y\ny\nz"`
112a=`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
115o=`echo -e "y\ny\nz"`
116a=`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'
121o=`echo -e "y\ny\ny\ny\ny\ny\ny\ny\ny\nz"`
122a=`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
125o=`echo -e "y\ny\ny\ny\ny\ny\ny\ny\ny\nz"`
126a=`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
129o=`echo -e "c\nb\na"`
130a=`echo -e "a\nb\nc" | $PROG -r`
131[[ "$a" != "$o" ]] && echo "Fail test 19 - $a"
132
133
134echo "Completed"
135
136exit 0
137
138# Template for additional test cases
139#o=`echo -e ""`
140#a=`echo -e "" | $PROG `
141#[[ "$a" != "$o" ]] && echo "Fail test  - $a"
142