OSDN Git Service

Merge tag 'android-8.1.0_r1' into oreo-x86
[android-x86/external-toybox.git] / tests / head.test
1 #!/bin/bash
2
3 [ -f testing.sh ] && . testing.sh
4
5 #testing "name" "command" "result" "infile" "stdin"
6
7 testing "head, stdin" "head -n 1 && echo yes" "one\nyes\n" "" "one\ntwo"
8 testing "head, stdin via -" "head -n 1 - && echo yes" "one\nyes\n" "" "one\ntwo"
9 testing "head, file" "head input -n 1 && echo yes" "one\nyes\n" "one\ntwo" ""
10 testing "-number" "head -2 input && echo yes" "one\ntwo\nyes\n" \
11         "one\ntwo\nthree\nfour" ""
12 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"
13
14 # coreutils & busybox name stdin as "standard input", toybox uses "-"
15 testing "-v file" "head -v -n 1 input" "==> input <==\none\n" "one\ntwo\n" ""
16 testing "-v stdin" "head -v -n 1 | sed 's/==> standard input <==/==> - <==/'" \
17         "==> - <==\none\n" "" "one\ntwo\n"
18
19 testing "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
22 echo "foo
23 bar
24 baz" > file1
25 testing "head, multiple files" "head -n 2 input file1" "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" ""
26 testing "-q, multiple files" "head -q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \
27         "one\ntwo\nthree\n" ""
28 rm file1
29
30 testing "-c 3" "head -c 3" "one" "" "one\ntwo"
31 testing "-c bigger than input" "head -c 3" "a" "" "a"
32 testing "-c 3 -n 1" "head -c 3 -n 1" "one\n" "" "one\ntwo"
33 testing "-n 1 -c 3" "head -n 1 -c 3" "one" "" "one\ntwo"