logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

test.sh (4143B)


  1. #!/bin/sh
  2. # SPDX-License-Identifier: BSD-2-Clause
  3. #-
  4. # Copyright (c) June 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
  5. # All rights reserved.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. # SUCH DAMAGE.
  27. #
  28. # TEST.sh - check if test(1) or builtin test works
  29. #
  30. test="$(dirname "$0")/../cmd/test"
  31. t ()
  32. {
  33. # $1 -> exit code
  34. # $2 -> $test expression
  35. count=$((count+1))
  36. out="$(eval "$test" "$2" 2>&1)"
  37. ret="$?"
  38. if [ -n "$out" ]; then
  39. printf "not ok %s - $out\n" "$count $2"
  40. elif [ "$ret" != "$1" ]; then
  41. printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
  42. else
  43. printf "ok %s\n" "$count $2"
  44. fi
  45. }
  46. count=0
  47. echo "1..130"
  48. t 0 'b = b'
  49. t 0 'b == b'
  50. t 1 'b != b'
  51. t 0 '\( b = b \)'
  52. t 0 '\( b == b \)'
  53. t 1 '! \( b = b \)'
  54. t 1 '! \( b == b \)'
  55. t 1 '! -f /etc/passwd'
  56. t 0 '-h = -h'
  57. t 0 '-o = -o'
  58. t 1 '-f = h'
  59. t 1 '-h = f'
  60. t 1 '-o = f'
  61. t 1 'f = -o'
  62. t 0 '\( -h = -h \)'
  63. t 1 '\( a = -h \)'
  64. t 1 '\( -f = h \)'
  65. t 0 '-h = -h -o a'
  66. t 0 '\( -h = -h \) -o 1'
  67. t 0 '-h = -h -o -h = -h'
  68. t 0 '\( -h = -h \) -o \( -h = -h \)'
  69. t 0 'roedelheim = roedelheim'
  70. t 1 'potsdam = berlin-dahlem'
  71. t 0 '-d /'
  72. t 0 '-d / -a a != b'
  73. t 1 '-z "-z"'
  74. t 0 '-n -n'
  75. t 0 '0'
  76. t 0 '\( 0 \)'
  77. t 0 '-E'
  78. t 0 '-X -a -X'
  79. t 0 '-XXX'
  80. t 0 '\( -E \)'
  81. t 0 'true -o X'
  82. t 0 'true -o -X'
  83. t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true'
  84. t 1 '-h /'
  85. t 0 '-r /'
  86. t "$([ "$(id -u)" -eq 0 ]; echo $?)" '-w /'
  87. t 0 '-x /bin/sh'
  88. t 0 '-c /dev/null'
  89. t 0 '-f /etc/passwd'
  90. t 0 '-s /etc/passwd'
  91. t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
  92. t 0 '100 -eq 100'
  93. t 0 '100 -lt 200'
  94. t 1 '1000 -lt 200'
  95. t 0 '1000 -gt 200'
  96. t 0 '1000 -ge 200'
  97. t 0 '1000 -ge 1000'
  98. t 1 '2 -ne 2'
  99. t 0 '0 -eq 0'
  100. t 1 '-5 -eq 5'
  101. t 0 '\( 0 -eq 0 \)'
  102. t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa'
  103. t 1 '"" -o ""'
  104. t 1 '"" -a ""'
  105. t 1 '"a" -a ""'
  106. t 0 '"a" -a ! ""'
  107. t 1 '""'
  108. t 0 '! ""'
  109. t 0 '!'
  110. t 0 '\('
  111. t 0 '\)'
  112. t 1 '\( = \)'
  113. t 0 '\( != \)'
  114. t 0 '\( ! \)'
  115. t 0 '\( \( \)'
  116. t 0 '\( \) \)'
  117. t 0 '! = !'
  118. t 1 '! != !'
  119. t 1 '-n = \)'
  120. t 0 '! != \)'
  121. t 1 '! = a'
  122. t 0 '! != -n'
  123. t 0 '! -c /etc/passwd'
  124. t 1 '! = = ='
  125. t 0 '! = = \)'
  126. t 0 '! "" -o ""'
  127. t 1 '! "x" -o ""'
  128. t 1 '! "" -o "x"'
  129. t 1 '! "x" -o "x"'
  130. t 0 '\( -f /etc/passwd \)'
  131. t 0 '\( ! "" \)'
  132. t 1 '\( ! -e \)'
  133. t 0 '0 -eq 0 -a -d /'
  134. t 0 '-s = "" -o "" = ""'
  135. t 0 '"" = "" -o -s = ""'
  136. t 1 '-s = "" -o -s = ""'
  137. t 0 '-z x -o x = "#" -o x = x'
  138. t 1 '-z y -o y = "#" -o y = x'
  139. t 0 '0 -ne 0 -o ! -f /'
  140. t 0 '1 -ne 0 -o ! -f /etc/passwd'
  141. t 1 '0 -ne 0 -o ! -f /etc/passwd'
  142. t 0 '-n ='
  143. t 1 '-z ='
  144. t 1 '! ='
  145. t 0 '-n -eq'
  146. t 1 '-z -eq'
  147. t 1 '! -eq'
  148. t 0 '-n -a'
  149. t 1 '-z -a'
  150. t 1 '! -a'
  151. t 0 '-n -o'
  152. t 1 '-z -o'
  153. t 1 '! -o'
  154. t 1 '! -n ='
  155. t 0 '! -z ='
  156. t 0 '! ! ='
  157. t 1 '! -n -eq'
  158. t 0 '! -z -eq'
  159. t 0 '! ! -eq'
  160. t 1 '! -n -a'
  161. t 0 '! -z -a'
  162. t 0 '! ! -a'
  163. t 1 '! -n -o'
  164. t 0 '! -z -o'
  165. t 0 '! ! -o'
  166. t 0 '\( -n = \)'
  167. t 1 '\( -z = \)'
  168. t 1 '\( ! = \)'
  169. t 0 '\( -n -eq \)'
  170. t 1 '\( -z -eq \)'
  171. t 1 '\( ! -eq \)'
  172. t 0 '\( -n -a \)'
  173. t 1 '\( -z -a \)'
  174. t 1 '\( ! -a \)'
  175. t 0 '\( -n -o \)'
  176. t 1 '\( -z -o \)'
  177. t 1 '\( ! -o \)'