1#!/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 "file" "tail file1" \ 11 "two\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" "" 12testing "-n in bounds" "tail -n 3 file1" "nine\nten\neleven\n" "" "" 13testing "-n out of bounds" "tail -n 999 file1" "$BIGTEST" "" "" 14testing "-n+ in bounds" "tail -n +3 file1" \ 15 "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" "" 16testing "-n+ outof bounds" "tail -n +999 file1" "" "" "" 17testing "-c in bounds" "tail -c 27 file1" \ 18 "even\neight\nnine\nten\neleven\n" "" "" 19testing "-c out of bounds" "tail -c 999 file1" "$BIGTEST" "" "" 20testing "-c+ in bounds" "tail -c +27 file1" \ 21 "x\nseven\neight\nnine\nten\neleven\n" "" "" 22testing "-c+ out of bonds" "tail -c +999 file1" "" "" "" 23testing "-N" "tail -1 file1" "eleven\n" "" "" 24rm file1 25 26testing "stdin no trailing newline" "tail -n 1 - " "c" "" "a\nb\nc" 27testing "file no trailing newline" "tail -n 1 input" "c" "a\nb\nc" "" 28 29optional TAIL_SEEK 30testing "noseek -n in bounds" "tail -n 3" "nine\nten\neleven\n" \ 31 "" "$BIGTEST" 32testing "noseek -n out of bounds" "tail -n 999" "$BIGTEST" "" "$BIGTEST" 33testing "noseek -n+ in bounds" "tail -n +3" \ 34 "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" \ 35 "$BIGTEST" 36testing "noseek -n+ outof bounds" "tail -n +999" "" "" "$BIGTEST" 37testing "noseek -c in bounds" "tail -c 27" \ 38 "even\neight\nnine\nten\neleven\n" "" "$BIGTEST" 39testing "noseek -c out of bounds" "tail -c 999" "$BIGTEST" "" "$BIGTEST" 40testing "noseek -c+ in bounds" "tail -c +27" \ 41 "x\nseven\neight\nnine\nten\neleven\n" "" "$BIGTEST" 42testing "noseek -c+ out of bonds" "tail -c +999" "" "" "$BIGTEST" 43 44makebigfile() 45{ 46 47 for j in $(seq 1 100) 48 do 49 printf "%s " $j 50 for i in $(seq 1 100) 51 do 52 printf %s 123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 53 done 54 echo 55 done 56} 57makebigfile > bigfile 58 59testing "-c 12345 -n 3 bigfile" "tail -c 12345 -n 3 bigfile | md5sum" \ 60 "347bbdcbad8a313f4dc7bd558c5bfcb8 -\n" "" "" 61testing "-n 3 -c 12345 bigfile" "tail -n 3 -c 12345 bigfile | md5sum" \ 62 "1698825a750288284ec3ba7d8a59f302 -\n" "" "" 63rm bigfile 64 65echo 111 > one 66testing "-f one" \ 67 'tail -f one & sleep .25 ; echo two >> one; sleep .25; echo three >> one; sleep .25; kill $! >/dev/null' \ 68 "111\ntwo\nthree\n" "" "" 69rm one 70 71echo uno > one 72echo dos > two 73echo tres > three 74testing "-f one two three" \ 75 'tail -f one two three & sleep .25 ; echo more >> three ; echo also >> one; sleep .25; kill $! >/dev/null' \ 76 "==> one <==\nuno\n\n==> two <==\ndos\n\n==> three <==\ntres\nmore\n\n==> one <==\nalso\n" "" "" 77rm one two three 78