• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7testing "head, stdin" "head -n 1 && echo yes" "one\nyes\n" "" "one\ntwo"
8testing "head, stdin via -" "head -n 1 - && echo yes" "one\nyes\n" "" "one\ntwo"
9testing "head, file" "head input -n 1 && echo yes" "one\nyes\n" "one\ntwo" ""
10testing "-number" "head -2 input && echo yes" "one\ntwo\nyes\n" \
11	"one\ntwo\nthree\nfour" ""
12testing "head, default lines" "head" "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 "-"
15testing "-v file" "head -v -n 1 input" "==> input <==\none\n" "one\ntwo\n" ""
16testing "-v stdin" "head -v -n 1 | sed 's/==> standard input <==/==> - <==/'" \
17	"==> - <==\none\n" "" "one\ntwo\n"
18
19testing "file and stdin" "head -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
25testing "head, multiple files" "head -n 2 input file1" "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" ""
26testing "-q, multiple files" "head -q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \
27	"one\ntwo\nthree\n" ""
28rm file1
29
30testing "-c 3" "head -c 3" "one" "" "one\ntwo"
31testing "-c bigger than input" "head -c 3" "a" "" "a"
32testing "-c 3 -n 1" "head -c 3 -n 1" "one\n" "" "one\ntwo"
33testing "-n 1 -c 3" "head -n 1 -c 3" "one" "" "one\ntwo"
34