1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash 2*cf5a6c84SAndroid Build Coastguard Worker 3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh 4*cf5a6c84SAndroid Build Coastguard Worker 5*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin" 6*cf5a6c84SAndroid Build Coastguard Worker 7*cf5a6c84SAndroid Build Coastguard WorkerBIGTEST="one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" 8*cf5a6c84SAndroid Build Coastguard Workerecho -ne "$BIGTEST" > file1 9*cf5a6c84SAndroid Build Coastguard Workertesting "tail" "tail && echo yes" "oneyes\n" "" "one" 10*cf5a6c84SAndroid Build Coastguard Workertesting "file" "tail file1" \ 11*cf5a6c84SAndroid Build Coastguard Worker "two\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" "" 12*cf5a6c84SAndroid Build Coastguard Workertesting "-n in bounds" "tail -n 3 file1" "nine\nten\neleven\n" "" "" 13*cf5a6c84SAndroid Build Coastguard Workertesting "-n out of bounds" "tail -n 999 file1" "$BIGTEST" "" "" 14*cf5a6c84SAndroid Build Coastguard Workertesting "-n+ in bounds" "tail -n +3 file1" \ 15*cf5a6c84SAndroid Build Coastguard Worker "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" "" 16*cf5a6c84SAndroid Build Coastguard Workertesting "-n+ outof bounds" "tail -n +999 file1" "" "" "" 17*cf5a6c84SAndroid Build Coastguard Workertesting "-c in bounds" "tail -c 27 file1" \ 18*cf5a6c84SAndroid Build Coastguard Worker "even\neight\nnine\nten\neleven\n" "" "" 19*cf5a6c84SAndroid Build Coastguard Workertesting "-c out of bounds" "tail -c 999 file1" "$BIGTEST" "" "" 20*cf5a6c84SAndroid Build Coastguard Workertesting "-c+ in bounds" "tail -c +27 file1" \ 21*cf5a6c84SAndroid Build Coastguard Worker "x\nseven\neight\nnine\nten\neleven\n" "" "" 22*cf5a6c84SAndroid Build Coastguard Workertesting "-c+ out of bonds" "tail -c +999 file1" "" "" "" 23*cf5a6c84SAndroid Build Coastguard Workertesting "-N" "tail -1 file1" "eleven\n" "" "" 24*cf5a6c84SAndroid Build Coastguard Workerrm file1 25*cf5a6c84SAndroid Build Coastguard Worker 26*cf5a6c84SAndroid Build Coastguard Workertesting "stdin no trailing newline" "tail -n 1 - " "c" "" "a\nb\nc" 27*cf5a6c84SAndroid Build Coastguard Workertesting "file no trailing newline" "tail -n 1 input" "c" "a\nb\nc" "" 28*cf5a6c84SAndroid Build Coastguard Worker 29*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -n in bounds" "tail -n 3" "nine\nten\neleven\n" \ 30*cf5a6c84SAndroid Build Coastguard Worker "" "$BIGTEST" 31*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -n out of bounds" "tail -n 999" "$BIGTEST" "" "$BIGTEST" 32*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -n+ in bounds" "tail -n +3" \ 33*cf5a6c84SAndroid Build Coastguard Worker "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" \ 34*cf5a6c84SAndroid Build Coastguard Worker "$BIGTEST" 35*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -n+ outof bounds" "tail -n +999" "" "" "$BIGTEST" 36*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -c in bounds" "tail -c 27" \ 37*cf5a6c84SAndroid Build Coastguard Worker "even\neight\nnine\nten\neleven\n" "" "$BIGTEST" 38*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -c out of bounds" "tail -c 999" "$BIGTEST" "" "$BIGTEST" 39*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -c+ in bounds" "tail -c +27" \ 40*cf5a6c84SAndroid Build Coastguard Worker "x\nseven\neight\nnine\nten\neleven\n" "" "$BIGTEST" 41*cf5a6c84SAndroid Build Coastguard Workertesting "noseek -c+ out of bonds" "tail -c +999" "" "" "$BIGTEST" 42*cf5a6c84SAndroid Build Coastguard Worker 43*cf5a6c84SAndroid Build Coastguard Workermakebigfile() 44*cf5a6c84SAndroid Build Coastguard Worker{ 45*cf5a6c84SAndroid Build Coastguard Worker for j in $(seq 1 100) 46*cf5a6c84SAndroid Build Coastguard Worker do 47*cf5a6c84SAndroid Build Coastguard Worker echo -n "$j " 48*cf5a6c84SAndroid Build Coastguard Worker for i in $(seq 1 100) 49*cf5a6c84SAndroid Build Coastguard Worker do 50*cf5a6c84SAndroid Build Coastguard Worker echo -n 123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 51*cf5a6c84SAndroid Build Coastguard Worker done 52*cf5a6c84SAndroid Build Coastguard Worker echo 53*cf5a6c84SAndroid Build Coastguard Worker done 54*cf5a6c84SAndroid Build Coastguard Worker} 55*cf5a6c84SAndroid Build Coastguard Workermakebigfile > bigfile 56*cf5a6c84SAndroid Build Coastguard Worker 57*cf5a6c84SAndroid Build Coastguard Workertesting "-c 12345 -n 3 bigfile" "tail -c 12345 -n 3 bigfile | md5sum" \ 58*cf5a6c84SAndroid Build Coastguard Worker "347bbdcbad8a313f4dc7bd558c5bfcb8 -\n" "" "" 59*cf5a6c84SAndroid Build Coastguard Workertesting "-n 3 -c 12345 bigfile" "tail -n 3 -c 12345 bigfile | md5sum" \ 60*cf5a6c84SAndroid Build Coastguard Worker "1698825a750288284ec3ba7d8a59f302 -\n" "" "" 61*cf5a6c84SAndroid Build Coastguard Workerrm bigfile 62*cf5a6c84SAndroid Build Coastguard Worker 63*cf5a6c84SAndroid Build Coastguard Workerecho 111 > one 64*cf5a6c84SAndroid Build Coastguard Workertesting "-f one" \ 65*cf5a6c84SAndroid Build Coastguard Worker 'tail -f one & sleep .25 ; echo two >> one; sleep .25; echo three >> one; sleep .25; kill $! >/dev/null' \ 66*cf5a6c84SAndroid Build Coastguard Worker "111\ntwo\nthree\n" "" "" 67*cf5a6c84SAndroid Build Coastguard Workerrm one 68*cf5a6c84SAndroid Build Coastguard Worker 69*cf5a6c84SAndroid Build Coastguard Workerecho uno > one 70*cf5a6c84SAndroid Build Coastguard Workerecho dos > two 71*cf5a6c84SAndroid Build Coastguard Workerecho tres > three 72*cf5a6c84SAndroid Build Coastguard Workertesting "-f one two three" \ 73*cf5a6c84SAndroid Build Coastguard Worker 'tail -f one two three & sleep .25 ; echo more >> three ; echo also >> one; sleep .25; kill $! >/dev/null' \ 74*cf5a6c84SAndroid Build Coastguard Worker "==> one <==\nuno\n\n==> two <==\ndos\n\n==> three <==\ntres\nmore\n\n==> one <==\nalso\n" "" "" 75*cf5a6c84SAndroid Build Coastguard Workerrm one two three 76*cf5a6c84SAndroid Build Coastguard Worker 77*cf5a6c84SAndroid Build Coastguard Workertesting "-F" "tail -s .1 -F walrus 2>/dev/null & sleep .2; echo hello > walrus; 78*cf5a6c84SAndroid Build Coastguard Workersleep .2; truncate -s 0 walrus; sleep .2; echo potato >> walrus; sleep .2; 79*cf5a6c84SAndroid Build Coastguard Workerecho hello >> walrus; sleep .2; rm walrus; sleep .2; echo done > walrus; 80*cf5a6c84SAndroid Build Coastguard Worker sleep .5; kill %1" "hello\npotato\nhello\ndone\n" "" "" 81*cf5a6c84SAndroid Build Coastguard Workerrm -f walrus 82