diff options
author | Malfurious <m@lfurio.us> | 2021-03-24 02:59:48 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2021-03-24 02:59:48 -0400 |
commit | a9737ee899dcfee46d8765c1b534b8c9df68cbe6 (patch) | |
tree | 2e0a68fbec1d86915e37c1db1c7768504f6e01e0 | |
parent | fee615fe9fd3a535bd6dfd8fcf01c3dee9300b6c (diff) | |
parent | 51bd4bc64308f1eb8e1aab20d6f3280549098267 (diff) | |
download | git-sonar-a9737ee899dcfee46d8765c1b534b8c9df68cbe6.tar.gz git-sonar-a9737ee899dcfee46d8765c1b534b8c9df68cbe6.zip |
Merge branch 'hotfix/unittests' of https://github.com/cbandera/git-radar
Merge pending pull request #67 of upstream git-radar project from user
cbandera. They write:
This is a pull request to fix issue #38. As it turns out, some built in
commands behave differently on Mac OS X and Linux.
In order to run the tests on Linux, I have added switch statements at
some points to call the functions with the respective syntax.
Also I realized, that the tests only worked for me when I set the
following options:
git config --global push.default simple
git config --global branch.autosetuprebase never
But that's probably just because these should be the defaults. I
normally have them set to something else...
-rwxr-xr-x | radar-base.sh | 7 | ||||
-rwxr-xr-x | test-branches.sh | 10 | ||||
-rwxr-xr-x | test-colors.sh | 11 | ||||
-rwxr-xr-x | test-commits.sh | 18 | ||||
-rwxr-xr-x | test-directories.sh | 8 | ||||
-rwxr-xr-x | test-files.sh | 51 | ||||
-rwxr-xr-x | test-format-config.sh | 1 | ||||
-rwxr-xr-x | test-radar-base.sh | 3 | ||||
-rwxr-xr-x | test-status.sh | 1 |
9 files changed, 70 insertions, 40 deletions
diff --git a/radar-base.sh b/radar-base.sh index 649978f..5ea2a0f 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -174,7 +174,12 @@ record_timestamp() { timestamp() { if is_repo; then - printf '%s' "$($(stat_type) -c%Y "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" + if [[ $OSTYPE == darwin* ]];then + printf '%s' "$(stat -f%m "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" + else + printf '%s' "$(stat -c %Y "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" + fi; + fi } diff --git a/test-branches.sh b/test-branches.sh index 5c33d23..891a819 100755 --- a/test-branches.sh +++ b/test-branches.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" @@ -96,8 +97,13 @@ test_remote_branch_name_quiet_when_not_in_repo() { echo "$debug_output" - assertEquals " 0" "$usages" - + if [[ $OSTYPE == darwin* ]];then + expected=" 0" + else + expected="0" + fi; + assertEquals "$expected" "$usages" + rm_tmp } diff --git a/test-colors.sh b/test-colors.sh index 927dab3..6243c8f 100755 --- a/test-colors.sh +++ b/test-colors.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" @@ -296,7 +297,7 @@ test_bash_colors_local() { assertEquals "$expected" "$(color_local_commits)" git push --quiet >/dev/null - git reset --hard head^ --quiet >/dev/null + git reset --hard HEAD^ --quiet >/dev/null printf -v expected "1\x01local-behind\x02↓\x01local-reset\x02" assertEquals "$expected" "$(bash_color_local_commits)" @@ -340,7 +341,7 @@ test_zsh_colors_local() { assertEquals "1%{local-ahead%}↑%{local-reset%}" "$(zsh_color_local_commits)" git push --quiet >/dev/null - git reset --hard head^ --quiet >/dev/null + git reset --hard HEAD^ --quiet >/dev/null assertEquals "1%{local-behind%}↓%{local-reset%}" "$(zsh_color_local_commits)" @@ -376,7 +377,7 @@ test_bash_colors_remote() { git push --quiet -u origin master >/dev/null repoLocation="$(pwd)" - git reset --hard head^ --quiet >/dev/null + git reset --hard HEAD^ --quiet >/dev/null git checkout -b mybranch --quiet git push --quiet -u origin mybranch >/dev/null @@ -387,7 +388,7 @@ test_bash_colors_remote() { echo "bar" > bar git add . git commit -m "new commit" --quiet - git push --quiet >/dev/null + git push --quiet origin mybranch >/dev/null printf -v expected "m 1 \x01remote-diverged\x02⇄\x01remote-reset\x02 1" assertEquals "$expected" "$(bash_color_remote_commits)" @@ -426,7 +427,7 @@ test_zsh_colors_remote() { git push --quiet -u origin master >/dev/null repoLocation="$(pwd)" - git reset --hard head^ --quiet >/dev/null + git reset --hard HEAD^ --quiet >/dev/null git checkout -b mybranch --quiet git push --quiet -u origin mybranch >/dev/null diff --git a/test-commits.sh b/test-commits.sh index 6c317f9..7634103 100755 --- a/test-commits.sh +++ b/test-commits.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" @@ -14,7 +15,6 @@ rm_tmp() { cd $scriptDir rm -rf /tmp/git-prompt-tests* } - test_commits_with_no_commits() { cd_to_tmp git init --quiet @@ -222,7 +222,6 @@ test_remote_branch_starts_with_local_branch_name() { rm_tmp } - test_remote_branch_ends_with_local_branch_name() { cd_to_tmp "remote" git init --bare --quiet @@ -297,11 +296,15 @@ test_dont_call_remote_branch_name() { usages="$(echo "$debug_output" | grep 'remote_branch_name' | wc -l )" #wc -l has a weird output - assertEquals " 0" "$usages" + if [[ $OSTYPE == darwin* ]];then + expected=" 0" + else + expected="0" + fi; + assertEquals "$expected" "$usages" rm_tmp } - test_dont_remote_if_remote_is_master() { cd_to_tmp git init --quiet @@ -322,7 +325,12 @@ test_dont_remote_if_remote_is_master() { usages="$(echo "$debug_output" | grep 'git rev-list' | wc -l )" - assertEquals " 0" "$usages" + if [[ $OSTYPE == darwin* ]];then + expected=" 0" + else + expected="0" + fi; + assertEquals "$expected" "$usages" rm_tmp } diff --git a/test-directories.sh b/test-directories.sh index 5dde303..219a9f3 100755 --- a/test-directories.sh +++ b/test-directories.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" @@ -64,7 +65,12 @@ test_record_timestamp_in_repo() { test_time_to_update_when_timestamp_is_old() { cd $scriptDir FETCH_TIME="$((5 * 60))" # Fetch every 5 mins - touch -A "-010000" "$(dot_git)/lastupdatetime" + if [[ $OSTYPE == darwin* ]];then + touch -A "-010000" "$(dot_git)/lastupdatetime" + else + newtimestamp=$(date -d "now -1 hour" +%Y%m%d%H%M) + touch -t $newtimestamp "$(dot_git)/lastupdatetime" + fi; assertTrue time_to_update } diff --git a/test-files.sh b/test-files.sh index b27a18c..8b06732 100755 --- a/test-files.sh +++ b/test-files.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" @@ -24,7 +25,7 @@ test_untracked_files() { touch foo assertEquals "1?" "$(untracked_status)" - git add . + git add --all assertEquals "" "$(untracked_status)" rm_tmp @@ -38,7 +39,7 @@ test_unstaged_modified_files() { touch foo touch bar - git add . + git add --all git commit -m "foo and bar" >/dev/null echo "foo" >> foo @@ -58,7 +59,7 @@ test_unstaged_deleted_files() { touch foo touch bar - git add . + git add --all git commit -m "foo and bar" >/dev/null rm foo @@ -77,11 +78,11 @@ test_staged_added_files() { assertEquals "" "$(staged_status)" touch foo - git add . + git add --all assertEquals "1A" "$(staged_status)" touch bar - git add . + git add --all assertEquals "2A" "$(staged_status)" rm_tmp @@ -95,15 +96,15 @@ test_staged_modified_files() { touch foo touch bar - git add . + git add --all git commit -m "foo and bar" >/dev/null echo "foo" >> foo - git add . + git add --all assertEquals "1M" "$(staged_status)" echo "bar" >> bar - git add . + git add --all assertEquals "2M" "$(staged_status)" rm_tmp @@ -117,15 +118,15 @@ test_staged_deleted_files() { touch foo touch bar - git add . + git add --all git commit -m "foo and bar" >/dev/null rm foo - git add . + git add --all assertEquals "1D" "$(staged_status)" rm bar - git add . + git add --all assertEquals "2D" "$(staged_status)" rm_tmp @@ -139,15 +140,15 @@ test_staged_renamed_files() { touch foo touch bar - git add . + git add --all git commit -m "foo and bar" >/dev/null mv foo foo2 - git add . + git add --all assertEquals "1R" "$(staged_status)" mv bar bar2 - git add . + git add --all assertEquals "2R" "$(staged_status)" rm_tmp @@ -159,17 +160,17 @@ test_conflicted_both_changes() { git checkout -b foo --quiet echo "foo" >> foo - git add . + git add --all git commit -m "foo" --quiet git checkout -b foo2 --quiet echo "bar" >> foo - git add . + git add --all git commit -m "bar" --quiet git checkout foo --quiet echo "foo2" >> foo - git add . + git add --all git commit -m "foo2" --quiet assertEquals "" "$(conflicted_status)" @@ -187,17 +188,17 @@ test_conflicted_them_changes() { git checkout -b foo --quiet echo "foo" >> foo - git add . + git add --all git commit -m "foo" --quiet git checkout -b foo2 --quiet rm foo - git add . + git add --all git commit -m "delete foo" --quiet git checkout foo --quiet echo "foo2" >> foo - git add . + git add --all git commit -m "foo2" --quiet assertEquals "" "$(conflicted_status)" @@ -215,17 +216,17 @@ test_conflicted_us_changes() { git checkout -b foo --quiet echo "foo" >> foo - git add . + git add --all git commit -m "foo" --quiet git checkout -b foo2 --quiet echo "bar" >> foo - git add . + git add --all git commit -m "bar" --quiet git checkout foo --quiet rm foo - git add . + git add --all git commit -m "delete foo" --quiet assertEquals "" "$(conflicted_status)" @@ -254,7 +255,7 @@ test_is_dirty() { cd ../ - git add . + git add --all assertTrue "staged addition files" is_dirty git commit -m "inital commit" --quiet @@ -264,7 +265,7 @@ test_is_dirty() { echo "foo" >> foo assertTrue "modified file unstaged" is_dirty - git add . + git add --all assertTrue "modified file staged" is_dirty rm_tmp diff --git a/test-format-config.sh b/test-format-config.sh index c5852e5..7e62c9f 100755 --- a/test-format-config.sh +++ b/test-format-config.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" diff --git a/test-radar-base.sh b/test-radar-base.sh index 9f7f8ee..ca1ddfd 100755 --- a/test-radar-base.sh +++ b/test-radar-base.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" @@ -25,4 +26,4 @@ test_show_remote_status() { assertFalse $? } -. ./shunit/shunit2
\ No newline at end of file +. ./shunit/shunit2 diff --git a/test-status.sh b/test-status.sh index 7378986..3d5dc46 100755 --- a/test-status.sh +++ b/test-status.sh @@ -1,3 +1,4 @@ +#!/bin/bash scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" |