logo

utils-std

Collection of commonly available Unix tools

mv.t (3756B)


  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
  53. $ mv same same
  54. mv: Error, passed to both source and destination: 'same'
  55. [1]
  56. $ test -e same
  57. $ ln same Same
  58. $ mv same Same
  59. $ test -e same
  60. $ test -e Same
  61. $ ln -s same same-s
  62. $ mv same same-s
  63. $ test -e same
  64. $ test -e Same
  65. $ test -e same-s
  66. $ mv Same same-s
  67. $ test -e same
  68. $ test -e Same
  69. $ test -e same-s
  70. $ rm same Same same-s
  71. Where destination is an existing directory
  72. $ mkdir destdir
  73. $ touch foo
  74. $ mv foo destdir
  75. $ test ! -e foo
  76. $ test -d destdir
  77. $ test -f destdir/foo
  78. $ rm -r destdir
  79. $ mkdir destdir_trail/
  80. $ touch foo_trail
  81. $ mv foo_trail destdir_trail/
  82. $ test ! -e foo_trail
  83. $ test -d destdir_trail
  84. $ test -f destdir_trail/foo_trail
  85. $ rm -r destdir_trail
  86. Where destination is an existing file
  87. $ touch foo_file destfile
  88. $ mv foo_file destfile
  89. $ test ! -e foo_file
  90. $ test -f destfile
  91. $ rm destfile
  92. $ touch foo_file_i destfile_i
  93. $ printf 'y\n' | mv -i foo_file_i destfile_i
  94. mv: Destination file './destfile_i' already exists, overwrite? [yN] y
  95. $ test ! -e foo_file_i
  96. $ test -f destfile_i
  97. $ rm destfile_i
  98. $ touch foo_file_trail destfile_trail
  99. $ mv foo_file_trail destfile_trail/
  100. mv: Failed opening destination directory 'destfile_trail/': Not a directory
  101. [1]
  102. $ test -f foo_file_trail
  103. $ test -f destfile_trail
  104. $ rm foo_file_trail destfile_trail
  105. Verbose (non-standard)
  106. $ touch foo
  107. $ mv -v foo bar
  108. mv: renamed 'foo' -> './bar'
  109. $ test ! -e foo
  110. $ test -e bar
  111. $ rm bar
  112. Last component used for destination filename
  113. $ mkdir -p src_last/dir dest_last
  114. $ touch src_last/dir/file
  115. $ mv src_last/dir/file dest_last/
  116. $ test -f dest_last/file
  117. $ test ! -e dest_last/dir/file
  118. $ test ! -e src_last/dir/file
  119. $ mv src_last/dir dest_last
  120. $ test -d dest_last/dir
  121. $ test ! -e src_last/dir
  122. $ test -f dest_last/file
  123. $ rm -r src_last dest_last
  124. No files should be left
  125. $ find .
  126. .