Re: [PATCH/RFC 1/3] t9903: add tests for git-prompt pcmode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Eduardo R. D'Avila" <erdavila@xxxxxxxxx> writes:

> 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 <erdavila@xxxxxxxxx>
> ---
> 250	0	t/t9903-bash-prompt.sh
>  t/t9903-bash-prompt.sh | 250 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 250 insertions(+)
>
> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
> index 15521cc..ebca9de 100755
> --- a/t/t9903-bash-prompt.sh
> +++ b/t/t9903-bash-prompt.sh
> @@ -535,4 +535,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 &&

Style; redirected filename immediately follows the redirection
operator, i.e.

	command >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: (\\\[\\\e[32m\\\]master\\\[\\\e[0m\\\]\\\[\\\e[0m\\\]):AFTER" > expected &&

With these escape codes that are hardcoded everywhere, the tests
look pretty much unreadable.  Could they be improved to something
like this (two ${reset} and some other characters may want to be
there):

	printf "BEFORE: (${C_green}master${C_reset}):AFTER"

by adding variable definitions early in this test file?

[the rest of the original left unsnipped for reference; my comments
end here]

> +	(
> +		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: (\\\[\\\e[31m\\\](%s...)\\\[\\\e[0m\\\]\\\[\\\e[0m\\\]):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: (\\\[\\\e[32m\\\]master\\\[\\\e[0m\\\] \\\[\\\e[31m\\\]*\\\[\\\e[0m\\\]):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: (\\\[\\\e[32m\\\]master\\\[\\\e[0m\\\] \\\[\\\e[32m\\\]+\\\[\\\e[0m\\\]):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: (\\\[\\\e[32m\\\]master\\\[\\\e[0m\\\] \\\[\\\e[31m\\\]*\\\[\\\e[32m\\\]+\\\[\\\e[0m\\\]):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: (\\\[\\\e[32m\\\]master\\\[\\\e[0m\\\] \\\[\\\e[32m\\\]#\\\[\\\e[0m\\\]):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: (\\\[\\\e[32m\\\]GIT_DIR!\\\[\\\e[0m\\\]\\\[\\\e[0m\\\]):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: (\\\[\\\e[32m\\\]master\\\[\\\e[0m\\\] \\\[\\\e[1;34m\\\]$\\\[\\\e[0m\\\]):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: (\\\[\\\e[32m\\\]master\\\[\\\e[0m\\\] \\\[\\\e[31m\\\]%%\\\[\\\e[0m\\\]):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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]