install-sh-unittests.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #! /bin/sh
  2. # Copyright (C) 2002-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. # Various install-sh checks.
  17. am_create_testdir=empty
  18. . test-init.sh
  19. install_sh_fail ()
  20. {
  21. err_rx=$1; shift
  22. ./install-sh ${1+"$@"} 2>stderr && { cat stderr >&2; exit 1; }
  23. cat stderr >&2
  24. $EGREP "install-sh:.* $err_rx" stderr || exit 1
  25. }
  26. get_shell_script install-sh
  27. # Basic errors.
  28. install_sh_fail 'no input file specified'
  29. install_sh_fail 'no input file specified' dest
  30. install_sh_fail 'no input file specified' -m 644 dest
  31. install_sh_fail 'no input file specified' -c -t dest
  32. # Incorrect usages.
  33. : > bar
  34. : > baz
  35. : > qux
  36. install_sh_fail 'target directory not allowed when installing a directory' \
  37. -d -t foo
  38. install_sh_fail 'target directory not allowed when installing a directory' \
  39. -d -t foo bar
  40. install_sh_fail 'foo: [iI]s not a directory' -t foo bar
  41. install_sh_fail 'foo: [iI]s not a directory' bar baz foo
  42. mkdir foo
  43. install_sh_fail 'target directory not allowed when installing a directory' \
  44. -d -t foo
  45. install_sh_fail 'target directory not allowed when installing a directory' \
  46. -d -t foo bar
  47. rmdir foo
  48. rm -f bar baz qux
  49. # Directories.
  50. for opts in '-d' '-d -T' '-T -d' '-d -T -d' '-T -d -T -d -T'; do
  51. # It should be OK to create no directory. We sometimes need
  52. # this when directory are conditionally defined.
  53. ./install-sh $opts
  54. # One directory.
  55. ./install-sh $opts d0
  56. test -d d0
  57. # Multiple directories (for make installdirs).
  58. ./install-sh $opts d1 d2 d3 d4
  59. test -d d1
  60. test -d d2
  61. test -d d3
  62. test -d d4
  63. rmdir d[0-9]
  64. # Subdirectories.
  65. ./install-sh $opts p1/p2/p3 p4//p5//p6//
  66. test -d p1/p2/p3
  67. test -d p4/p5/p6
  68. rmdir p[0-9]/p[0-9]/p[0-9]
  69. rmdir p[0-9]/p[0-9]
  70. rmdir p[0-9]
  71. done
  72. # Files.
  73. mkdir d0 d1 d2 d3 d4
  74. : > x
  75. ./install-sh -c -m 644 x y
  76. test -f x
  77. test -f y
  78. ./install-sh -m 644 y z
  79. test -f y
  80. test -f z
  81. # Multiple files.
  82. ./install-sh -m 644 -c x z d1
  83. test -f x
  84. test -f z
  85. test -f d1/x
  86. test -f d1/z
  87. ./install-sh -m 644 x z d2//
  88. test -f x
  89. test -f z
  90. test -f d2/x
  91. test -f d2/z
  92. ./install-sh -t d3 -m 644 x z
  93. test -f x
  94. test -f z
  95. test -f d3/x
  96. test -f d3/z
  97. ./install-sh -t d4// -m 644 x z
  98. test -f x
  99. test -f z
  100. test -f d4/x
  101. test -f d4/z
  102. ./install-sh -T x d3/y
  103. test -f x
  104. test -f d3/y
  105. install_sh_fail 'd3: [iI]s a directory' -T x d3
  106. install_sh_fail 'd4(//)?: [iI]s a directory' -T x d4//
  107. # Ensure that install-sh works with names that include spaces.
  108. touch 'a b'
  109. mkdir 'x y'
  110. ./install-sh 'a b' 'x y'
  111. test -f x\ \ y/a\ \ b
  112. test -f 'a b'
  113. # Ensure we do not run into 'test' operator precedence bugs with Tru64 sh.
  114. for c in = '(' ')' '!'; do
  115. install_sh_fail 'no input file specified' $c
  116. test -f stderr # sanity check
  117. grep 'test: ' stderr && exit 1
  118. # Skip tests if the file system is not capable.
  119. mkdir ./$c || continue
  120. rmdir ./$c
  121. ./install-sh -d $c/$c/$c
  122. rm -rf ./$c
  123. ./install-sh -d $c d5/$c/$c
  124. test -d ./$c
  125. test -d d5/$c/$c
  126. ./install-sh x $c
  127. test -f ./$c/x
  128. rm -f ./$c/x
  129. ./install-sh -t $c x
  130. test -f ./$c/x
  131. rm -rf ./$c
  132. ( : > ./$c ) || continue
  133. ./install-sh $c x d5/$c/$c
  134. test -f d5/$c/$c/x
  135. test -f d5/$c/$c/$c
  136. rm -f d5/$c/$c/?
  137. ./install-sh -t d5/$c/$c $c x
  138. test -f d5/$c/$c/x
  139. test -f d5/$c/$c/$c
  140. done
  141. :