usage.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. # Verify that chmod works correctly with odd option combinations.
  3. # Copyright (C) 2004-2018 Free Software Foundation, Inc.
  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 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ chmod
  16. # Each line in this list is a set of arguments, followed by :,
  17. # followed by the set of files it will attempt to chmod,
  18. # or empty if the usage is erroneous.
  19. # Many of these test cases are due to Glenn Fowler.
  20. # These test cases assume GNU behavior for "options" like -w.
  21. cases='
  22. -- :
  23. -- -- :
  24. -- -- -- f : -- f
  25. -- -- -w f : -w f
  26. -- -- f : f
  27. -- -w :
  28. -- -w -- f : -- f
  29. -- -w -w f : -w f
  30. -- -w f : f
  31. -- f :
  32. -w :
  33. -w -- :
  34. -w -- -- f : -- f
  35. -w -- -w f : -w f
  36. -w -- f : f
  37. -w -w :
  38. -w -w -- f : f
  39. -w -w -w f : f
  40. -w -w f : f
  41. -w f : f
  42. f :
  43. f -- :
  44. f -w : f
  45. f f :
  46. u+gr f :
  47. ug,+x f :
  48. '
  49. all_files=$(echo "$cases" | sed 's/.*://'|sort -u)
  50. old_IFS=$IFS
  51. IFS='
  52. '
  53. for case in $cases; do
  54. IFS=$old_IFS
  55. args=$(expr "$case" : ' *\(.*[^ ]\) *:')
  56. files=$(expr "$case" : '.*: *\(.*\)')
  57. case $files in
  58. '')
  59. touch -- $all_files || framework_failure_
  60. returns_ 1 chmod $args 2>/dev/null || fail=1
  61. ;;
  62. ?*)
  63. touch -- $files || framework_failure_
  64. chmod $args || fail=1
  65. for file in $files; do
  66. # Test for misparsing args by creating all $files but $file.
  67. # chmod has a bug if it succeeds even though $file is absent.
  68. rm -f -- $all_files && touch -- $files && rm -- $file \
  69. || framework_failure_
  70. returns_ 1 chmod $args 2>/dev/null || fail=1
  71. done
  72. ;;
  73. esac
  74. done
  75. Exit $fail