self-check-seq.tap 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Sanity check for the automake testsuite.
  17. # Check the 'seq_' subroutine.
  18. . test-init.sh
  19. plan_ 14
  20. unset stderr_fileno_
  21. check_work ()
  22. {
  23. desc=$1 args=$2 exp=$3
  24. st=0; got=$(seq_ $args) || st=$?
  25. command_ok_ "$desc [exit status = 0]" test $st -eq 0
  26. command_ok_ "$desc [output]" test x"$exp" = x"$got"
  27. }
  28. check_work 'one-argument form' '5' "\
  29. 1
  30. 2
  31. 3
  32. 4
  33. 5"
  34. check_work 'two-arguments form' '7 11' "\
  35. 7
  36. 8
  37. 9
  38. 10
  39. 11"
  40. check_work 'three-arguments form (1)' '120 5 135' "\
  41. 120
  42. 125
  43. 130
  44. 135"
  45. check_work 'three-arguments form (1)' '13 4 23' "\
  46. 13
  47. 17
  48. 21"
  49. check_err ()
  50. {
  51. desc=$1 args=$2 err=$3
  52. (seq_ $args) >output || st=$?
  53. # Protect content emitted on stdout/stderr, to avoid sending to the
  54. # TAP driver possible "Bail out!" directives generated by 'seq_'.
  55. # Use 'grep -c' below for the same reason.
  56. sed 's/^/: /' output
  57. command_ok_ "$desc [exit status = 99]" test $st -eq 99
  58. command_ok_ "$desc [error message]" grep -c "seq_: $err" output
  59. }
  60. check_err 'no argument is an error' '' 'missing argument'
  61. check_err 'four arguments is an error' '1 1 2 1' 'too many arguments'
  62. check_err 'six arguments is an error' '1 1 1 1 1 1' 'too many arguments'
  63. :