• 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 "test -b" "type_test -b" "" "" ""
29testing "test -c" "type_test -c" "L" "" ""
30testing "test -d" "type_test -d" "d" "" ""
31testing "test -f" "type_test -f" "fs" "" ""
32testing "test -h" "type_test -h" "L" "" ""
33testing "test -L" "type_test -L" "L" "" ""
34testing "test -s" "type_test -s" "ds" "" ""
35testing "test -S" "type_test -S" "" "" ""
36testing "test -p" "type_test -p" "p" "" ""
37testing "test -e" "type_test -e" "dfLsp" "" ""
38testing "test ! -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 "test -n" "test -n "" || test -n a && echo yes" "yes\n" "" ""
47testing "test -z" "test -n a || test -n "" && echo yes" "yes\n" "" ""
48testing "test a = b" "test a = b || test "" = "" && echo yes" "yes\n" "" ""
49testing "test 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 "test -eq" "arith_test -eq" "e\n" "" ""
59testing "test -ne" "arith_test -ne" "l\ng\n" "" ""
60testing "test -gt" "arith_test -gt" "g\n" "" ""
61testing "test -ge" "arith_test -ge" "e\ng\n" "" ""
62testing "test -lt" "arith_test -lt" "l\n" "" ""
63testing "test -le" "arith_test -le" "l\ne\n" "" ""
64
65# test ! = -o a
66# test ! \( = -o a \)
67# test \( ! = \) -o a
68