toybox/tests/test.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3[ -f testing.sh ] && . testing.sh
   4
   5#testing "name" "command" "result" "infile" "stdin"
   6
   7testcmd '0 args' '; echo $?'  '1\n' '' ''
   8testcmd '1 arg' '== ; echo $?' '0\n' '' ''
   9testcmd '2 args' '-e == ; echo $?' '1\n' '' ''
  10testcmd '3 args' '-e == -e ; echo $?' '0\n' '' ''
  11testcmd '' '\( == \) ; echo $?' '1\n' '' ''
  12testcmd '' '\( == \( ; echo $?' '0\n' '' ''
  13
  14# TODO: Should also have device and socket files
  15
  16mkdir d
  17touch f
  18ln -s /dev/null L
  19echo nonempty > s
  20mkfifo p
  21
  22type_test()
  23{
  24  for i in d f L s p n
  25  do
  26    "$C" $* $i && echo -n $i
  27  done
  28}
  29
  30testing "-b" "type_test -b" "" "" ""
  31testing "-c" "type_test -c" "L" "" ""
  32testing "-d" "type_test -d" "d" "" ""
  33testing "-f" "type_test -f" "fs" "" ""
  34testing "-h" "type_test -h" "L" "" ""
  35testing "-L" "type_test -L" "L" "" ""
  36testing "-s" "type_test -s" "ds" "" ""
  37testing "-S" "type_test -S" "" "" ""
  38testing "-p" "type_test -p" "p" "" ""
  39testing "-e" "type_test -e" "dfLsp" "" ""
  40testing "! -e" 'type_test ! -e' "n" "" ""
  41
  42rm f L s p
  43rmdir d
  44
  45# TODO: Test rwx gu t
  46
  47testcmd "" "'' || echo yes" "yes\n" "" ""
  48testcmd "" "a && echo yes" "yes\n" "" ""
  49testcmd "-n" "-n '' || echo yes" "yes\n" "" ""
  50testcmd "-n2" "-n a && echo yes" "yes\n" "" ""
  51testcmd "-z" "-z '' && echo yes" "yes\n" "" ""
  52testcmd "-z2" "-z a || echo yes" "yes\n" "" ""
  53testcmd "" "a = b || echo yes" "yes\n" "" ""
  54testcmd "" "'' = '' && echo yes" "yes\n" "" ""
  55testcmd "a != b" "a != b && echo yes" "yes\n" "" ""
  56testcmd "a != b" "a != a || echo yes" "yes\n" "" ""
  57
  58arith_test()
  59{
  60  $C -1 $1 1 && echo -n l
  61  $C 0 $1 0 && echo -n e
  62  $C -3 $1 -5 && echo -n g
  63}
  64
  65testing "-eq" "arith_test -eq" "e" "" ""
  66testing "-ne" "arith_test -ne" "lg" "" ""
  67testing "-gt" "arith_test -gt" "g" "" ""
  68testing "-ge" "arith_test -ge" "eg" "" ""
  69testing "-lt" "arith_test -lt" "l" "" ""
  70testing "-le" "arith_test -le" "le" "" ""
  71
  72# test ! = -o a
  73# test ! \( = -o a \)
  74# test \( ! = \) -o a
  75# test \( \)
  76
  77#testing "" "[ -a -eq -a ] && echo yes" "yes\n" "" ""
  78
  79# -e == -a
  80# -e == -a -o -d != -o
  81# \( "x" \) -a \) == \)
  82# \( ! ! ! -e \) \)
  83
  84#  // () -a (() -a () -o ()) -o ()
  85#  // x -a ( x -o x ) -a x
  86#  // x -o ( x -a x ) -a x -o x
  87
  88# trailing ! and (
  89