blob: f4b8667360e30865dc41b415b270def0402ab5c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/bin/bash
[ -f testing.sh ] && . testing.sh
#testing "name" "command" "result" "infile" "stdin"
BIGTEST="one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n"
echo -ne "$BIGTEST" > file1
testing "tail" "tail && echo yes" "oneyes\n" "" "one"
testing "tail file" "tail file1" \
"two\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" ""
testing "tail -n in bounds" "tail -n 3 file1" "nine\nten\neleven\n" "" ""
testing "tail -n out of bounds" "tail -n 999 file1" "$BIGTEST" "" ""
testing "tail -n+ in bounds" "tail -n +3 file1" \
"three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" ""
testing "tail -n+ outof bounds" "tail -n +999 file1" "" "" ""
testing "tail -c in bounds" "tail -c 27 file1" \
"even\neight\nnine\nten\neleven\n" "" ""
testing "tail -c out of bounds" "tail -c 999 file1" "$BIGTEST" "" ""
testing "tail -c+ in bounds" "tail -c +27 file1" \
"x\nseven\neight\nnine\nten\neleven\n" "" ""
testing "tail -c+ out of bonds" "tail -c +999 file1" "" "" ""
rm file1
testing "tail stdin no trailing newline" "tail -n 1 - " "c" "" "a\nb\nc"
testing "tail file no trailing newline" "tail -n 1 input" "c" "a\nb\nc" ""
optional TAIL_SEEK
testing "tail noseek -n in bounds" "tail -n 3" "nine\nten\neleven\n" \
"" "$BIGTEST"
testing "tail noseek -n out of bounds" "tail -n 999" "$BIGTEST" "" "$BIGTEST"
testing "tail noseek -n+ in bounds" "tail -n +3" \
"three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" \
"$BIGTEST"
testing "tail noseek -n+ outof bounds" "tail -n +999" "" "" "$BIGTEST"
testing "tail noseek -c in bounds" "tail -c 27" \
"even\neight\nnine\nten\neleven\n" "" "$BIGTEST"
testing "tail noseek -c out of bounds" "tail -c 999" "$BIGTEST" "" "$BIGTEST"
testing "tail noseek -c+ in bounds" "tail -c +27" \
"x\nseven\neight\nnine\nten\neleven\n" "" "$BIGTEST"
testing "tail noseek -c+ out of bonds" "tail -c +999" "" "" "$BIGTEST"
makebigfile()
{
for j in $(seq 1 100)
do
printf "%s " $j
for i in $(seq 1 100)
do
printf %s 123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
done
echo
done
}
makebigfile > bigfile
testing "tail -c 12345 -n 3 bigfile" "tail -c 12345 -n 3 bigfile | md5sum" \
"347bbdcbad8a313f4dc7bd558c5bfcb8 -\n" "" ""
testing "tail -n 3 -c 12345 bigfile" "tail -n 3 -c 12345 bigfile | md5sum" \
"1698825a750288284ec3ba7d8a59f302 -\n" "" ""
|