mirror of
https://github.com/jimeh/dotify.git
synced 2026-02-19 10:06:39 +00:00
Massive restructuring code-base
This commit is contained in:
33
test/integration/link-action-test.sh
Executable file
33
test/integration/link-action-test.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../test-helper.sh"
|
||||
source "../../src/lib/dotify-action.sh"
|
||||
|
||||
#
|
||||
# Integration test: link action
|
||||
#
|
||||
|
||||
# Create temp files/folders used for tests.
|
||||
TEST_SOURCE="tmp/source"
|
||||
TEST_TARGET="tmp/target"
|
||||
MY_DOTFILE="$TEST_SOURCE/Dotfile"
|
||||
mkdir -p "$TEST_SOURCE" "$TEST_TARGET"
|
||||
|
||||
PROFILE_TXT="# I am a .profile file"
|
||||
echo "$PROFILE_TXT" > "tmp/source/profile"
|
||||
|
||||
# Basic of basics.
|
||||
echo -e "profile -> .profile" > "$MY_DOTFILE"
|
||||
assert_raises "../../bin/dotify -f '$MY_DOTFILE' -t '$TEST_TARGET'" 0
|
||||
assert "../../bin/dotify -f '$MY_DOTFILE' -t '$TEST_TARGET'" \
|
||||
" Create symlink: $TEST_TARGET/.profile -> .dotfiles/profile"
|
||||
assert "readlink '$TEST_TARGET/.profile'" ".dotfiles/profile"
|
||||
assert "cat '$TEST_TARGET/.profile'" "$PROFILE_TXT"
|
||||
rm "TEST_TARGET/.profile"
|
||||
rm "$MY_DOTFILE"
|
||||
|
||||
|
||||
# Remove temp files/folders used for locate-dotfile() tests.
|
||||
rm "tmp/source/profile"
|
||||
rmdir "tmp/source" "tmp/target" "tmp"
|
||||
|
||||
assert_end 'Integration: link action'
|
||||
@@ -1,20 +1,15 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../test-helper.sh"
|
||||
source "../../src/lib/dotify-action.sh"
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals/action.sh"
|
||||
|
||||
#
|
||||
# dotify-action() tests
|
||||
#
|
||||
|
||||
# Set required environment variables.
|
||||
DOTIFY_RUN_MODE="install"
|
||||
DOTIFY_OPT_DEFAULT_ACTION="link"
|
||||
|
||||
# Simple mock for link action.
|
||||
dotify-action-link() {
|
||||
echo "link stub: $@"
|
||||
}
|
||||
|
||||
stub "dotify-setup-root-link"
|
||||
stub_and_echo "dotify-get-run-mode" "install"
|
||||
stub_and_echo "dotify-get-default-action" "link"
|
||||
stub_and_echo "dotify-action-link" "link stub: \$@"
|
||||
|
||||
# Given a specific action.
|
||||
assert "dotify-action link ackrc .ackrc" "link stub: install .ackrc ackrc"
|
||||
@@ -34,4 +29,8 @@ assert_raises "dotify-action foo ackrc .ackrc" 1
|
||||
assert "dotify-action foo ackrc .ackrc" ""
|
||||
assert "dotify-action foo ackrc .ackrc 2>&1" "ERROR: \"foo\" is not a valid action."
|
||||
|
||||
|
||||
restore "dotify-setup-root-link"
|
||||
restore "dotify-get-run-mode"
|
||||
restore "dotify-action-link"
|
||||
assert_end "dotify-action()"
|
||||
@@ -4,7 +4,7 @@ source "../../../src/lib/helpers/trim.sh"
|
||||
source "../../../src/lib/internals/compile-dotfile.sh"
|
||||
|
||||
#
|
||||
# compile-dotfile() tests
|
||||
# dotify-compile-dotfile() tests
|
||||
#
|
||||
|
||||
# Create temp files/folders used for locate-dotfile() tests.
|
||||
@@ -14,27 +14,28 @@ echo "hostname='air'" > $dotfile
|
||||
|
||||
|
||||
# Compiles file given as first argument.
|
||||
assert "compile-dotfile $dotfile" "hostname='air'"
|
||||
assert_raises "compile-dotfile tmp/fake" 1
|
||||
assert "compile-dotfile tmp/fake" ""
|
||||
assert "compile-dotfile tmp/fake 2>&1" "ERROR: \"tmp/fake\" does not exist."
|
||||
assert "dotify-compile-dotfile $dotfile" "hostname='air'"
|
||||
assert_raises "dotify-compile-dotfile tmp/fake" 1
|
||||
assert "dotify-compile-dotfile tmp/fake" ""
|
||||
assert "dotify-compile-dotfile tmp/fake 2>&1" \
|
||||
"ERROR: \"tmp/fake\" does not exist."
|
||||
|
||||
|
||||
# Compiles file from global $DOTFILE variable.
|
||||
DOTFILE=$dotfile
|
||||
assert "compile-dotfile" "hostname='air'"
|
||||
DOTFILE="tmp/fake"
|
||||
assert_raises "compile-dotfile" 1
|
||||
assert "compile-dotfile" ""
|
||||
assert "compile-dotfile 2>&1" "ERROR: \"tmp/fake\" does not exist."
|
||||
unset DOTFILE
|
||||
# Compiles file from dotify-get-dotfile-path attribute helper.
|
||||
stub_and_echo "dotify-get-dotfile-path" "$dotfile"
|
||||
assert "dotify-compile-dotfile" "hostname='air'"
|
||||
stub_and_echo "dotify-get-dotfile-path" "tmp/fake"
|
||||
assert_raises "dotify-compile-dotfile" 1
|
||||
assert "dotify-compile-dotfile" ""
|
||||
assert "dotify-compile-dotfile 2>&1" "ERROR: \"tmp/fake\" does not exist."
|
||||
restore "dotify-get-dotfile-path"
|
||||
|
||||
|
||||
# Compiles standard actions
|
||||
echo -e "root_link .dotfiles
|
||||
link: ackrc -> .ackrc
|
||||
link: gitconfig -> \".gitconfig\"" > $dotfile
|
||||
assert "compile-dotfile $dotfile" "root_link .dotfiles
|
||||
assert "dotify-compile-dotfile $dotfile" "root_link .dotfiles
|
||||
dotify-action link ackrc .ackrc
|
||||
dotify-action link gitconfig \".gitconfig\""
|
||||
|
||||
@@ -43,7 +44,7 @@ dotify-action link gitconfig \".gitconfig\""
|
||||
echo -e "root_link .dotfiles
|
||||
link: -> .ackrc
|
||||
link:-> \".gitconfig\"" > $dotfile
|
||||
assert "compile-dotfile $dotfile" "root_link .dotfiles
|
||||
assert "dotify-compile-dotfile $dotfile" "root_link .dotfiles
|
||||
dotify-action link .ackrc
|
||||
dotify-action link \".gitconfig\""
|
||||
|
||||
@@ -52,7 +53,7 @@ dotify-action link \".gitconfig\""
|
||||
echo -e "root_link .dotfiles
|
||||
link: ackrc -> .ackrc
|
||||
gitconfig -> \".gitconfig\"" > $dotfile
|
||||
assert "compile-dotfile $dotfile" "root_link .dotfiles
|
||||
assert "dotify-compile-dotfile $dotfile" "root_link .dotfiles
|
||||
dotify-action link ackrc .ackrc
|
||||
dotify-action default gitconfig \".gitconfig\""
|
||||
|
||||
@@ -61,7 +62,7 @@ dotify-action default gitconfig \".gitconfig\""
|
||||
echo -e "root_link .dotfiles
|
||||
-> .ackrc
|
||||
-> \".gitconfig\"" > $dotfile
|
||||
assert "compile-dotfile $dotfile" "root_link .dotfiles
|
||||
assert "dotify-compile-dotfile $dotfile" "root_link .dotfiles
|
||||
dotify-action default .ackrc
|
||||
dotify-action default \".gitconfig\""
|
||||
|
||||
@@ -71,7 +72,7 @@ echo -e "root_link .dotfiles
|
||||
if [ true ]; then
|
||||
ackrc -> .ackrc
|
||||
fi" > $dotfile
|
||||
assert "compile-dotfile $dotfile" "root_link .dotfiles
|
||||
assert "dotify-compile-dotfile $dotfile" "root_link .dotfiles
|
||||
if [ true ]; then
|
||||
dotify-action default ackrc .ackrc
|
||||
fi"
|
||||
@@ -87,7 +88,7 @@ profile -> .profile
|
||||
# Apps
|
||||
ackrc -> .ackrc
|
||||
gitconfig -> .gitconfig" > $dotfile
|
||||
assert "compile-dotfile $dotfile" "root_link .dotfiles
|
||||
assert "dotify-compile-dotfile $dotfile" "root_link .dotfiles
|
||||
dotify-action default profile .profile
|
||||
dotify-action default ackrc .ackrc
|
||||
dotify-action default gitconfig .gitconfig"
|
||||
@@ -98,4 +99,4 @@ rm "tmp/Dotfile"
|
||||
rmdir "tmp"
|
||||
assert_raises "test -d tmp" 1
|
||||
|
||||
assert_end 'compile-dotfile()'
|
||||
assert_end 'dotify-compile-dotfile()'
|
||||
|
||||
@@ -3,48 +3,53 @@ source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals/create-symlink.sh"
|
||||
|
||||
#
|
||||
# create-symlink() tests
|
||||
# dotify-create-symlink() tests
|
||||
#
|
||||
|
||||
# Create temp files/folders used for create-symlink() tests.
|
||||
# Create temp files/folders used for dotify-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_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"
|
||||
rm "tmp/target/.dotfiles"
|
||||
assert 'dotify-create-symlink ../source tmp/target/.dotfiles 2>&1' "created"
|
||||
rm "tmp/target/.dotfiles"
|
||||
|
||||
# When target exists an is a symlink to the same source.
|
||||
# When target exists and 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' ""
|
||||
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"
|
||||
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' \
|
||||
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 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' \
|
||||
assert_raises 'dotify-create-symlink ../source/profile tmp/target/.profile' 1
|
||||
assert 'dotify-create-symlink ../source/profile tmp/target/.profile' ""
|
||||
assert 'dotify-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' \
|
||||
assert_raises 'dotify-create-symlink ../source tmp/target' 1
|
||||
assert 'dotify-create-symlink ../source tmp/target' ""
|
||||
assert 'dotify-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()'
|
||||
assert_end 'dotify-create-symlink()'
|
||||
|
||||
32
test/lib/internals/has-action-test.sh
Executable file
32
test/lib/internals/has-action-test.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals/register-action.sh"
|
||||
source "../../../src/lib/internals/has-action.sh"
|
||||
|
||||
#
|
||||
# dotify-register-action() tests
|
||||
#
|
||||
|
||||
# When no actions are registered.
|
||||
assert_raises 'dotify-has-action "link"' 1
|
||||
|
||||
# When checking an action that is registered.
|
||||
dotify-register-action "link"
|
||||
assert_raises 'dotify-has-action "link"' 0
|
||||
unset DOTIFY_ACTIONS
|
||||
|
||||
# When checking an action that is not registered.
|
||||
dotify-register-action "link"
|
||||
assert_raises 'dotify-has-action "git"' 1
|
||||
unset DOTIFY_ACTIONS
|
||||
|
||||
# When registering and checking multiple actions
|
||||
dotify-register-action "link"
|
||||
dotify-register-action "git"
|
||||
assert_raises 'dotify-has-action "link"' 0
|
||||
assert_raises 'dotify-has-action "git"' 0
|
||||
assert_raises 'dotify-has-action "copy"' 1
|
||||
unset DOTIFY_ACTIONS
|
||||
|
||||
|
||||
assert_end "dotify-register-action() tests"
|
||||
@@ -1,51 +0,0 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals/locate-dotfile.sh"
|
||||
|
||||
#
|
||||
# locate-dotfile() tests
|
||||
#
|
||||
|
||||
# Create temp files/folders used for locate-dotfile() tests.
|
||||
mkdir -p "test-tmp/with" "test-tmp/without"
|
||||
touch "test-tmp/with/Dotfile"
|
||||
|
||||
# When $DOTFILE is empty and current path has a Dotfile.
|
||||
cd "test-tmp/with"
|
||||
DOTFILE=""
|
||||
assert_raises 'locate-dotfile' 0
|
||||
assert 'locate-dotfile; echo "$DOTFILE"' "$(pwd)/Dotfile"
|
||||
unset DOTFILE
|
||||
cd-back
|
||||
|
||||
# When $DOTFILE is empty and current path does not have a Dotfile.
|
||||
cd "test-tmp/without"
|
||||
DOTFILE=""
|
||||
assert_raises 'locate-dotfile' 1
|
||||
assert 'locate-dotfile 2>&1' "ERROR: \"$(pwd)\" does not have a Dotfile."
|
||||
assert 'locate-dotfile; echo "$DOTFILE"' ""
|
||||
unset DOTFILE
|
||||
cd-back
|
||||
|
||||
# When $DOTFILE is not empty and points at a existing Dotfile.
|
||||
DOTFILE="test-tmp/with/Dotfile"
|
||||
assert_raises 'locate-dotfile' 0
|
||||
assert 'locate-dotfile; echo "$DOTFILE"' "$DOTFILE"
|
||||
unset DOTFILE
|
||||
|
||||
# When $DOTFILE is not empty and points at a non-existing Dotfile.
|
||||
DOTFILE="test-tmp/without/Dotfile"
|
||||
assert_raises 'locate-dotfile' 1
|
||||
assert 'locate-dotfile 2>&1' "ERROR: \"$DOTFILE\" does not exist."
|
||||
assert 'locate-dotfile; echo "$DOTFILE"' "$DOTFILE"
|
||||
unset DOTFILE
|
||||
|
||||
# Remove temp files/folders used for locate-dotfile() tests.
|
||||
rm "test-tmp/with/Dotfile"
|
||||
rmdir "test-tmp/with" "test-tmp/without" "test-tmp"
|
||||
|
||||
# Ensure temp files/folder were cleaned up.
|
||||
assert_raises "test -d test-tmp" 1
|
||||
|
||||
# End of locate-dotfile() tests.
|
||||
assert_end 'locate-dotfile()'
|
||||
@@ -1,36 +0,0 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals/locate-target.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()'
|
||||
28
test/lib/internals/register-action-test.sh
Executable file
28
test/lib/internals/register-action-test.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/internals/register-action.sh"
|
||||
|
||||
#
|
||||
# dotify-register-action() tests
|
||||
#
|
||||
|
||||
# Registering an action.
|
||||
dotify-register-action "link"
|
||||
assert 'echo ${DOTIFY_ACTIONS[@]}' "link"
|
||||
unset DOTIFY_ACTIONS
|
||||
|
||||
# Registering multiple actions.
|
||||
dotify-register-action "link"
|
||||
dotify-register-action "git"
|
||||
assert 'echo ${DOTIFY_ACTIONS[@]}' "link git"
|
||||
unset DOTIFY_ACTIONS
|
||||
|
||||
# Registering the same action multiple times.
|
||||
dotify-register-action "link"
|
||||
dotify-register-action "link"
|
||||
assert 'echo ${DOTIFY_ACTIONS[@]}' "link"
|
||||
assert_raises 'dotify-register-action "link"' 1
|
||||
unset DOTIFY_ACTIONS
|
||||
|
||||
|
||||
assert_end "dotify-register-action() tests"
|
||||
Reference in New Issue
Block a user