From 8d7c08e7f0d1fd880345cf4c62b0568e509ce13a Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 12 Feb 2015 00:07:07 +0000 Subject: separate tests into modules --- test-directories.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++ test.sh | 88 ++--------------------------------------------------- unit-tests.sh | 76 --------------------------------------------- 3 files changed, 78 insertions(+), 162 deletions(-) create mode 100755 test-directories.sh delete mode 100755 unit-tests.sh diff --git a/test-directories.sh b/test-directories.sh new file mode 100755 index 0000000..adf8ea8 --- /dev/null +++ b/test-directories.sh @@ -0,0 +1,76 @@ +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_to_tmp + local filePath="$(dot_git)" + assertEquals "" "$filePath" + rm_tmp +} + +test_dot_git_location_in_repo() { + cd $scriptDir + local filePath="$(dot_git)" + local expected=".git" + assertEquals "$expected" "$filePath" +} + +test_is_repo_not_in_repo() { + cd_to_tmp + assertFalse is_repo + rm_tmp +} + +test_is_repo_in_repo() { + cd $scriptDir + assertTrue is_repo +} + +test_record_timestamp_in_repo() { + cd $scriptDir + record_timestamp + local timestamp="$(timestamp)" + local timenow="$(time_now)" + assertSame "$timenow" "$timestamp" +} + +test_time_to_update_when_timestamp_is_old() { + cd $scriptDir + touch -A "-010000" "$(dot_git)/lastupdatetime" + assertTrue time_to_update +} + +test_not_time_to_update_when_just_recorded() { + cd $scriptDir + record_timestamp + assertFalse time_to_update +} + +. ./shunit/shunit2 diff --git a/test.sh b/test.sh index cc65c64..06bbc29 100755 --- a/test.sh +++ b/test.sh @@ -1,87 +1,3 @@ -set -e +#!/bin/sh -scriptDir="$( dirname "$0" )" - -source "$scriptDir/git-base.sh" - -echo "\n---------------------------" -echo "\n In a git repo" -echo "\n---------------------------" - -echo "\nTest: Root of this git repo" -echo "$(git_root)" - -echo "\nTest: Location of .git" -echo "$(dot_git)" - -echo "\nTest: is_repo should be false" -if is_repo; then - echo "is repo" -else - echo "not repo" -fi - -echo "\nTest: Record the timestamp" -record_timestamp -echo "Timestamp = $(timestamp)" -echo "Time now = $(time_now)" - -echo "\nTest: Time to update when just recorded" -if time_to_update; then - echo "time to update" -else - echo "not time yet" -fi - -echo "\nTest: Don't fetch if it's not time to update" -fetch_async "debug" - -echo "\nTest: Time to update when timestamp 5 mins ago" -touch -A "-010000" "$(dot_git)/lastupdatetime" -if time_to_update; then - echo "time to update" -else - echo "not time yet" -fi - -echo "\nTest: Do a non-blocking git fetch" -fetch_async "debug" -echo "Did I block?" - - -echo "\n---------------------------" -echo "\n Not in a git repo" -echo "\n---------------------------" - -mkdir -p /tmp/git-base-tests -cd /tmp/git-base-tests - -echo "\nTest: Root of this git repo" -echo "git_root is:$(git_root) (empty means no root)" - -echo "\nTest: Location of .git" -echo "dot_git is:$(dot_git) (empty means no root)" - -echo "\nTest: is_repo should be false" -if is_repo; then - echo "is repo" -else - echo "not repo" -fi - -echo "\nTest: Record the timestamp" -record_timestamp -echo "no output should be seen" - -echo "\nTest: Check the timestamp" -echo "timestamp is:$(timestamp) (empty means not in dir)" - -echo "\nTest: Is it time to update?" -if time_to_update; then - echo "time to update" -else - echo "not time yet" -fi - -echo "\nTest: Try to fetch" -fetch_async "debug" +./test-directories.sh diff --git a/unit-tests.sh b/unit-tests.sh deleted file mode 100755 index adf8ea8..0000000 --- a/unit-tests.sh +++ /dev/null @@ -1,76 +0,0 @@ -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_to_tmp - local filePath="$(dot_git)" - assertEquals "" "$filePath" - rm_tmp -} - -test_dot_git_location_in_repo() { - cd $scriptDir - local filePath="$(dot_git)" - local expected=".git" - assertEquals "$expected" "$filePath" -} - -test_is_repo_not_in_repo() { - cd_to_tmp - assertFalse is_repo - rm_tmp -} - -test_is_repo_in_repo() { - cd $scriptDir - assertTrue is_repo -} - -test_record_timestamp_in_repo() { - cd $scriptDir - record_timestamp - local timestamp="$(timestamp)" - local timenow="$(time_now)" - assertSame "$timenow" "$timestamp" -} - -test_time_to_update_when_timestamp_is_old() { - cd $scriptDir - touch -A "-010000" "$(dot_git)/lastupdatetime" - assertTrue time_to_update -} - -test_not_time_to_update_when_just_recorded() { - cd $scriptDir - record_timestamp - assertFalse time_to_update -} - -. ./shunit/shunit2 -- cgit v1.2.3