ln.sh (4074B)
- #!/bin/sh
- # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- plans=63
- WD=$(dirname "$0")
- target="${WD}/../cmd/ln"
- . "${WD}/tap.sh"
- t_readlink() {
- t_cmd "readlink:$1 -> $2" "$2
- " readlink "$1"
- }
- t_args --exit=1 hard_enoent \
- "ln: error: Failed creating hard link from 'hard_enoent_src' to 'hard_enoent_dest': No such file or directory
- " \
- hard_enoent_src hard_enoent_dest
- t_args --exit=1 soft_enoent \
- "ln: error: Failed creating symlink 'hard_enoent_dest/hard_enoent_ref1': No such file or directory
- " \
- -s hard_enoent_ref1 hard_enoent_ref2 hard_enoent_dest
- t_cmd '' '' touch hard_file_src
- t_args 'hard_file' '' hard_file_src hard_file_dest
- t_cmd '' '' test -f hard_file_dest
- t_cmd '' '' rm hard_file_src hard_file_dest
- t_cmd '' '' touch hard_file_src1 ./hard_file_src2
- t_cmd '' '' mkdir hard_dir_dest
- t_args 'hard_file_dir' '' hard_file_src1 ./hard_file_src2 hard_dir_dest
- t_cmd '' '' test -f hard_dir_dest/hard_file_src1
- t_cmd '' '' test -f hard_dir_dest/hard_file_src2
- t_cmd '' '' rm hard_file_src1 hard_file_src2
- t_cmd '' '' rm -r hard_dir_dest
- t_args 'sym_enoent' '' -s sym_enoent_ref sym_enoent_dest
- t_readlink sym_enoent_dest sym_enoent_ref
- t_cmd '' '' rm sym_enoent_dest
- t_args --exit=1 'sym_enoent2' \
- "ln: error: Failed creating symlink 'sym_enoent_dest/sym_enoent_ref1': No such file or directory
- " \
- -s sym_enoent_ref1 sym_enoent_ref2 sym_enoent_dest
- t_cmd '' '' mkdir sym_dir_slash
- t_args 'sym_dir_slash' '' -s sym_enoent_ref1 ./sym_enoent_ref2 sym_dir_slash/
- t_readlink sym_dir_slash/sym_enoent_ref1 sym_enoent_ref1
- t_readlink sym_dir_slash/sym_enoent_ref2 ./sym_enoent_ref2
- t_cmd '' '' rm -r sym_dir_slash
- t_cmd '' '' mkdir sym_dir_noslash
- t_args 'sym_dir_noslash' '' -s sym_enoent_ref1 ./sym_enoent_ref2 sym_dir_noslash
- t_readlink sym_dir_noslash/sym_enoent_ref1 sym_enoent_ref1
- t_readlink sym_dir_noslash/sym_enoent_ref2 ./sym_enoent_ref2
- t_cmd '' '' rm -r sym_dir_noslash
- t_cmd '' '' touch force_symlink
- t_args --exit=1 'force_symlink' "ln: error: Destination 'force_symlink' already exists
- " -s foo force_symlink
- t_cmd --exit=1 '' '' test -L force_symlink
- t_args 'force_symlink:force' '' -sf foo force_symlink
- t_cmd '' '' test -L force_symlink
- t_cmd '' '' rm force_symlink
- t_cmd '' '' mkdir n_directory
- t_args 'n_directory:n_dir_symlink' '' -s n_directory n_dir_symlink
- t_args --exit=1 'n_directory:sn' "ln: error: Destination 'n_dir_symlink' already exists
- " -sn //example.org n_dir_symlink
- t_readlink n_dir_symlink n_directory
- t_args 'n_dir_symlink:snf' '' -snf //example.org n_dir_symlink
- t_readlink n_dir_symlink //example.org
- t_cmd '' '' rm -r n_directory n_dir_symlink
- t_cmd '' '' mkdir e_target_dir
- t_args 'e_ref_dir:e_target_dir' '' -s e_ref_dir e_target_dir
- t_cmd '' '' test '!' -e e_ref_dir
- t_cmd '' '' test '!' -L e_target_dir
- t_cmd '' '' test -d e_target_dir
- t_cmd '' '' test -L e_target_dir/e_ref_dir
- echo mere copy > e_src_dir
- t_cmd '' '' test -f e_src_dir
- t_args 'e_src_dir:e_target_dir' '' e_src_dir e_target_dir
- echo hardlink > e_src_dir
- t_cmd '' '' test -d e_target_dir
- t_cmd '' '' test -f e_target_dir/e_src_dir
- t_cmd '' 'hardlink
- ' cat e_target_dir/e_src_dir
- t_cmd '' '' rm -r e_target_dir e_src_dir
- t_args 'implicit_dest' '' -sn //example.org
- t_readlink ./example.org //example.org
- t_cmd '' '' rm ./example.org
- t_args 'target_broken_symlink:create' '' -s /var/empty/e/no/ent target_broken_symlink
- t_args --exit=1 'target_broken_symlink' "\
- ln: error: Destination 'target_broken_symlink' already exists
- " -s //example.org target_broken_symlink
- t_args 'target_broken_symlink:force' '' -sf //example.org target_broken_symlink
- t_cmd 'target_broken_symlink:cleanup' '' rm target_broken_symlink
- t_args 'dest_broken_symlink:create' '' -s /foo/bar/dest_broken_symlink ./
- t_args --exit=1 'dest_broken_symlink' "\
- ln: error: Destination './/dest_broken_symlink' already exists
- " -s /foo/bar/dest_broken_symlink ./
- t_args 'dest_broken_symlink:force' '' -sf /foo/bar/dest_broken_symlink ./
- t_cmd 'dest_broken_symlink:cleanup' '' rm dest_broken_symlink