diff --git a/src/lib/internals/create-symlink.sh b/src/lib/internals/create-symlink.sh index c22ffb9..c0a91d1 100644 --- a/src/lib/internals/create-symlink.sh +++ b/src/lib/internals/create-symlink.sh @@ -4,19 +4,19 @@ dotify-create-symlink() { if [ ! -e "$target" ] && [ ! -h "$target" ]; then ln -s "$source" "$target" - echo "created" + echo " create: $target --> $source" return 0 elif [ -h "$target" ]; then - if [ "$(readlink "$target")" == "$source" ]; then - echo "exists" + local link_source="$(readlink "$target")" + if [ "$link_source" == "$source" ]; then + echo " exists: $target" return 0 else - echo "ERROR: \"$target\" exists, is a symlink to:" \ - "$(readlink "$target")" >&2 + echo " exists: $target -- is symlink to: $link_source" return 1 fi else - echo "ERROR: \"$target\" exists" >&2 - return 1 + echo " exists: $target -- is a regular file/folder" + return 2 fi } diff --git a/test/lib/internals/create-symlink.test.sh b/test/lib/internals/create-symlink.test.sh index ec9283e..3793324 100755 --- a/test/lib/internals/create-symlink.test.sh +++ b/test/lib/internals/create-symlink.test.sh @@ -14,39 +14,46 @@ touch "tmp/source/profile" assert_raises 'dotify-create-symlink ../source tmp/target/.dotfiles' 0 assert 'readlink tmp/target/.dotfiles' "../source" rm "tmp/target/.dotfiles" -assert 'dotify-create-symlink ../source tmp/target/.dotfiles' "created" +assert 'dotify-create-symlink ../source tmp/target/.dotfiles' \ + " create: tmp/target/.dotfiles --> ../source" rm "tmp/target/.dotfiles" -assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' "created" +assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' \ + " create: tmp/target/.dotfiles --> ../source" rm "tmp/target/.dotfiles" # When target exists and is a symlink to the same source. ln -s "../source" "tmp/target/.dotfiles" assert_raises 'dotify-create-symlink ../source tmp/target/.dotfiles' 0 -assert 'dotify-create-symlink ../source tmp/target/.dotfiles' "exists" -assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' "exists" +assert 'dotify-create-symlink ../source tmp/target/.dotfiles' \ + " exists: tmp/target/.dotfiles" +assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' \ + " exists: tmp/target/.dotfiles" rm "tmp/target/.dotfiles" # When target exists and is a symlink to a different source. ln -s "../other" "tmp/target/.dotfiles" assert_raises 'dotify-create-symlink ../source tmp/target/.dotfiles' 1 -assert 'dotify-create-symlink ../source tmp/target/.dotfiles' "" +assert 'dotify-create-symlink ../source tmp/target/.dotfiles' \ + " exists: tmp/target/.dotfiles -- is symlink to: ../other" assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' \ - "ERROR: \"tmp/target/.dotfiles\" exists, is a symlink to: ../other" + " exists: tmp/target/.dotfiles -- is symlink to: ../other" rm "tmp/target/.dotfiles" # When target exists and is a file. touch "tmp/target/.profile" -assert_raises 'dotify-create-symlink ../source/profile tmp/target/.profile' 1 -assert 'dotify-create-symlink ../source/profile tmp/target/.profile' "" +assert_raises 'dotify-create-symlink ../source/profile tmp/target/.profile' 2 +assert 'dotify-create-symlink ../source/profile tmp/target/.profile' \ + " exists: tmp/target/.profile -- is a regular file/folder" assert 'dotify-create-symlink ../source/profile tmp/target/.profile 2>&1' \ - "ERROR: \"tmp/target/.profile\" exists" + " exists: tmp/target/.profile -- is a regular file/folder" rm "tmp/target/.profile" # When target exists and is a directory. -assert_raises 'dotify-create-symlink ../source tmp/target' 1 -assert 'dotify-create-symlink ../source tmp/target' "" +assert_raises 'dotify-create-symlink ../source tmp/target' 2 +assert 'dotify-create-symlink ../source tmp/target' \ + " exists: tmp/target -- is a regular file/folder" assert 'dotify-create-symlink ../source tmp/target 2>&1' \ - "ERROR: \"tmp/target\" exists" + " exists: tmp/target -- is a regular file/folder" # Remove temp files/folders used for locate-dotfile() tests. rm "tmp/source/profile"