From 0eeb5677650dc35ce3e3bef77b6a9a3154d221d2 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 12 Feb 2015 00:03:43 +0000 Subject: make and remove tmp dirs for tests to be more cleanly --- unit-tests.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'unit-tests.sh') diff --git a/unit-tests.sh b/unit-tests.sh index 2f106e5..adf8ea8 100755 --- a/unit-tests.sh +++ b/unit-tests.sh @@ -1,18 +1,38 @@ - scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/git-base.sh" +tmpfile="" + +cd_to_tmp() { + tmpfile="/tmp/git-prompt-tests-$(time_now)" + mkdir -p "$tmpfile" + cd "$tmpfile" +} + +rm_tmp() { + cd $scriptDir + rm -r "$tmpfile" +} + test_git_root_in_repo() { cd $scriptDir local root="$(git_root)" assertEquals "$scriptDir" "$root" } +test_git_root_not_in_repo() { + cd_to_tmp + local root="$(git_root)" + assertEquals "" "$root" + rm_tmp +} + test_dot_git_location_not_in_repo() { - cd / + cd_to_tmp local filePath="$(dot_git)" assertEquals "" "$filePath" + rm_tmp } test_dot_git_location_in_repo() { @@ -23,8 +43,9 @@ test_dot_git_location_in_repo() { } test_is_repo_not_in_repo() { - cd / + cd_to_tmp assertFalse is_repo + rm_tmp } test_is_repo_in_repo() { -- cgit v1.2.3