testit.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/bin/sh
  2. run() {
  3. prog=$1; shift
  4. name=$1; shift
  5. answer=$1; shift
  6. echo Running test $name.
  7. result=`HOME=$builddir $builddir/$prog $*`
  8. if [ "$answer" != "$result" ]; then
  9. echo "Test \"$prog $*\" failed with: \"$result\" != \"$answer\" "
  10. exit 2
  11. fi
  12. }
  13. run_diff() {
  14. prog=$1; shift
  15. name=$1; shift
  16. in_file=$1; shift
  17. answer_file=$1; shift
  18. out=$builddir/tmp.out
  19. diff_file=$builddir/tmp.diff
  20. echo Running test $name.
  21. $builddir/$prog $in_file > $out
  22. ret=$?
  23. diff $out $answer_file > $diff_file
  24. diff_ret=$?
  25. if [ "$diff_ret" != "0" ]; then
  26. echo "Test \"$name\" failed output is in $out, diff is:"
  27. cat $diff_file
  28. exit 2
  29. fi
  30. rm $out $diff_file
  31. }
  32. builddir=`pwd`
  33. srcdir=$builddir
  34. cd ${srcdir}
  35. test1=${builddir}/test1
  36. echo "Running tests in `pwd`"
  37. #make -q testcases
  38. run test1 "test1 - 1" "arg1: 1 arg2: (none)" --arg1
  39. run test1 "test1 - 2" "arg1: 0 arg2: foo" --arg2 foo
  40. run test1 "test1 - 3" "arg1: 1 arg2: something" --arg1 --arg2 something
  41. run test1 "test1 - 4" "arg1: 0 arg2: another" --simple another
  42. run test1 "test1 - 5" "arg1: 1 arg2: alias" --two
  43. run test1 "test1 - 6" "arg1: 1 arg2: (none) rest: --arg2" --arg1 -- --arg2
  44. run test1 "test1 - 7" "arg1: 0 arg2: abcd rest: --arg1" --simple abcd -- --arg1
  45. run test1 "test1 - 8" "arg1: 1 arg2: (none) rest: --arg2" --arg1 --takerest --arg2
  46. run test1 "test1 - 9" "arg1: 0 arg2: foo" -2 foo
  47. run test1 "test1 - 10" "arg1: 0 arg2: (none) arg3: 50" -3 50
  48. run test1 "test1 - 11" "arg1: 0 arg2: bar" -T bar
  49. run test1 "test1 - 12" "arg1: 1 arg2: (none)" -O
  50. run test1 "test1 - 13" "arg1: 1 arg2: foo" -OT foo
  51. run test1 "test1 - 14" "arg1: 0 arg2: (none) inc: 1" --inc
  52. run test1 "test1 - 15" "arg1: 0 arg2: foo inc: 1" -I --arg2 foo
  53. POSIX_ME_HARDER=1 ; export POSIX_ME_HARDER
  54. run test1 "test1 - 16" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
  55. unset POSIX_ME_HARDER
  56. POSIXLY_CORRECT=1 ; export POSIXLY_CORRECT
  57. run test1 "test1 - 17" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
  58. unset POSIXLY_CORRECT
  59. run test1 "test1 - 18" "callback: c sampledata bar arg1: 1 arg2: (none)" --arg1 --cb bar
  60. run test1 "test1 - 19" "" --echo-args
  61. run test1 "test1 - 20" "--arg1" --echo-args --arg1
  62. run test1 "test1 - 21" "--arg2 something" -T something -e
  63. run test1 "test1 - 22" "--arg2 something more args" -T something -a more args
  64. run test1 "test1 - 23" "--echo-args -a" --echo-args -e -a
  65. run test1 "test1 - 24" "arg1: 0 arg2: (none) short: 1" -onedash
  66. run test1 "test1 - 25" "arg1: 0 arg2: (none) short: 1" --onedash
  67. run test1 "test1 - 26" "callback: c arg for cb2 foo arg1: 0 arg2: (none)" --cb2 foo
  68. run test1 "test1 - 27" "arg1: 0 arg2: (none) rest: -" -
  69. run test1 "test1 - 28" "arg1: 0 arg2: foo rest: -" - -2 foo
  70. run test1 "test1 - 29" "arg1: 0 arg2: bbbb" --arg2=aaaa -2 bbbb
  71. run test1 "test1 - 30" "arg1: 0 arg2: 'foo bingo' rest: boggle" --grab bingo boggle
  72. run test1 "test1 - 31" "arg1: 0 arg2: 'foo bar' rest: boggle" --grabbar boggle
  73. run test1 "test1 - 32" "arg1: 0 arg2: (none) aInt: 123456789" -i 123456789
  74. run test1 "test1 - 33" "arg1: 0 arg2: (none) aInt: 123456789" --int 123456789
  75. run test1 "test1 - 34" "arg1: 0 arg2: (none) aShort: 12345" -s 12345
  76. run test1 "test1 - 35" "arg1: 0 arg2: (none) aShort: 12345" --short 12345
  77. run test1 "test1 - 36" "arg1: 0 arg2: (none) aLong: 1123456789" -l 1123456789
  78. run test1 "test1 - 37" "arg1: 0 arg2: (none) aLong: 1123456789" --long 1123456789
  79. run test1 "test1 - 38" "arg1: 0 arg2: (none) aLongLong: 1111123456789" -L 1111123456789
  80. run test1 "test1 - 39" "arg1: 0 arg2: (none) aLongLong: 1111123456789" --longlong 1111123456789
  81. run test1 "test1 - 40" "arg1: 0 arg2: (none) aFloat: 10.1" -f 10.1
  82. run test1 "test1 - 41" "arg1: 0 arg2: (none) aFloat: 10.1" --float 10.1
  83. run test1 "test1 - 42" "arg1: 0 arg2: (none) aDouble: 10.1" -d 10.1
  84. run test1 "test1 - 43" "arg1: 0 arg2: (none) aDouble: 10.1" --double 10.1
  85. run test1 "test1 - 44" "arg1: 0 arg2: (none) oStr: (none)" --optional
  86. run test1 "test1 - 45" "arg1: 0 arg2: (none) oStr: yadda" --optional=yadda
  87. run test1 "test1 - 46" "arg1: 0 arg2: (none) oStr: yadda" --optional yadda
  88. run test1 "test1 - 47" "arg1: 0 arg2: (none) oStr: ping rest: pong" --optional=ping pong
  89. run test1 "test1 - 48" "arg1: 0 arg2: (none) oStr: ping rest: pong" --optional ping pong
  90. run test1 "test1 - 49" "arg1: 0 arg2: (none) aArgv: A B rest: C" --argv A --argv B C
  91. run test1 "test1 - 50" "arg1: 0 arg2: foo=bar" -2foo=bar
  92. run test1 "test1 - 51" "arg1: 0 arg2: foo=bar" -2=foo=bar
  93. run test1 "test1 - 52" "arg1: 0 arg2: (none) aFlag: 0xfeed" --bitxor
  94. run test1 "test1 - 53" "arg1: 0 arg2: (none) aFlag: 0xffff" --bitset
  95. run test1 "test1 - 54" "arg1: 0 arg2: (none) aFlag: 0x28c" --bitclr
  96. run test1 "test1 - 55" "arg1: 0 arg2: (none) aFlag: 0x8888" --nobitset
  97. run test1 "test1 - 56" "arg1: 0 arg2: (none) aFlag: 0xface" --nobitclr
  98. run test1 "test1 - 57" "arg1: 0 arg2: (none) aBits: foo,baz" --bits foo,bar,baz,!bar
  99. run test1 "test1 - 58" "\
  100. Usage: lt-test1 [-I?] [-c|--cb2=STRING] [--arg1] [-2|--arg2=ARG]
  101. [-3|--arg3=ANARG] [-onedash] [--optional=STRING] [--val]
  102. [-i|--int=INT] [-s|--short=SHORT] [-l|--long=LONG]
  103. [-L|--longlong=LONGLONG] [-f|--float=FLOAT] [-d|--double=DOUBLE]
  104. [--randint=INT] [--randshort=SHORT] [--randlong=LONG]
  105. [--randlonglong=LONGLONG] [--argv=STRING] [--bitset] [--bitclr]
  106. [--bitxor] [--nstr=STRING] [--lstr=STRING] [-I|--inc]
  107. [-c|--cb=STRING] [--longopt] [-?|--help] [--usage] [--simple=ARG]" --usage
  108. run test1 "test1 - 59" "\
  109. Usage: lt-test1 [OPTION...]
  110. --arg1 First argument with a really long
  111. description. After all, we have to test
  112. argument help wrapping somehow, right?
  113. -2, --arg2=ARG Another argument (default: \"(none)\")
  114. -3, --arg3=ANARG A third argument
  115. -onedash POPT_ARGFLAG_ONEDASH: Option takes a single -
  116. --optional[=STRING] POPT_ARGFLAG_OPTIONAL: Takes an optional
  117. string argument
  118. --val POPT_ARG_VAL: 125992 141421
  119. -i, --int=INT POPT_ARG_INT: 271828 (default: 271828)
  120. -s, --short=SHORT POPT_ARG_SHORT: 4523 (default: 4523)
  121. -l, --long=LONG POPT_ARG_LONG: 738905609 (default: 738905609)
  122. -L, --longlong=LONGLONG POPT_ARG_LONGLONG: 738905609 (default:
  123. 738905609)
  124. -f, --float=FLOAT POPT_ARG_FLOAT: 3.14159 (default: 3.14159)
  125. -d, --double=DOUBLE POPT_ARG_DOUBLE: 9.8696 (default: 9.8696)
  126. --randint=INT POPT_ARGFLAG_RANDOM: experimental
  127. --randshort=SHORT POPT_ARGFLAG_RANDOM: experimental
  128. --randlong=LONG POPT_ARGFLAG_RANDOM: experimental
  129. --randlonglong=LONGLONG POPT_ARGFLAG_RANDOM: experimental
  130. --argv STRING POPT_ARG_ARGV: append string to argv array
  131. (can be used multiple times)
  132. --[no]bitset POPT_BIT_SET: |= 0x7777
  133. --[no]bitclr POPT_BIT_CLR: &= ~0xf842
  134. --bitxor POPT_ARGFLAG_XOR: ^= (0x8ace^0xfeed)
  135. --nstr=STRING POPT_ARG_STRING: (null) (default: null)
  136. --lstr=STRING POPT_ARG_STRING: \"123456789...\" (default:
  137. \"This tests default strings and exceeds the
  138. ... limit.
  139. 123456789+123456789+123456789+123456789+123456789+ 123456789+123456789+123456789+123456789+123456789+ 1234567...\")
  140. arg for cb2
  141. -c, --cb2=STRING Test argument callbacks
  142. -I, --inc An included argument
  143. Callback arguments
  144. -c, --cb=STRING Test argument callbacks
  145. --longopt Unused option for help testing
  146. Options implemented via popt alias/exec:
  147. --simple=ARG simple description
  148. Help options:
  149. -?, --help Show this help message
  150. --usage Display brief usage message" --help
  151. #run_diff test3 "test3 - 51" test3-data/01.input test3-data/01.answer
  152. #run_diff test3 "test3 - 52" test3-data/02.input test3-data/02.answer
  153. #run_diff test3 "test3 - 53" test3-data/03.input test3-data/03.answer
  154. echo ""
  155. echo "Passed."