aboutsummaryrefslogtreecommitdiff
path: root/tests/head.test
blob: 6ed027c4a36f8e63ef6e509f43b61c9593adfd18 (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
#!/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