Re: [PATCH v3 2/2] Added tests for reset -

2015-03-12 Thread Eric Sunshine
On Tue, Mar 10, 2015 at 1:52 PM, Sudhanshu Shekhar
sudshekha...@gmail.com wrote:
 On Tue, Mar 10, 2015 at 6:56 PM, Matthieu Moy
 matthieu@grenoble-inp.fr wrote:
 Sudhanshu Shekhar sudshekha...@gmail.com writes:
 +test_expect_success 'reset - in the presence of file named - with previous 
 branch' '
 + echo Unstaged changes after reset: expect 
 + echo M - expect 
 + echo M 1 expect 

 Here and elsewhere: why not

 cat expect -EOF
 Unstaged changes after reset:
 M -
 M 1

 ?
 I was confused whether to use cat or echo. I thought using cat will
 disrupt the indentation as the EOF needs to be on a single line. This
 is why I chose echo. Please let me know your thoughts on this.

Here-docs are easier to compose and read than individual 'echo'
statements for multi-line content.

The '-' in front of EOF allows you to indent the entire body. Even
better, use -\EOF to signify that you don't expect any interpolation
to occur within the body.
--
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 v3 2/2] Added tests for reset -

2015-03-10 Thread Sudhanshu Shekhar
Added the following test cases:
1) Confirm error message when git reset is used with no previous branch
2) Confirm git reset - works like git reset @{-1}
3) Confirm - is always treated as a commit unless the -- file option
is specified
4) Confirm git reset - works normally even when a file named @{-1} is
present

Helped-by: David Aguilar dav...@gmail.com
Signed-off-by: Sudhanshu Shekhar sudshekha...@gmail.com
---
I have tried to keep each test self sufficient. Please let me know if any 
changes are required.
Thank you!

 t/t7102-reset.sh | 139 +++
 1 file changed, 139 insertions(+)

diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 98bcfe2..0faf241 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -568,4 +568,143 @@ test_expect_success 'reset --mixed sets up work tree' '
test_cmp expect actual
 '
 
+test_expect_success 'reset - with no previous branch' '
+   git init no_previous 
+   (
+   cd no_previous 
+   test_must_fail git reset - 2output
+   ) 
+   test_i18ngrep bad flag no_previous/output
+'
+
+test_expect_success 'reset - while having file named - and no previous branch' 
'
+   git init no_previous 
+   (
+   cd no_previous 
+   ./- 
+   test_must_fail git reset - 2output
+   ) 
+   test_i18ngrep bad flag no_previous/output
+'
+
+
+test_expect_success 'reset - in the presence of file named - with previous 
branch' '
+   echo Unstaged changes after reset: expect 
+   echo M - expect 
+   echo M 1 expect 
+   git init no_previous 
+   (
+   cd no_previous 
+   ./- 
+   1 
+   git add 1 - 
+   git commit -m add base files 
+   git checkout -b new_branch 
+   echo random ./- 
+   echo wow 1 
+   git add 1 - 
+   git reset - ../output
+   ) 
+   rm -rf no_previous 
+   test_cmp output expect
+'
+test_expect_success 'reset - in the presence of file named - with -- option' '
+   echo Unstaged changes after reset: expect 
+   echo M - expect 
+   echo M 1 expect 
+   git init no_previous 
+   (
+   cd no_previous 
+   ./- 
+   1 
+   git add 1 - 
+   git commit -m add base files 
+   git checkout -b new_branch 
+   echo random ./- 
+   echo wow 1 
+   git add 1 - 
+   git reset - -- ../output
+   ) 
+   rm -rf no_previous 
+   test_cmp output expect
+'
+
+test_expect_success 'reset - in the presence of file named - with -- file 
option' '
+   echo Unstaged changes after reset: expect 
+   echo M - expect 
+   git init no_previous 
+   (
+   cd no_previous 
+   ./- 
+   1 
+   git add 1 - 
+   git commit -m add base files 
+   git checkout -b new_branch 
+   echo random ./- 
+   echo wow 1 
+   git add 1 - 
+   git reset -- - ../output
+   ) 
+   rm -rf no_previous
+   test_cmp output expect
+'
+test_expect_success 'reset - in the presence of file named - with both pre and 
post -- option' '
+   echo Unstaged changes after reset: expect 
+   echo M - expect 
+   git init no_previous 
+   (
+   cd no_previous 
+   ./- 
+   1 
+   git add 1 - 
+   git commit -m add base files 
+   git checkout -b new_branch 
+   echo random ./- 
+   echo wow 1 
+   git add 1 - 
+   git reset - -- - ../output
+   ) 
+   rm -rf no_previous
+   test_cmp output expect
+'
+
+test_expect_success 'reset - works same as reset @{-1}' '
+   git init no_previous 
+   (
+   cd no_previous 
+   echo random random 
+   git add random 
+   git commit -m base commit 
+   git checkout -b temp 
+   echo new-file new-file 
+   git add new-file 
+   git commit -m added new-file 
+   git reset - 
+   git status --porcelain ../first 
+   git add new-file 
+   git commit -m added new-file 
+   git reset @{-1} 
+   git status --porcelain ../second
+   ) 
+   test_cmp first second
+'
+
+test_expect_success 'reset - with file named @{-1}' '
+   echo Unstaged changes after reset: expect 
+   echo M @{-1} expect 
+   git init no_previous 
+   (
+   cd no_previous 
+   echo random ./@{-1} 
+   git add ./@{-1} 
+   git commit -m base commit 
+   git checkout -b new_branch 
+   echo additional stuff ./@{-1} 
+

Re: [PATCH v3 2/2] Added tests for reset -

2015-03-10 Thread Matthieu Moy
Sudhanshu Shekhar sudshekha...@gmail.com writes:

 +test_expect_success 'reset - while having file named - and no previous 
 branch' '

I like having the expected behavior in the test name too. e.g. add
fails at the end of the sentence.

 +test_expect_success 'reset - in the presence of file named - with previous 
 branch' '
 + echo Unstaged changes after reset: expect 
 + echo M - expect 
 + echo M 1 expect 

Here and elsewhere: why not

cat expect -EOF
Unstaged changes after reset:
M -
M 1

?

 + rm -rf no_previous 

That would be best done in a test_when_finished, so that the directory
is removed regardless of whether the test failed before this line or
not.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
--
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 v3 2/2] Added tests for reset -

2015-03-10 Thread Sudhanshu Shekhar
Hi,

On Tue, Mar 10, 2015 at 6:56 PM, Matthieu Moy
matthieu@grenoble-inp.fr wrote:
 Sudhanshu Shekhar sudshekha...@gmail.com writes:

 +test_expect_success 'reset - while having file named - and no previous 
 branch' '

 I like having the expected behavior in the test name too. e.g. add
 fails at the end of the sentence.

Sure. I will update this in the next patch.

 +test_expect_success 'reset - in the presence of file named - with previous 
 branch' '
 + echo Unstaged changes after reset: expect 
 + echo M - expect 
 + echo M 1 expect 

 Here and elsewhere: why not

 cat expect -EOF
 Unstaged changes after reset:
 M -
 M 1

 ?

I was confused whether to use cat or echo. I thought using cat will
disrupt the indentation as the EOF needs to be on a single line. This
is why I chose echo. Please let me know your thoughts on this.

 + rm -rf no_previous 

 That would be best done in a test_when_finished, so that the directory
 is removed regardless of whether the test failed before this line or
 not.
Thanks for pointing this out. I will update this accordingly.

 --
 Matthieu Moy
 http://www-verimag.imag.fr/~moy/

Regards,
Sudhanshu
--
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 v3 2/2] Added tests for reset -

2015-03-10 Thread Eric Sunshine
On Tue, Mar 10, 2015 at 6:52 AM, Sudhanshu Shekhar
sudshekha...@gmail.com wrote:
 Added tests for reset -

Mention the area of the project you are changing, followed by a colon,
followed by a short summary of the change. Drop capitalization. Write
in imperative mood.

t7102: add 'reset -' tests

 Added the following test cases:

Imperative mood: Add test cases:

 1) Confirm error message when git reset is used with no previous branch
 2) Confirm git reset - works like git reset @{-1}
 3) Confirm - is always treated as a commit unless the -- file option
 is specified
 4) Confirm git reset - works normally even when a file named @{-1} is
 present

 Helped-by: David Aguilar dav...@gmail.com
 Signed-off-by: Sudhanshu Shekhar sudshekha...@gmail.com
 ---
 diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
 index 98bcfe2..0faf241 100755
 --- a/t/t7102-reset.sh
 +++ b/t/t7102-reset.sh
 @@ -568,4 +568,143 @@ test_expect_success 'reset --mixed sets up work tree' '
 test_cmp expect actual
  '

 +test_expect_success 'reset - in the presence of file named - with previous 
 branch' '
 +   echo Unstaged changes after reset: expect 
 +   echo M - expect 
 +   echo M 1 expect 

Mentioned by Matthieu: Use cat -\EOF.

 +   git init no_previous 
 +   (
 +   cd no_previous 
 +   ./- 

Unnecessarily complex ./- when - will suffice.

 +   1 
 +   git add 1 - 
 +   git commit -m add base files 
 +   git checkout -b new_branch 
 +   echo random ./- 
 +   echo wow 1 
 +   git add 1 - 
 +   git reset - ../output

Since you will be comparing this output with expected output, it is
customary to name this file actual.

 +   ) 
 +   rm -rf no_previous 

Mentioned by Matthieu: Use test_when_finished(). You want this cleanup
action invoked even if any part of the test fails, so register it as
early as possible for it to be effective; either just before or after
git-init.

 +   test_cmp output expect

When test_cmp() detects a difference in the expected and actual
output, it dumps the difference (in 'diff' format) as debugging
output. It's easier to read 'diff' output, and matches our
expectations more closely, if 'expect' is mentioned before 'actual',
so:

test_cmp expect actual

 +'
 +test_expect_success 'reset - in the presence of file named - with -- file 
 option' '
 +   echo Unstaged changes after reset: expect 
 +   echo M - expect 
 +   git init no_previous 
 +   (
 +   cd no_previous 
 +   ./- 
 +   1 
 +   git add 1 - 
 +   git commit -m add base files 
 +   git checkout -b new_branch 
 +   echo random ./- 
 +   echo wow 1 
 +   git add 1 - 
 +   git reset -- - ../output
 +   ) 
 +   rm -rf no_previous

Broken -chain.

 +   test_cmp output expect
 +'
 +test_expect_success 'reset - in the presence of file named - with both pre 
 and post -- option' '
 +   echo Unstaged changes after reset: expect 
 +   echo M - expect 
 +   git init no_previous 
 +   (
 +   cd no_previous 
 +   ./- 
 +   1 
 +   git add 1 - 
 +   git commit -m add base files 
 +   git checkout -b new_branch 
 +   echo random ./- 
 +   echo wow 1 
 +   git add 1 - 
 +   git reset - -- - ../output
 +   ) 
 +   rm -rf no_previous

Broken -chain.

 +   test_cmp output expect
 +'
 +
 +test_expect_success 'reset - works same as reset @{-1}' '
 +   git init no_previous 
 +   (
 +   cd no_previous 
 +   echo random random 
 +   git add random 
 +   git commit -m base commit 
 +   git checkout -b temp 
 +   echo new-file new-file 
 +   git add new-file 
 +   git commit -m added new-file 
 +   git reset - 
 +   git status --porcelain ../first 
 +   git add new-file 
 +   git commit -m added new-file 
 +   git reset @{-1} 
 +   git status --porcelain ../second
 +   ) 

In other tests, you performed rm -rf no_previous  cleanup at this
point, but it's missing here.

 +   test_cmp first second
 +'
 +
 +test_expect_success 'reset - with file named @{-1}' '
 +   echo Unstaged changes after reset: expect 
 +   echo M @{-1} expect 
 +   git init no_previous 
 +   (
 +   cd no_previous 
 +   echo random ./@{-1} 
 +   git add ./@{-1} 
 +   git commit -m base commit 
 +   git checkout -b new_branch 
 +   echo additional stuff ./@{-1} 
 +   git add ./@{-1} 
 +   git reset - ../output
 +   ) 
 +   rm -rf