Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 1572e18

Browse files
erdavilagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f3a412 commit 1572e18

File tree

1 file changed

+254
-0
lines changed

1 file changed

+254
-0
lines changed

t/t9903-bash-prompt.sh

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ test_description='test git-specific bash prompt functions'
1010
. "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
1111

1212
actual="$TRASH_DIRECTORY/actual"
13+
c_red='\\[\\e[31m\\]'
14+
c_green='\\[\\e[32m\\]'
15+
c_lblue='\\[\\e[1;34m\\]'
16+
c_clear='\\[\\e[0m\\]'
1317

1418
test_expect_success 'setup for prompt tests' '
1519
mkdir -p subdir/subsubdir &&
@@ -535,4 +539,254 @@ test_expect_success 'prompt - format string starting with dash' '
535539
test_cmp expected "$actual"
536540
'
537541

542+
test_expect_success 'prompt - pc mode' '
543+
printf "BEFORE: (master):AFTER" >expected &&
544+
printf "" >expected_output &&
545+
(
546+
__git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
547+
test_cmp expected_output "$actual" &&
548+
printf "%s" "$PS1" >"$actual"
549+
) &&
550+
test_cmp expected "$actual"
551+
'
552+
553+
test_expect_success 'prompt - bash color pc mode - branch name' '
554+
printf "BEFORE: (${c_green}master${c_clear}${c_clear}):AFTER" >expected &&
555+
(
556+
GIT_PS1_SHOWCOLORHINTS=y &&
557+
__git_ps1 "BEFORE:" ":AFTER" >"$actual"
558+
printf "%s" "$PS1" >"$actual"
559+
) &&
560+
test_cmp expected "$actual"
561+
'
562+
563+
test_expect_success 'prompt - bash color pc mode - detached head' '
564+
printf "BEFORE: (${c_red}(%s...)${c_clear}${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected &&
565+
git checkout b1^ &&
566+
test_when_finished "git checkout master" &&
567+
(
568+
GIT_PS1_SHOWCOLORHINTS=y &&
569+
__git_ps1 "BEFORE:" ":AFTER" &&
570+
printf "%s" "$PS1" >"$actual"
571+
) &&
572+
test_cmp expected "$actual"
573+
'
574+
575+
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '
576+
printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_clear}):AFTER" >expected &&
577+
echo "dirty" >file &&
578+
test_when_finished "git reset --hard" &&
579+
(
580+
GIT_PS1_SHOWDIRTYSTATE=y &&
581+
GIT_PS1_SHOWCOLORHINTS=y &&
582+
__git_ps1 "BEFORE:" ":AFTER" &&
583+
printf "%s" "$PS1" >"$actual"
584+
) &&
585+
test_cmp expected "$actual"
586+
'
587+
588+
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '
589+
printf "BEFORE: (${c_green}master${c_clear} ${c_green}+${c_clear}):AFTER" >expected &&
590+
echo "dirty" >file &&
591+
test_when_finished "git reset --hard" &&
592+
git add -u &&
593+
(
594+
GIT_PS1_SHOWDIRTYSTATE=y &&
595+
GIT_PS1_SHOWCOLORHINTS=y &&
596+
__git_ps1 "BEFORE:" ":AFTER" &&
597+
printf "%s" "$PS1" >"$actual"
598+
) &&
599+
test_cmp expected "$actual"
600+
'
601+
602+
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '
603+
printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER" >expected &&
604+
echo "dirty index" >file &&
605+
test_when_finished "git reset --hard" &&
606+
git add -u &&
607+
echo "dirty worktree" >file &&
608+
(
609+
GIT_PS1_SHOWCOLORHINTS=y &&
610+
GIT_PS1_SHOWDIRTYSTATE=y &&
611+
__git_ps1 "BEFORE:" ":AFTER" &&
612+
printf "%s" "$PS1" >"$actual"
613+
) &&
614+
test_cmp expected "$actual"
615+
'
616+
617+
test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '
618+
printf "BEFORE: (${c_green}master${c_clear} ${c_green}#${c_clear}):AFTER" >expected &&
619+
(
620+
GIT_PS1_SHOWDIRTYSTATE=y &&
621+
GIT_PS1_SHOWCOLORHINTS=y &&
622+
cd otherrepo &&
623+
__git_ps1 "BEFORE:" ":AFTER" &&
624+
printf "%s" "$PS1" >"$actual"
625+
) &&
626+
test_cmp expected "$actual"
627+
'
628+
629+
test_expect_success 'prompt - bash color pc mode - inside .git directory' '
630+
printf "BEFORE: (${c_green}GIT_DIR!${c_clear}${c_clear}):AFTER" >expected &&
631+
echo "dirty" >file &&
632+
test_when_finished "git reset --hard" &&
633+
(
634+
GIT_PS1_SHOWDIRTYSTATE=y &&
635+
GIT_PS1_SHOWCOLORHINTS=y &&
636+
cd .git &&
637+
__git_ps1 "BEFORE:" ":AFTER" &&
638+
printf "%s" "$PS1" >"$actual"
639+
) &&
640+
test_cmp expected "$actual"
641+
'
642+
643+
test_expect_success 'prompt - bash color pc mode - stash status indicator' '
644+
printf "BEFORE: (${c_green}master${c_clear} ${c_lblue}\$${c_clear}):AFTER" >expected &&
645+
echo 2 >file &&
646+
git stash &&
647+
test_when_finished "git stash drop" &&
648+
(
649+
GIT_PS1_SHOWSTASHSTATE=y &&
650+
GIT_PS1_SHOWCOLORHINTS=y &&
651+
__git_ps1 "BEFORE:" ":AFTER" &&
652+
printf "%s" "$PS1" >"$actual"
653+
) &&
654+
test_cmp expected "$actual"
655+
'
656+
657+
test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '
658+
printf "BEFORE: (${c_green}master${c_clear} ${c_red}%%${c_clear}):AFTER" >expected &&
659+
(
660+
GIT_PS1_SHOWUNTRACKEDFILES=y &&
661+
GIT_PS1_SHOWCOLORHINTS=y &&
662+
__git_ps1 "BEFORE:" ":AFTER" &&
663+
printf "%s" "$PS1" >"$actual"
664+
) &&
665+
test_cmp expected "$actual"
666+
'
667+
668+
test_expect_success 'prompt - zsh color pc mode - branch name' '
669+
printf "BEFORE: (%%F{green}master%%f%%f):AFTER" >expected &&
670+
(
671+
ZSH_VERSION=5.0.0 &&
672+
GIT_PS1_SHOWCOLORHINTS=y &&
673+
__git_ps1 "BEFORE:" ":AFTER" >"$actual"
674+
printf "%s" "$PS1" >"$actual"
675+
) &&
676+
test_cmp expected "$actual"
677+
'
678+
679+
test_expect_success 'prompt - zsh color pc mode - detached head' '
680+
printf "BEFORE: (%%F{red}(%s...)%%f%%f):AFTER" $(git log -1 --format="%h" b1^) >expected &&
681+
git checkout b1^ &&
682+
test_when_finished "git checkout master" &&
683+
(
684+
ZSH_VERSION=5.0.0 &&
685+
GIT_PS1_SHOWCOLORHINTS=y &&
686+
__git_ps1 "BEFORE:" ":AFTER" &&
687+
printf "%s" "$PS1" >"$actual"
688+
) &&
689+
test_cmp expected "$actual"
690+
'
691+
692+
test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty worktree' '
693+
printf "BEFORE: (%%F{green}master%%f %%F{red}*%%f):AFTER" >expected &&
694+
echo "dirty" >file &&
695+
test_when_finished "git reset --hard" &&
696+
(
697+
ZSH_VERSION=5.0.0 &&
698+
GIT_PS1_SHOWDIRTYSTATE=y &&
699+
GIT_PS1_SHOWCOLORHINTS=y &&
700+
__git_ps1 "BEFORE:" ":AFTER" &&
701+
printf "%s" "$PS1" >"$actual"
702+
) &&
703+
test_cmp expected "$actual"
704+
'
705+
706+
test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index' '
707+
printf "BEFORE: (%%F{green}master%%f %%F{green}+%%f):AFTER" >expected &&
708+
echo "dirty" >file &&
709+
test_when_finished "git reset --hard" &&
710+
git add -u &&
711+
(
712+
ZSH_VERSION=5.0.0 &&
713+
GIT_PS1_SHOWDIRTYSTATE=y &&
714+
GIT_PS1_SHOWCOLORHINTS=y &&
715+
__git_ps1 "BEFORE:" ":AFTER" &&
716+
printf "%s" "$PS1" >"$actual"
717+
) &&
718+
test_cmp expected "$actual"
719+
'
720+
721+
test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index and worktree' '
722+
printf "BEFORE: (%%F{green}master%%f %%F{red}*%%F{green}+%%f):AFTER" >expected &&
723+
echo "dirty index" >file &&
724+
test_when_finished "git reset --hard" &&
725+
git add -u &&
726+
echo "dirty worktree" >file &&
727+
(
728+
ZSH_VERSION=5.0.0 &&
729+
GIT_PS1_SHOWCOLORHINTS=y &&
730+
GIT_PS1_SHOWDIRTYSTATE=y &&
731+
__git_ps1 "BEFORE:" ":AFTER" &&
732+
printf "%s" "$PS1" >"$actual"
733+
) &&
734+
test_cmp expected "$actual"
735+
'
736+
737+
test_expect_success 'prompt - zsh color pc mode - dirty status indicator - before root commit' '
738+
printf "BEFORE: (%%F{green}master%%f %%F{green}#%%f):AFTER" >expected &&
739+
(
740+
ZSH_VERSION=5.0.0 &&
741+
GIT_PS1_SHOWDIRTYSTATE=y &&
742+
GIT_PS1_SHOWCOLORHINTS=y &&
743+
cd otherrepo &&
744+
__git_ps1 "BEFORE:" ":AFTER" &&
745+
printf "%s" "$PS1" >"$actual"
746+
) &&
747+
test_cmp expected "$actual"
748+
'
749+
750+
test_expect_success 'prompt - zsh color pc mode - inside .git directory' '
751+
printf "BEFORE: (%%F{green}GIT_DIR!%%f%%f):AFTER" >expected &&
752+
echo "dirty" >file &&
753+
test_when_finished "git reset --hard" &&
754+
(
755+
ZSH_VERSION=5.0.0 &&
756+
GIT_PS1_SHOWDIRTYSTATE=y &&
757+
GIT_PS1_SHOWCOLORHINTS=y &&
758+
cd .git &&
759+
__git_ps1 "BEFORE:" ":AFTER" &&
760+
printf "%s" "$PS1" >"$actual"
761+
) &&
762+
test_cmp expected "$actual"
763+
'
764+
765+
test_expect_success 'prompt - zsh color pc mode - stash status indicator' '
766+
printf "BEFORE: (%%F{green}master%%f %%F{blue}$%%f):AFTER" >expected &&
767+
echo 2 >file &&
768+
git stash &&
769+
test_when_finished "git stash drop" &&
770+
(
771+
ZSH_VERSION=5.0.0 &&
772+
GIT_PS1_SHOWSTASHSTATE=y &&
773+
GIT_PS1_SHOWCOLORHINTS=y &&
774+
__git_ps1 "BEFORE:" ":AFTER" &&
775+
printf "%s" "$PS1" >"$actual"
776+
) &&
777+
test_cmp expected "$actual"
778+
'
779+
780+
test_expect_success 'prompt - zsh color pc mode - untracked files status indicator' '
781+
printf "BEFORE: (%%F{green}master%%f %%F{red}%%%%%%f):AFTER" >expected &&
782+
(
783+
ZSH_VERSION=5.0.0 &&
784+
GIT_PS1_SHOWUNTRACKEDFILES=y &&
785+
GIT_PS1_SHOWCOLORHINTS=y &&
786+
__git_ps1 "BEFORE:" ":AFTER" &&
787+
printf "%s" "$PS1" >"$actual"
788+
) &&
789+
test_cmp expected "$actual"
790+
'
791+
538792
test_done

0 commit comments

Comments
 (0)