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