OSDN Git Service

Merge branch 'master' of https://android.googlesource.com/platform/external/toybox...
[android-x86/external-toybox.git] / tests / cat.test
1 #!/bin/bash
2
3 [ -f testing.sh ] && . testing.sh
4
5 #testing "name" "command" "result" "infile" "stdin"
6
7 echo "one" > file1
8 echo "two" > file2
9 testing "cat" "cat && echo yes" "oneyes\n" "" "one"
10 testing "-" "cat - && echo yes" "oneyes\n" "" "one"
11 testing "file1 file2" "cat file1 file2" "one\ntwo\n"  "" ""
12 testing "- file"      "cat - file1"     "zero\none\n" "" "zero\n"
13 testing "file -"      "cat file1 -"     "one\nzero\n" "" "zero\n"
14
15 testing "file1 notfound file2" \
16         "cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \
17         "one\ntwo\ncat: notfound: No such file or directory\n" "" ""
18
19 FILE="$(readlink -f /proc/self/exe)"
20 testing "file1" \
21         'cat "$FILE" > file1 && cmp "$FILE" file1 && echo yes' \
22         "yes\n" "" ""
23
24 testing "- file1" \
25         "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \
26         "-hello\n" "" "hello\n"
27
28 testing "> /dev/full" \
29         "cat - > /dev/full 2>stderr && echo ok; cat stderr; rm stderr" \
30         "cat: xwrite: No space left on device\n" "" "zero\n"
31
32 rm file1 file2