3
0

cp.tests 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/bin/sh
  2. # Copyright 2010 by Denys Vlasenko
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. # Opening quote in "omitting directory 'dir'" message:
  6. sq='`' # GNU cp: `
  7. sq="'" # bbox cp: '
  8. rm -rf cp.testdir >/dev/null
  9. mkdir cp.testdir
  10. mkdir cp.testdir/dir
  11. > cp.testdir/dir/file
  12. ln -s file cp.testdir/dir/file_symlink
  13. > cp.testdir/file
  14. ln -s file cp.testdir/file_symlink
  15. ln -s dir cp.testdir/dir_symlink
  16. # testing "test name" "command" "expected result" "file input" "stdin"
  17. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  18. testing "cp" '\
  19. cd cp.testdir || exit 1; cp * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  20. test ! -L file && test -f file || echo BAD: file
  21. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  22. test ! -L dir && test ! -e dir || echo BAD: dir
  23. test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
  24. ' "\
  25. cp: omitting directory ${sq}dir'
  26. cp: omitting directory ${sq}dir_symlink'
  27. 1
  28. " "" ""
  29. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  30. testing "cp -d" '\
  31. cd cp.testdir || exit 1; cp -d * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  32. test ! -L file && test -f file || echo BAD: file
  33. test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  34. test ! -L dir && test ! -e dir || echo BAD: dir
  35. test -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
  36. ' "\
  37. cp: omitting directory ${sq}dir'
  38. 1
  39. " "" ""
  40. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  41. testing "cp -P" '\
  42. cd cp.testdir || exit 1; cp -P * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  43. test ! -L file && test -f file || echo BAD: file
  44. test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  45. test ! -L dir && test ! -e dir || echo BAD: dir
  46. test -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
  47. ' "\
  48. cp: omitting directory ${sq}dir'
  49. 1
  50. " "" ""
  51. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  52. testing "cp -L" '\
  53. cd cp.testdir || exit 1; cp -L * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  54. test ! -L file && test -f file || echo BAD: file
  55. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  56. test ! -L dir && test ! -e dir || echo BAD: dir
  57. test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
  58. ' "\
  59. cp: omitting directory ${sq}dir'
  60. cp: omitting directory ${sq}dir_symlink'
  61. 1
  62. " "" ""
  63. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  64. testing "cp -H" '\
  65. cd cp.testdir || exit 1; cp -H * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  66. test ! -L file && test -f file || echo BAD: file
  67. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  68. test ! -L dir && test ! -e dir || echo BAD: dir
  69. test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
  70. ' "\
  71. cp: omitting directory ${sq}dir'
  72. cp: omitting directory ${sq}dir_symlink'
  73. 1
  74. " "" ""
  75. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  76. testing "cp -R" '\
  77. cd cp.testdir || exit 1; cp -R * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  78. test ! -L file && test -f file || echo BAD: file
  79. test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  80. test ! -L dir && test -d dir || echo BAD: dir
  81. test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  82. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  83. test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  84. ' "\
  85. 0
  86. " "" ""
  87. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  88. testing "cp -Rd" '\
  89. cd cp.testdir || exit 1; cp -Rd * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  90. test ! -L file && test -f file || echo BAD: file
  91. test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  92. test ! -L dir && test -d dir || echo BAD: dir
  93. test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  94. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  95. test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  96. ' "\
  97. 0
  98. " "" ""
  99. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  100. testing "cp -RP" '\
  101. cd cp.testdir || exit 1; cp -RP * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  102. test ! -L file && test -f file || echo BAD: file
  103. test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  104. test ! -L dir && test -d dir || echo BAD: dir
  105. test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  106. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  107. test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  108. ' "\
  109. 0
  110. " "" ""
  111. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  112. testing "cp -RL" '\
  113. cd cp.testdir || exit 1; cp -RL * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  114. test ! -L file && test -f file || echo BAD: file
  115. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  116. test ! -L dir && test -d dir || echo BAD: dir
  117. test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  118. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  119. test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  120. ' "\
  121. 0
  122. " "" ""
  123. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  124. # GNU coreutils 7.2 says:
  125. # cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir'
  126. test x"$SKIP_KNOWN_BUGS" = x"" && \
  127. testing "cp -RH" '\
  128. cd cp.testdir || exit 1; cp -RH * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  129. test ! -L file && test -f file || echo BAD: file
  130. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  131. test ! -L dir && test -d dir || echo BAD: dir
  132. test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  133. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  134. test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  135. ' "\
  136. 0
  137. " "" ""
  138. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  139. # GNU coreutils 7.2 says:
  140. # cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir'
  141. test x"$SKIP_KNOWN_BUGS" = x"" && \
  142. testing "cp -RHP" '\
  143. cd cp.testdir || exit 1; cp -RHP * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  144. test ! -L file && test -f file || echo BAD: file
  145. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  146. test ! -L dir && test -d dir || echo BAD: dir
  147. test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  148. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  149. test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  150. ' "\
  151. 0
  152. " "" ""
  153. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  154. testing "cp -RHL" '\
  155. cd cp.testdir || exit 1; cp -RHL * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  156. test ! -L file && test -f file || echo BAD: file
  157. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  158. test ! -L dir && test -d dir || echo BAD: dir
  159. test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  160. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  161. test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  162. ' "\
  163. 0
  164. " "" ""
  165. rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
  166. # Wow! "cp -RLH" is not the same as "cp -RHL" (prev test)!
  167. # GNU coreutils 7.2 says:
  168. # cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir'
  169. test x"$SKIP_KNOWN_BUGS" = x"" && \
  170. testing "cp -RLH" '\
  171. cd cp.testdir || exit 1; cp -RLH * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
  172. test ! -L file && test -f file || echo BAD: file
  173. test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
  174. test ! -L dir && test -d dir || echo BAD: dir
  175. test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
  176. test ! -L dir/file && test -f dir/file || echo BAD: dir/file
  177. test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
  178. ' "\
  179. 0
  180. " "" ""
  181. # Clean up
  182. rm -rf cp.testdir cp.testdir2 2>/dev/null
  183. exit $FAILCOUNT