PageRenderTime 2832ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/test-argp-2.sh

https://gitlab.com/changlimin/gnulib
Shell | 113 lines | 58 code | 25 blank | 30 comment | 6 complexity | adcc63aa3ba222565bc3a7039586c3cb MD5 | raw file
  1. #! /bin/sh
  2. # Test suite for argp.
  3. # Copyright (C) 2006-2022 Free Software Foundation, Inc.
  4. # This file is part of the GNUlib Library.
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>. */
  18. . "${srcdir=.}/init.sh"; path_prepend_ .
  19. ERR=0
  20. unset ARGP_HELP_FMT
  21. func_compare() {
  22. # If argp was compiled without base_name, it will display full program name.
  23. # If run on mingw, it will display the program name with a .exe suffix.
  24. sed '1{
  25. s,: [^ ]*/test-argp,: test-argp,
  26. s,: test-argp\.exe,: test-argp,
  27. }' | LC_ALL=C tr -d '\r' > out
  28. compare expected out
  29. }
  30. ####
  31. # Test --usage output
  32. cat > expected <<EOT
  33. Usage: test-argp [-tvCSOlp?V] [-f FILE] [-r FILE] [-o[ARG]] [--test]
  34. [--file=FILE] [--input=FILE] [--read=FILE] [--verbose] [--cantiga]
  35. [--sonet] [--option] [--optional[=ARG]] [--many] [--one] [--two]
  36. [--limerick] [--poem] [--help] [--usage] [--version] ARGS...
  37. EOT
  38. ${CHECKER} test-argp${EXEEXT} --usage | func_compare || ERR=1
  39. ####
  40. # Test working usage-indent format
  41. cat > expected <<EOT
  42. Usage: test-argp [-tvCSOlp?V] [-f FILE] [-r FILE] [-o[ARG]] [--test]
  43. [--file=FILE] [--input=FILE] [--read=FILE] [--verbose] [--cantiga] [--sonet]
  44. [--option] [--optional[=ARG]] [--many] [--one] [--two] [--limerick] [--poem]
  45. [--help] [--usage] [--version] ARGS...
  46. EOT
  47. ARGP_HELP_FMT='usage-indent=0' ${CHECKER} test-argp${EXEEXT} --usage | func_compare || ERR=1
  48. ####
  49. # Test --help output
  50. cat >expected <<EOT
  51. Usage: test-argp [OPTION...] ARGS...
  52. documentation string
  53. Main options
  54. -t, --test
  55. Option Group 1
  56. -f, -r, --file=FILE, --input=FILE, --read=FILE
  57. Option with a mandatory argument
  58. -v, --verbose Simple option without arguments
  59. Option Group 1.1
  60. -C, --cantiga create a cantiga
  61. -S, --sonet create a sonet
  62. Option Group 2
  63. -O, --option An option
  64. -o, --optional[=ARG] Option with an optional argument. ARG is one of
  65. the following:
  66. many many units
  67. one one unit
  68. two two units
  69. Option Group 2.1
  70. -l, --limerick create a limerick
  71. -p, --poem create a poem
  72. -?, --help give this help list
  73. --usage give a short usage message
  74. -V, --version print program version
  75. Mandatory or optional arguments to long options are also mandatory or optional
  76. for any corresponding short options.
  77. Report bugs to <>.
  78. EOT
  79. # Compare --help output, but filter out any bug-reporting email address.
  80. ${CHECKER} test-argp${EXEEXT} --help \
  81. | sed 's/^\(Report bugs to \)<[^>]*>.$/\1<>./' | func_compare || ERR=1
  82. ####
  83. # Test ambiguous option handling
  84. ${CHECKER} test-argp${EXEEXT} --optio 2>/dev/null && ERR=1
  85. ####
  86. # Run built-in tests
  87. ${CHECKER} test-argp${EXEEXT} || ERR=1
  88. Exit $ERR