1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5#testing "name" "command" "result" "infile" "stdin" 6 7testcmd "stdin" "-n 1 && echo yes" "one\nyes\n" "" "one\ntwo" 8testcmd "stdin via -" "-n 1 - && echo yes" "one\nyes\n" "" "one\ntwo" 9testcmd "file" "input -n 1 && echo yes" "one\nyes\n" "one\ntwo" "" 10testcmd "-number" "-2 input && echo yes" "one\ntwo\nyes\n" \ 11 "one\ntwo\nthree\nfour" "" 12testcmd "default lines" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12" 13 14# coreutils & busybox name stdin as "standard input", toybox uses "-" 15testcmd "-v file" "-v -n 1 input" "==> input <==\none\n" "one\ntwo\n" "" 16testcmd "-v stdin" "-v -n 1 | sed 's/standard input/-/'" \ 17 "==> - <==\none\n" "" "one\ntwo\n" 18 19testcmd "file and stdin" "-n 1 input - | sed 's/standard input/-/'" \ 20 "==> input <==\none\n\n==> - <==\nfoo\n" "one\ntwo\n" "foo\nbar\n" 21 22echo "foo 23bar 24baz" > file1 25testcmd "multiple files" "-n 2 input file1" \ 26 "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" "" 27testcmd "-q, multiple files" "-q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \ 28 "one\ntwo\nthree\n" "" 29rm file1 30 31testcmd "-c 3" "-c 3" "one" "" "one\ntwo" 32testcmd "-c bigger than input" "-c 3" "a" "" "a" 33testcmd "-c 3 -n 1" "-c 3 -n 1" "one\n" "" "one\ntwo" 34testcmd "-n 1 -c 3" "-n 1 -c 3" "one" "" "one\ntwo" 35testing "unget" 'while read i; do echo =$i; head -n 1; done < input' \ 36 '=one\ntwo\n=three\nfour\n=five\n' 'one\ntwo\nthree\nfour\nfive\n' '' 37