logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

mv.t (4324B)


  1. #!/usr/bin/env cram
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. $ export PATH="$TESTDIR/../cmd:$PATH"
  5. $ test "$(command -v mv)" = "$TESTDIR/../cmd/mv"
  6. POSIX, non-directory target with a trailing slash is an error
  7. $ touch nondir file
  8. $ mv file nondir/
  9. mv: Failed opening destination directory 'nondir/': Not a directory
  10. [1]
  11. $ test -e file
  12. $ test -e nondir
  13. $ mv enoent nondir/
  14. mv: Failed opening destination directory 'nondir/': Not a directory
  15. [1]
  16. $ rm nondir file
  17. POSIX mv(1) step 1a, no -f option, no -i option
  18. $ mkdir -m -w 1a_no-f_no-write
  19. $ touch src
  20. $ printf '\n' | mv src 1a_no-f_no-write/dest
  21. mv: Failed moving 'src' to './1a_no-f_no-write/dest': Permission denied
  22. [1]
  23. $ test -e src
  24. $ printf 'n\n' | mv src 1a_no-f_no-write/dest
  25. mv: Failed moving 'src' to './1a_no-f_no-write/dest': Permission denied
  26. [1]
  27. $ test -e src
  28. $ printf 'y\n' | mv src 1a_no-f_no-write/dest
  29. mv: Failed moving 'src' to './1a_no-f_no-write/dest': Permission denied
  30. [1]
  31. $ test ! -e src
  32. [1]
  33. $ rm -fr 1a_no-f_no-write
  34. POSIX mv(1) step 1b, no -f option, -i passed
  35. $ mkdir 1a_no-f_write
  36. $ touch src 1a_no-f_write/dest
  37. $ printf '\n' | mv -i src 1a_no-f_write/dest
  38. mv: Destination file './1a_no-f_write/dest' already exists, overwrite? [yN]
  39. mv: Got empty response, considering it false
  40. $ test -e src
  41. $ test -d 1a_no-f_write
  42. $ printf 'n\n' | mv -i src 1a_no-f_write/dest
  43. mv: Destination file './1a_no-f_write/dest' already exists, overwrite? [yN] n
  44. $ test -f src
  45. $ test -d 1a_no-f_write
  46. $ printf 'y\n' | mv -i src 1a_no-f_write/dest
  47. mv: Destination file './1a_no-f_write/dest' already exists, overwrite? [yN] y
  48. $ test ! -e src
  49. $ test -d 1a_no-f_write
  50. $ rm -fr 1a_no-f_write
  51. POSIX mv(1) step 2, same file
  52. $ touch same-name
  53. $ mv same-name same-name
  54. mv: Error, passed to both source and destination: 'same-name'
  55. [1]
  56. $ test -e same-name
  57. $ rm same-name
  58. POSIX mv(1) step 2, same file, hardlink
  59. $ touch same-src-h
  60. $ ln same-src-h same-dest-h
  61. $ mv same-src-h same-src-h
  62. mv: Error, passed to both source and destination: 'same-src-h'
  63. [1]
  64. $ test -e same-src-h
  65. $ test -e same-dest-h
  66. $ rm same-src-h same-dest-h
  67. POSIX mv(1) step 2, same file, symlink
  68. $ touch same-src-s
  69. $ ln -s same-src-s same-dest-s
  70. $ mv same-src-s same-src-s
  71. mv: Error, passed to both source and destination: 'same-src-s'
  72. [1]
  73. $ test -e same-src-s
  74. $ test -e same-dest-s
  75. $ rm same-src-s same-dest-s
  76. Where destination is an existing directory
  77. $ mkdir destdir
  78. $ touch foo
  79. $ mv foo destdir
  80. $ test ! -e foo
  81. $ test -d destdir
  82. $ test -f destdir/foo
  83. $ rm -r destdir
  84. $ mkdir destdir_trail/
  85. $ touch foo_trail
  86. $ mv foo_trail destdir_trail/
  87. $ test ! -e foo_trail
  88. $ test -d destdir_trail
  89. $ test -f destdir_trail/foo_trail
  90. $ rm -r destdir_trail
  91. Where destination is an existing file
  92. $ touch foo_file destfile
  93. $ mv foo_file destfile
  94. $ test ! -e foo_file
  95. $ test -f destfile
  96. $ rm destfile
  97. $ touch foo_file_i destfile_i
  98. $ printf 'y\n' | mv -i foo_file_i destfile_i
  99. mv: Destination file './destfile_i' already exists, overwrite? [yN] y
  100. $ test ! -e foo_file_i
  101. $ test -f destfile_i
  102. $ rm destfile_i
  103. $ touch foo_file_trail destfile_trail
  104. $ mv foo_file_trail destfile_trail/
  105. mv: Failed opening destination directory 'destfile_trail/': Not a directory
  106. [1]
  107. $ test -f foo_file_trail
  108. $ test -f destfile_trail
  109. $ rm foo_file_trail destfile_trail
  110. Verbose (non-standard)
  111. $ touch foo
  112. $ mv -v foo bar
  113. mv: renamed 'foo' -> './bar'
  114. $ test ! -e foo
  115. $ test -e bar
  116. $ rm bar
  117. Last component used for destination filename
  118. $ mkdir -p src_last/dir dest_last
  119. $ touch src_last/dir/file
  120. $ mv src_last/dir/file dest_last/
  121. $ test -f dest_last/file
  122. $ test ! -e dest_last/dir/file
  123. $ test ! -e src_last/dir/file
  124. $ mv src_last/dir dest_last
  125. $ test -d dest_last/dir
  126. $ test ! -e src_last/dir
  127. $ test -f dest_last/file
  128. $ rm -r src_last dest_last
  129. Works with non-resolving source symlinks
  130. $ ln -s /var/empty/e/no/ent symlink_enoent
  131. $ test -L symlink_enoent
  132. $ mv symlink_enoent symlink_enoent.done
  133. $ test ! -L symlink_enoent
  134. $ test -L symlink_enoent.done
  135. $ rm symlink_enoent.done
  136. No files should be left
  137. $ find .
  138. .