toybox/tests/cat.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3[ -f testing.sh ] && . testing.sh
   4
   5#testing "name" "command" "result" "infile" "stdin"
   6
   7echo "one" > file1
   8echo "two" > file2
   9testing "cat" "cat && echo yes" "oneyes\n" "" "one"
  10testing "-" "cat - && echo yes" "oneyes\n" "" "one"
  11testing "file1 file2" "cat file1 file2" "one\ntwo\n"  "" ""
  12testing "- file"      "cat - file1"     "zero\none\n" "" "zero\n"
  13testing "file -"      "cat file1 -"     "one\nzero\n" "" "zero\n"
  14
  15testing "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
  19testing "binary" \
  20        'cat "$C" > file1 && cmp "$C" file1 && echo yes' "yes\n" "" ""
  21
  22testing "- file1" \
  23        "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \
  24        "-hello\n" "" "hello\n"
  25
  26skipnot [ -e /dev/full ]
  27testing "> /dev/full" \
  28        "cat - > /dev/full 2>/dev/null || echo failed" \
  29        "failed\n" "" "zero\n"
  30
  31rm file1 file2
  32