aboutsummaryrefslogtreecommitdiff
path: root/tests/head.test
blob: 4e4c01bd6ecf2b374f421e19ca8d216980013e79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

testing "head, stdin" "head -n 1 && echo yes" "one\nyes\n" "" "one\ntwo"
testing "head, stdin via -" "head -n 1 - && echo yes" "one\nyes\n" "" "one\ntwo"
testing "head, file" "head input -n 1 && echo yes" "one\nyes\n" "one\ntwo" ""
testing "-number" "head -2 input && echo yes" "one\ntwo\nyes\n" \
	"one\ntwo\nthree\nfour" ""
testing "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"

# coreutils & busybox name stdin as "standard input", toybox uses "-"
testing "-v file" "head -v -n 1 input" "==> input <==\none\n" "one\ntwo\n" ""
testing "-v stdin" "head -v -n 1 | sed 's/==> standard input <==/==> - <==/'" \
	"==> - <==\none\n" "" "one\ntwo\n"

testing "file and stdin" "head -n 1 input - | sed 's/==> standard input <==/==> - <==/'" \
	"==> input <==\none\n\n==> - <==\nfoo\n" "one\ntwo\n" "foo\nbar\n"

echo "foo
bar
baz" > file1
testing "head, multiple files" "head -n 2 input file1" "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" ""
testing "-q, multiple files" "head -q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \
	"one\ntwo\nthree\n" ""
rm file1

testing "-c 3" "head -c 3" "one" "" "one\ntwo"
testing "-c bigger than input" "head -c 3" "a" "" "a"
testing "-c 3 -n 1" "head -c 3 -n 1" "one\n" "" "one\ntwo"
testing "-n 1 -c 3" "head -n 1 -c 3" "one" "" "one\ntwo"