From 1572e18e60e0702561d1d59d140615ab7ff54295 Mon Sep 17 00:00:00 2001 From: "Eduardo R. D'Avila" Date: Wed, 26 Jun 2013 00:05:13 -0300 Subject: t9903: add tests for git-prompt pcmode git-prompt.sh lacks tests for PROMPT_COMMAND mode. Add tests for: * pcmode prompt without colors * pcmode prompt with colors for bash * pcmode prompt with colors for zsh Having these tests enables an upcoming refactor in a safe way. Signed-off-by: Eduardo R. D'Avila Signed-off-by: Junio C Hamano --- t/t9903-bash-prompt.sh | 254 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) (limited to 't') diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index 15521cc4f9..6a88778fe6 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -10,6 +10,10 @@ test_description='test git-specific bash prompt functions' . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh" actual="$TRASH_DIRECTORY/actual" +c_red='\\[\\e[31m\\]' +c_green='\\[\\e[32m\\]' +c_lblue='\\[\\e[1;34m\\]' +c_clear='\\[\\e[0m\\]' test_expect_success 'setup for prompt tests' ' mkdir -p subdir/subsubdir && @@ -535,4 +539,254 @@ test_expect_success 'prompt - format string starting with dash' ' test_cmp expected "$actual" ' +test_expect_success 'prompt - pc mode' ' + printf "BEFORE: (master):AFTER" >expected && + printf "" >expected_output && + ( + __git_ps1 "BEFORE:" ":AFTER" >"$actual" && + test_cmp expected_output "$actual" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - branch name' ' + printf "BEFORE: (${c_green}master${c_clear}${c_clear}):AFTER" >expected && + ( + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" >"$actual" + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - detached head' ' + printf "BEFORE: (${c_red}(%s...)${c_clear}${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected && + git checkout b1^ && + test_when_finished "git checkout master" && + ( + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' ' + printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_clear}):AFTER" >expected && + echo "dirty" >file && + test_when_finished "git reset --hard" && + ( + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' ' + printf "BEFORE: (${c_green}master${c_clear} ${c_green}+${c_clear}):AFTER" >expected && + echo "dirty" >file && + test_when_finished "git reset --hard" && + git add -u && + ( + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' ' + printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER" >expected && + echo "dirty index" >file && + test_when_finished "git reset --hard" && + git add -u && + echo "dirty worktree" >file && + ( + GIT_PS1_SHOWCOLORHINTS=y && + GIT_PS1_SHOWDIRTYSTATE=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' ' + printf "BEFORE: (${c_green}master${c_clear} ${c_green}#${c_clear}):AFTER" >expected && + ( + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + cd otherrepo && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - inside .git directory' ' + printf "BEFORE: (${c_green}GIT_DIR!${c_clear}${c_clear}):AFTER" >expected && + echo "dirty" >file && + test_when_finished "git reset --hard" && + ( + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + cd .git && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - stash status indicator' ' + printf "BEFORE: (${c_green}master${c_clear} ${c_lblue}\$${c_clear}):AFTER" >expected && + echo 2 >file && + git stash && + test_when_finished "git stash drop" && + ( + GIT_PS1_SHOWSTASHSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - bash color pc mode - untracked files status indicator' ' + printf "BEFORE: (${c_green}master${c_clear} ${c_red}%%${c_clear}):AFTER" >expected && + ( + GIT_PS1_SHOWUNTRACKEDFILES=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - branch name' ' + printf "BEFORE: (%%F{green}master%%f%%f):AFTER" >expected && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" >"$actual" + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - detached head' ' + printf "BEFORE: (%%F{red}(%s...)%%f%%f):AFTER" $(git log -1 --format="%h" b1^) >expected && + git checkout b1^ && + test_when_finished "git checkout master" && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty worktree' ' + printf "BEFORE: (%%F{green}master%%f %%F{red}*%%f):AFTER" >expected && + echo "dirty" >file && + test_when_finished "git reset --hard" && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index' ' + printf "BEFORE: (%%F{green}master%%f %%F{green}+%%f):AFTER" >expected && + echo "dirty" >file && + test_when_finished "git reset --hard" && + git add -u && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index and worktree' ' + printf "BEFORE: (%%F{green}master%%f %%F{red}*%%F{green}+%%f):AFTER" >expected && + echo "dirty index" >file && + test_when_finished "git reset --hard" && + git add -u && + echo "dirty worktree" >file && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWCOLORHINTS=y && + GIT_PS1_SHOWDIRTYSTATE=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - dirty status indicator - before root commit' ' + printf "BEFORE: (%%F{green}master%%f %%F{green}#%%f):AFTER" >expected && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + cd otherrepo && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - inside .git directory' ' + printf "BEFORE: (%%F{green}GIT_DIR!%%f%%f):AFTER" >expected && + echo "dirty" >file && + test_when_finished "git reset --hard" && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWDIRTYSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + cd .git && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - stash status indicator' ' + printf "BEFORE: (%%F{green}master%%f %%F{blue}$%%f):AFTER" >expected && + echo 2 >file && + git stash && + test_when_finished "git stash drop" && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWSTASHSTATE=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + +test_expect_success 'prompt - zsh color pc mode - untracked files status indicator' ' + printf "BEFORE: (%%F{green}master%%f %%F{red}%%%%%%f):AFTER" >expected && + ( + ZSH_VERSION=5.0.0 && + GIT_PS1_SHOWUNTRACKEDFILES=y && + GIT_PS1_SHOWCOLORHINTS=y && + __git_ps1 "BEFORE:" ":AFTER" && + printf "%s" "$PS1" >"$actual" + ) && + test_cmp expected "$actual" +' + test_done -- cgit v1.2.3 From f3bd62d02ff189c42d404f9a0b347499e016cc23 Mon Sep 17 00:00:00 2001 From: "Eduardo R. D'Avila" Date: Wed, 26 Jun 2013 00:05:15 -0300 Subject: t9903: remove redundant tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After refactoring __git_ps1_colorize_gitstring, codepaths for bash and zsh became mostly common and tests for bash and zsh became redundant. Remove tests for zsh. Keep one minimal test that stress the difference in codepaths for bash and zsh. Suggested-by: SZEDER Gábor Signed-off-by: Eduardo R. D'Avila Signed-off-by: Junio C Hamano --- t/t9903-bash-prompt.sh | 115 +------------------------------------------------ 1 file changed, 1 insertion(+), 114 deletions(-) (limited to 't') diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index 6a88778fe6..f250dfc55a 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -665,7 +665,7 @@ test_expect_success 'prompt - bash color pc mode - untracked files status indica test_cmp expected "$actual" ' -test_expect_success 'prompt - zsh color pc mode - branch name' ' +test_expect_success 'prompt - zsh color pc mode' ' printf "BEFORE: (%%F{green}master%%f%%f):AFTER" >expected && ( ZSH_VERSION=5.0.0 && @@ -676,117 +676,4 @@ test_expect_success 'prompt - zsh color pc mode - branch name' ' test_cmp expected "$actual" ' -test_expect_success 'prompt - zsh color pc mode - detached head' ' - printf "BEFORE: (%%F{red}(%s...)%%f%%f):AFTER" $(git log -1 --format="%h" b1^) >expected && - git checkout b1^ && - test_when_finished "git checkout master" && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWCOLORHINTS=y && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - -test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty worktree' ' - printf "BEFORE: (%%F{green}master%%f %%F{red}*%%f):AFTER" >expected && - echo "dirty" >file && - test_when_finished "git reset --hard" && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWDIRTYSTATE=y && - GIT_PS1_SHOWCOLORHINTS=y && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - -test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index' ' - printf "BEFORE: (%%F{green}master%%f %%F{green}+%%f):AFTER" >expected && - echo "dirty" >file && - test_when_finished "git reset --hard" && - git add -u && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWDIRTYSTATE=y && - GIT_PS1_SHOWCOLORHINTS=y && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - -test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index and worktree' ' - printf "BEFORE: (%%F{green}master%%f %%F{red}*%%F{green}+%%f):AFTER" >expected && - echo "dirty index" >file && - test_when_finished "git reset --hard" && - git add -u && - echo "dirty worktree" >file && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWCOLORHINTS=y && - GIT_PS1_SHOWDIRTYSTATE=y && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - -test_expect_success 'prompt - zsh color pc mode - dirty status indicator - before root commit' ' - printf "BEFORE: (%%F{green}master%%f %%F{green}#%%f):AFTER" >expected && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWDIRTYSTATE=y && - GIT_PS1_SHOWCOLORHINTS=y && - cd otherrepo && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - -test_expect_success 'prompt - zsh color pc mode - inside .git directory' ' - printf "BEFORE: (%%F{green}GIT_DIR!%%f%%f):AFTER" >expected && - echo "dirty" >file && - test_when_finished "git reset --hard" && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWDIRTYSTATE=y && - GIT_PS1_SHOWCOLORHINTS=y && - cd .git && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - -test_expect_success 'prompt - zsh color pc mode - stash status indicator' ' - printf "BEFORE: (%%F{green}master%%f %%F{blue}$%%f):AFTER" >expected && - echo 2 >file && - git stash && - test_when_finished "git stash drop" && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWSTASHSTATE=y && - GIT_PS1_SHOWCOLORHINTS=y && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - -test_expect_success 'prompt - zsh color pc mode - untracked files status indicator' ' - printf "BEFORE: (%%F{green}master%%f %%F{red}%%%%%%f):AFTER" >expected && - ( - ZSH_VERSION=5.0.0 && - GIT_PS1_SHOWUNTRACKEDFILES=y && - GIT_PS1_SHOWCOLORHINTS=y && - __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" - ) && - test_cmp expected "$actual" -' - test_done -- cgit v1.2.3 From 15981f4eec9c6a7c12b9c0fbe98e68228c46edb7 Mon Sep 17 00:00:00 2001 From: "Eduardo R. D'Avila" Date: Wed, 26 Jun 2013 00:05:16 -0300 Subject: git-prompt.sh: do not print duplicate clean color code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not print a duplicate clean color code when there is no other indicators other than the current branch in colored prompt. Acked-by: SZEDER Gábor Signed-off-by: Eduardo R. D'Avila Signed-off-by: Junio C Hamano --- t/t9903-bash-prompt.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 't') diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index f250dfc55a..5cd138ed9a 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -551,7 +551,7 @@ test_expect_success 'prompt - pc mode' ' ' test_expect_success 'prompt - bash color pc mode - branch name' ' - printf "BEFORE: (${c_green}master${c_clear}${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}master${c_clear}):AFTER" >expected && ( GIT_PS1_SHOWCOLORHINTS=y && __git_ps1 "BEFORE:" ":AFTER" >"$actual" @@ -561,7 +561,7 @@ test_expect_success 'prompt - bash color pc mode - branch name' ' ' test_expect_success 'prompt - bash color pc mode - detached head' ' - printf "BEFORE: (${c_red}(%s...)${c_clear}${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected && + printf "BEFORE: (${c_red}(%s...)${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected && git checkout b1^ && test_when_finished "git checkout master" && ( @@ -627,7 +627,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - befo ' test_expect_success 'prompt - bash color pc mode - inside .git directory' ' - printf "BEFORE: (${c_green}GIT_DIR!${c_clear}${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}GIT_DIR!${c_clear}):AFTER" >expected && echo "dirty" >file && test_when_finished "git reset --hard" && ( @@ -666,7 +666,7 @@ test_expect_success 'prompt - bash color pc mode - untracked files status indica ' test_expect_success 'prompt - zsh color pc mode' ' - printf "BEFORE: (%%F{green}master%%f%%f):AFTER" >expected && + printf "BEFORE: (%%F{green}master%%f):AFTER" >expected && ( ZSH_VERSION=5.0.0 && GIT_PS1_SHOWCOLORHINTS=y && -- cgit v1.2.3