logo

utils-std

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

ln.sh (4074B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. plans=63
  5. WD=$(dirname "$0")
  6. target="${WD}/../cmd/ln"
  7. . "${WD}/tap.sh"
  8. t_readlink() {
  9. t_cmd "readlink:$1 -> $2" "$2
  10. " readlink "$1"
  11. }
  12. t_args --exit=1 hard_enoent \
  13. "ln: error: Failed creating hard link from 'hard_enoent_src' to 'hard_enoent_dest': No such file or directory
  14. " \
  15. hard_enoent_src hard_enoent_dest
  16. t_args --exit=1 soft_enoent \
  17. "ln: error: Failed creating symlink 'hard_enoent_dest/hard_enoent_ref1': No such file or directory
  18. " \
  19. -s hard_enoent_ref1 hard_enoent_ref2 hard_enoent_dest
  20. t_cmd '' '' touch hard_file_src
  21. t_args 'hard_file' '' hard_file_src hard_file_dest
  22. t_cmd '' '' test -f hard_file_dest
  23. t_cmd '' '' rm hard_file_src hard_file_dest
  24. t_cmd '' '' touch hard_file_src1 ./hard_file_src2
  25. t_cmd '' '' mkdir hard_dir_dest
  26. t_args 'hard_file_dir' '' hard_file_src1 ./hard_file_src2 hard_dir_dest
  27. t_cmd '' '' test -f hard_dir_dest/hard_file_src1
  28. t_cmd '' '' test -f hard_dir_dest/hard_file_src2
  29. t_cmd '' '' rm hard_file_src1 hard_file_src2
  30. t_cmd '' '' rm -r hard_dir_dest
  31. t_args 'sym_enoent' '' -s sym_enoent_ref sym_enoent_dest
  32. t_readlink sym_enoent_dest sym_enoent_ref
  33. t_cmd '' '' rm sym_enoent_dest
  34. t_args --exit=1 'sym_enoent2' \
  35. "ln: error: Failed creating symlink 'sym_enoent_dest/sym_enoent_ref1': No such file or directory
  36. " \
  37. -s sym_enoent_ref1 sym_enoent_ref2 sym_enoent_dest
  38. t_cmd '' '' mkdir sym_dir_slash
  39. t_args 'sym_dir_slash' '' -s sym_enoent_ref1 ./sym_enoent_ref2 sym_dir_slash/
  40. t_readlink sym_dir_slash/sym_enoent_ref1 sym_enoent_ref1
  41. t_readlink sym_dir_slash/sym_enoent_ref2 ./sym_enoent_ref2
  42. t_cmd '' '' rm -r sym_dir_slash
  43. t_cmd '' '' mkdir sym_dir_noslash
  44. t_args 'sym_dir_noslash' '' -s sym_enoent_ref1 ./sym_enoent_ref2 sym_dir_noslash
  45. t_readlink sym_dir_noslash/sym_enoent_ref1 sym_enoent_ref1
  46. t_readlink sym_dir_noslash/sym_enoent_ref2 ./sym_enoent_ref2
  47. t_cmd '' '' rm -r sym_dir_noslash
  48. t_cmd '' '' touch force_symlink
  49. t_args --exit=1 'force_symlink' "ln: error: Destination 'force_symlink' already exists
  50. " -s foo force_symlink
  51. t_cmd --exit=1 '' '' test -L force_symlink
  52. t_args 'force_symlink:force' '' -sf foo force_symlink
  53. t_cmd '' '' test -L force_symlink
  54. t_cmd '' '' rm force_symlink
  55. t_cmd '' '' mkdir n_directory
  56. t_args 'n_directory:n_dir_symlink' '' -s n_directory n_dir_symlink
  57. t_args --exit=1 'n_directory:sn' "ln: error: Destination 'n_dir_symlink' already exists
  58. " -sn //example.org n_dir_symlink
  59. t_readlink n_dir_symlink n_directory
  60. t_args 'n_dir_symlink:snf' '' -snf //example.org n_dir_symlink
  61. t_readlink n_dir_symlink //example.org
  62. t_cmd '' '' rm -r n_directory n_dir_symlink
  63. t_cmd '' '' mkdir e_target_dir
  64. t_args 'e_ref_dir:e_target_dir' '' -s e_ref_dir e_target_dir
  65. t_cmd '' '' test '!' -e e_ref_dir
  66. t_cmd '' '' test '!' -L e_target_dir
  67. t_cmd '' '' test -d e_target_dir
  68. t_cmd '' '' test -L e_target_dir/e_ref_dir
  69. echo mere copy > e_src_dir
  70. t_cmd '' '' test -f e_src_dir
  71. t_args 'e_src_dir:e_target_dir' '' e_src_dir e_target_dir
  72. echo hardlink > e_src_dir
  73. t_cmd '' '' test -d e_target_dir
  74. t_cmd '' '' test -f e_target_dir/e_src_dir
  75. t_cmd '' 'hardlink
  76. ' cat e_target_dir/e_src_dir
  77. t_cmd '' '' rm -r e_target_dir e_src_dir
  78. t_args 'implicit_dest' '' -sn //example.org
  79. t_readlink ./example.org //example.org
  80. t_cmd '' '' rm ./example.org
  81. t_args 'target_broken_symlink:create' '' -s /var/empty/e/no/ent target_broken_symlink
  82. t_args --exit=1 'target_broken_symlink' "\
  83. ln: error: Destination 'target_broken_symlink' already exists
  84. " -s //example.org target_broken_symlink
  85. t_args 'target_broken_symlink:force' '' -sf //example.org target_broken_symlink
  86. t_cmd 'target_broken_symlink:cleanup' '' rm target_broken_symlink
  87. t_args 'dest_broken_symlink:create' '' -s /foo/bar/dest_broken_symlink ./
  88. t_args --exit=1 'dest_broken_symlink' "\
  89. ln: error: Destination './/dest_broken_symlink' already exists
  90. " -s /foo/bar/dest_broken_symlink ./
  91. t_args 'dest_broken_symlink:force' '' -sf /foo/bar/dest_broken_symlink ./
  92. t_cmd 'dest_broken_symlink:cleanup' '' rm dest_broken_symlink