mirror of
https://github.com/jimeh/dotify.git
synced 2026-02-19 10:06:39 +00:00
Reorganize internal functions
This commit is contained in:
50
test/lib/internals/create-symlink-test.sh
Executable file
50
test/lib/internals/create-symlink-test.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals.sh"
|
||||
|
||||
#
|
||||
# create-symlink() tests
|
||||
#
|
||||
|
||||
# Create temp files/folders used for create-symlink() tests.
|
||||
mkdir -p "tmp/source" "tmp/target"
|
||||
touch "tmp/source/profile"
|
||||
|
||||
# Creates a normal symlink.
|
||||
assert_raises 'create-symlink ../source tmp/target/.dotfiles' 0
|
||||
assert 'readlink tmp/target/.dotfiles' "../source"
|
||||
rm "tmp/target/.dotfiles"
|
||||
|
||||
# When target exists an is a symlink to the same source.
|
||||
ln -s "../source" "tmp/target/.dotfiles"
|
||||
assert_raises 'create-symlink ../source tmp/target/.dotfiles' 0
|
||||
assert 'create-symlink ../source tmp/target/.dotfiles 2>&1' ""
|
||||
rm "tmp/target/.dotfiles"
|
||||
|
||||
# When target exists and is a symlink to a different source.
|
||||
ln -s "../other" "tmp/target/.dotfiles"
|
||||
assert_raises 'create-symlink ../source tmp/target/.dotfiles' 1
|
||||
assert 'create-symlink ../source tmp/target/.dotfiles' ""
|
||||
assert 'create-symlink ../source tmp/target/.dotfiles 2>&1' \
|
||||
"ERROR: \"tmp/target/.dotfiles\" exists, is a symlink to: ../other"
|
||||
rm "tmp/target/.dotfiles"
|
||||
|
||||
# When target exists and is a file.
|
||||
touch "tmp/target/.profile"
|
||||
assert_raises 'create-symlink ../source/profile tmp/target/.profile' 1
|
||||
assert 'create-symlink ../source/profile tmp/target/.profile' ""
|
||||
assert 'create-symlink ../source/profile tmp/target/.profile 2>&1' \
|
||||
"ERROR: \"tmp/target/.profile\" exists"
|
||||
rm "tmp/target/.profile"
|
||||
|
||||
# When target exists and is a directory.
|
||||
assert_raises 'create-symlink ../source tmp/target' 1
|
||||
assert 'create-symlink ../source tmp/target' ""
|
||||
assert 'create-symlink ../source tmp/target 2>&1' \
|
||||
"ERROR: \"tmp/target\" exists"
|
||||
|
||||
# Remove temp files/folders used for locate-dotfile() tests.
|
||||
rm "tmp/source/profile"
|
||||
rmdir "tmp/source" "tmp/target" "tmp"
|
||||
|
||||
assert_end 'create-symlink()'
|
||||
@@ -1,9 +1,9 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../test-helper.sh"
|
||||
source "../../src/lib/internals.sh"
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals.sh"
|
||||
|
||||
#
|
||||
# locate-dotfile()
|
||||
# locate-dotfile() tests
|
||||
#
|
||||
|
||||
# Create temp files/folders used for locate-dotfile() tests.
|
||||
@@ -49,37 +49,3 @@ assert_raises "test -d test-tmp" 1
|
||||
|
||||
# End of locate-dotfile() tests.
|
||||
assert_end 'locate-dotfile()'
|
||||
|
||||
|
||||
#
|
||||
# locate-target()
|
||||
#
|
||||
|
||||
# When $TARGET is empty.
|
||||
TARGET=""
|
||||
assert_raises 'locate-target' 0
|
||||
assert 'locate-target; echo "$TARGET"' "$HOME"
|
||||
unset TARGET
|
||||
|
||||
# When $TARGET is not empty and is a directory.
|
||||
TARGET="$(pwd)"
|
||||
assert_raises 'locate-target' 0
|
||||
assert 'locate-target; echo "$TARGET"' "$(pwd)"
|
||||
unset TARGET
|
||||
|
||||
# When $TARGET is not empty and is not a directory.
|
||||
TARGET="/tmp/this/does/not/exist"
|
||||
assert_raises 'locate-target' 1
|
||||
assert 'locate-target 2>&1' "ERROR: Target \"$TARGET\" is not a directory."
|
||||
assert 'locate-target; echo "$TARGET"' "$TARGET"
|
||||
unset TARGET
|
||||
|
||||
# If neither $TARGET or $HOME is set, ~ is expanded to find home folder
|
||||
original_home="$HOME"
|
||||
unset HOME
|
||||
assert_raises 'locate-target' 0
|
||||
assert 'locate-target; echo "$TARGET"' "$original_home"
|
||||
HOME="$original_home"
|
||||
|
||||
# End of locate-target() tests.
|
||||
assert_end 'locate-target()'
|
||||
36
test/lib/internals/locate-target-test.sh
Executable file
36
test/lib/internals/locate-target-test.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals.sh"
|
||||
|
||||
#
|
||||
# locate-target() tests
|
||||
#
|
||||
|
||||
# When $TARGET is empty.
|
||||
TARGET=""
|
||||
assert_raises 'locate-target' 0
|
||||
assert 'locate-target; echo "$TARGET"' "$HOME"
|
||||
unset TARGET
|
||||
|
||||
# When $TARGET is not empty and is a directory.
|
||||
TARGET="$(pwd)"
|
||||
assert_raises 'locate-target' 0
|
||||
assert 'locate-target; echo "$TARGET"' "$(pwd)"
|
||||
unset TARGET
|
||||
|
||||
# When $TARGET is not empty and is not a directory.
|
||||
TARGET="/tmp/this/does/not/exist"
|
||||
assert_raises 'locate-target' 1
|
||||
assert 'locate-target 2>&1' "ERROR: Target \"$TARGET\" is not a directory."
|
||||
assert 'locate-target; echo "$TARGET"' "$TARGET"
|
||||
unset TARGET
|
||||
|
||||
# If neither $TARGET or $HOME is set, ~ is expanded to find home folder
|
||||
original_home="$HOME"
|
||||
unset HOME
|
||||
assert_raises 'locate-target' 0
|
||||
assert 'locate-target; echo "$TARGET"' "$original_home"
|
||||
HOME="$original_home"
|
||||
|
||||
# End of locate-target() tests.
|
||||
assert_end 'locate-target()'
|
||||
@@ -4,7 +4,7 @@ source "../../src/lib/parse-dotfile-options.sh"
|
||||
source "../../src/lib/trim.sh"
|
||||
|
||||
#
|
||||
# parse-dotfile-options()
|
||||
# parse-dotfile-options() tests
|
||||
#
|
||||
|
||||
stub "parse-dotfile-root_link-option"
|
||||
@@ -24,7 +24,7 @@ assert_end "parse-dotfile-options()"
|
||||
|
||||
|
||||
#
|
||||
# parse-dotfile-option()
|
||||
# parse-dotfile-option() tests
|
||||
#
|
||||
|
||||
# Create temp files/folders used for locate-dotfile() tests.
|
||||
@@ -62,7 +62,7 @@ assert_end "parse-dotfile-option()"
|
||||
|
||||
|
||||
#
|
||||
# parse-dotfile-root_link-option()
|
||||
# parse-dotfile-root_link-option() tests
|
||||
#
|
||||
|
||||
stub "parse-dotfile-option"
|
||||
@@ -76,7 +76,7 @@ assert_end "parse-dotfile-root_link-option()"
|
||||
|
||||
|
||||
#
|
||||
# parse-dotfile-default_action-option()
|
||||
# parse-dotfile-default_action-option() tests
|
||||
#
|
||||
|
||||
stub "parse-dotfile-option"
|
||||
Reference in New Issue
Block a user