Update output of dotify-create-symlink command

This commit is contained in:
2015-07-03 13:06:02 +01:00
parent 246d9bac5e
commit f88fbba4ae
2 changed files with 26 additions and 19 deletions

View File

@@ -4,19 +4,19 @@ dotify-create-symlink() {
if [ ! -e "$target" ] && [ ! -h "$target" ]; then if [ ! -e "$target" ] && [ ! -h "$target" ]; then
ln -s "$source" "$target" ln -s "$source" "$target"
echo "created" echo " create: $target --> $source"
return 0 return 0
elif [ -h "$target" ]; then elif [ -h "$target" ]; then
if [ "$(readlink "$target")" == "$source" ]; then local link_source="$(readlink "$target")"
echo "exists" if [ "$link_source" == "$source" ]; then
echo " exists: $target"
return 0 return 0
else else
echo "ERROR: \"$target\" exists, is a symlink to:" \ echo " exists: $target -- is symlink to: $link_source"
"$(readlink "$target")" >&2
return 1 return 1
fi fi
else else
echo "ERROR: \"$target\" exists" >&2 echo " exists: $target -- is a regular file/folder"
return 1 return 2
fi fi
} }

View File

@@ -14,39 +14,46 @@ touch "tmp/source/profile"
assert_raises 'dotify-create-symlink ../source tmp/target/.dotfiles' 0 assert_raises 'dotify-create-symlink ../source tmp/target/.dotfiles' 0
assert 'readlink tmp/target/.dotfiles' "../source" assert 'readlink tmp/target/.dotfiles' "../source"
rm "tmp/target/.dotfiles" 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" 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" rm "tmp/target/.dotfiles"
# When target exists and is a symlink to the same source. # When target exists and is a symlink to the same source.
ln -s "../source" "tmp/target/.dotfiles" ln -s "../source" "tmp/target/.dotfiles"
assert_raises 'dotify-create-symlink ../source tmp/target/.dotfiles' 0 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' \
assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' "exists" " exists: tmp/target/.dotfiles"
assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' \
" exists: tmp/target/.dotfiles"
rm "tmp/target/.dotfiles" rm "tmp/target/.dotfiles"
# When target exists and is a symlink to a different source. # When target exists and is a symlink to a different source.
ln -s "../other" "tmp/target/.dotfiles" ln -s "../other" "tmp/target/.dotfiles"
assert_raises 'dotify-create-symlink ../source tmp/target/.dotfiles' 1 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' \ 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" rm "tmp/target/.dotfiles"
# When target exists and is a file. # When target exists and is a file.
touch "tmp/target/.profile" touch "tmp/target/.profile"
assert_raises 'dotify-create-symlink ../source/profile tmp/target/.profile' 1 assert_raises 'dotify-create-symlink ../source/profile tmp/target/.profile' 2
assert 'dotify-create-symlink ../source/profile tmp/target/.profile' "" 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' \ 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" rm "tmp/target/.profile"
# When target exists and is a directory. # When target exists and is a directory.
assert_raises 'dotify-create-symlink ../source tmp/target' 1 assert_raises 'dotify-create-symlink ../source tmp/target' 2
assert 'dotify-create-symlink ../source tmp/target' "" assert 'dotify-create-symlink ../source tmp/target' \
" exists: tmp/target -- is a regular file/folder"
assert 'dotify-create-symlink ../source tmp/target 2>&1' \ 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. # Remove temp files/folders used for locate-dotfile() tests.
rm "tmp/source/profile" rm "tmp/source/profile"