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

2013-06-24 Thread SZEDER Gábor
On Sat, Jun 22, 2013 at 01:32:38PM -0300, Eduardo D'Avila wrote:
> These tests where important to make sure that I wouldn't break anything during
> the refactorization. Having them pass before *and* after refactorization
> guarantees that nothing was broken (except for some subtle case that might 
> have
> not be included in the tests).
> 
> However, I agree that they became redundant.
> 
> Would it make sense to include a patch that only removes the zsh
> tests, after the
> refactorization?

That would be fine with me.


Thanks,
Gábor

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-06-23 Thread Junio C Hamano
"Eduardo D'Avila"  writes:

> However, I agree that they became redundant.
>
> Would it make sense to include a patch that only removes the zsh
> tests, after the refactorization?

I think that would be a sensible thing to do.

In any case, Szeder seems to be giving a good guidance on patches in
the completion area (not just this series), and completion is not
something I am deeply interested in, so I'll watch from the sidelines
and wait until you two to figure out the best solution ;-)

Thanks for working on this topic.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-06-22 Thread Eduardo D'Avila
2013/6/22 SZEDER Gábor :
> On Thu, Jun 20, 2013 at 11:25:26PM -0300, Eduardo R. D'Avila wrote:
>> 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 
>
> I doubt the value of separate tests for zsh.  They might make sense as
> long as there are different code paths for doing coloring for the two
> shells, but after your refactorization in 2/4 there is only one common
> block of if statements, which is already thoroughly excercised by your
> tests for bash, making the separate tests for zsh redundant.

These tests where important to make sure that I wouldn't break anything during
the refactorization. Having them pass before *and* after refactorization
guarantees that nothing was broken (except for some subtle case that might have
not be included in the tests).

However, I agree that they became redundant.

Would it make sense to include a patch that only removes the zsh
tests, after the
refactorization? I'm considering that *1* simple zsh test must be kept during
this removal, to make sure the code path for zsh is run.


Eduardo
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-06-22 Thread SZEDER Gábor
Hi,

On Thu, Jun 20, 2013 at 11:25:26PM -0300, Eduardo R. D'Avila wrote:
> 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 

I doubt the value of separate tests for zsh.  They might make sense as
long as there are different code paths for doing coloring for the two
shells, but after your refactorization in 2/4 there is only one common
block of if statements, which is already thoroughly excercised by your
tests for bash, making the separate tests for zsh redundant.


Gábor

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] t9903: add tests for git-prompt pcmode

2013-06-20 Thread Eduardo R. D'Avila
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 
---
254 0   t/t9903-bash-prompt.sh
 t/t9903-bash-prompt.sh | 254 +
 1 file changed, 254 insertions(+)

diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 15521cc..6a88778 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_gree