• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7# TODO: Should also have device and socket files
8
9mkdir d
10touch f
11ln -s /dev/null L
12echo nonempty > s
13mkfifo p
14
15type_test()
16{
17  result=""
18  for i in d f L s p n
19  do
20    if test $* $i
21    then
22      result=$result$i
23    fi
24  done
25  printf "%s" $result
26}
27
28testing "-b" "type_test -b" "" "" ""
29testing "-c" "type_test -c" "L" "" ""
30testing "-d" "type_test -d" "d" "" ""
31testing "-f" "type_test -f" "fs" "" ""
32testing "-h" "type_test -h" "L" "" ""
33testing "-L" "type_test -L" "L" "" ""
34testing "-s" "type_test -s" "ds" "" ""
35testing "-S" "type_test -S" "" "" ""
36testing "-p" "type_test -p" "p" "" ""
37testing "-e" "type_test -e" "dfLsp" "" ""
38testing "! -e" "type_test ! -e" "n" "" ""
39
40rm f L s p
41rmdir d
42
43# TODO: Test rwx gu t
44
45testing "test" "test "" || test a && echo yes" "yes\n" "" ""
46testing "-n" "test -n "" || test -n a && echo yes" "yes\n" "" ""
47testing "-z" "test -n a || test -n "" && echo yes" "yes\n" "" ""
48testing "a = b" "test a = b || test "" = "" && echo yes" "yes\n" "" ""
49testing "a != b" "test "" != "" || test a = b && echo yes" "yes\n" "" ""
50
51arith_test()
52{
53  test -1 $1 1 && echo l
54  test 0 $1 0 && echo e
55  test -3 $1 -5 && echo g
56}
57
58testing "-eq" "arith_test -eq" "e\n" "" ""
59testing "-ne" "arith_test -ne" "l\ng\n" "" ""
60testing "-gt" "arith_test -gt" "g\n" "" ""
61testing "-ge" "arith_test -ge" "e\ng\n" "" ""
62testing "-lt" "arith_test -lt" "l\n" "" ""
63testing "-le" "arith_test -le" "l\ne\n" "" ""
64
65# test ! = -o a
66# test ! \( = -o a \)
67# test \( ! = \) -o a
68