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

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

 



On Mon, Mar 9, 2015 at 4:46 PM, Sundararajan R <dyoucme@xxxxxxxxx> wrote:
> As you had suggested @Junio, I have added the required tests.
> Please let me know if there is something is I should add.
>
> Signed-off-by: Sundararajan R <dyoucme@xxxxxxxxx>
> Thanks-to: Junio C Hamano
> ---
> I have added 6 tests to check for the following cases:
> git reset - with no @{-1}
> git reset - with no @{-1} and file named -
> git reset - with @{-1} and file named @{-1}
> git reset - with @{-1} and file named -
> git reset - with @{-1} and file named @{-1} and -
> git reset - with @{-1} and no file named - or @{-1}
> The 1st test with no previous branch results in the error
> The 2nd,3rd,4th and 5th result in the ambiguous argument error
> The 6th test has - working like @{-1}

See my review of patch 1 regarding where to place commentary, how to
construct a good commit message, and how to formulate the trailers
(Helped-by:, Signed-off-by:).

> diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
> index 98bcfe2..a670938 100755
> --- a/t/t7102-reset.sh
> +++ b/t/t7102-reset.sh
> @@ -568,4 +568,111 @@ test_expect_success 'reset --mixed sets up work tree' '
>         test_cmp expect actual
>  '
>
> +test_expect_success 'reset - with no @{-1}' '
> +       git init new --quiet &&

Why --quiet?

> +       cd new &&

As Torsten mentioned already, wrap a subshell (via '(' and ')') around
the 'cd' and commands which should be invoked within the subdirectory.
Doing so ensures that tests following this one aren't incorrectly run
within the working directory set by this test.

> +       test_must_fail git reset - >actual &&
> +       touch expect &&

Unless the timestamp of 'expect' is significant, don't use "touch" to
create the file. Instead, just say ">expect &&" on a line by itself.

> +       test_cmp expect actual

What is the intention here? Rather than git-reset's stderr, you've
captured stdout, which doesn't seem particularly interesting.

> +'
> +
> +rm -rf new

This is ineffective since the test just above left you inside the
'new' subdirectory, and there is no 'new' subdirectory within that one
to clean up.

> +cat >expect <<EOF
> +fatal: ambiguous argument '-': both revision and filename
> +Use ./- for file named -
> +Use '--' to separate paths from revisions, like this:
> +'git <command> [<revision>...] -- [<file>...]'
> +EOF

Reproducing the error message verbatim is fragile. Any minor change to
the text will cause the test to fail. Generally speaking, it is
sufficient just to use test_must_fail to ensure that the command fails
as expected. If you feel particularly strongly about checking that the
correct error condition occurred, then just check the error output
using test_i18ngrep() for a significant phrase, such as "ambiguous
argument".

> +test_expect_success 'reset - with no @{-1} and file named -' '
> +       git init new --quiet &&
> +       cd new &&
> +       echo "Hello" > - &&

Drop the space after the redirection operator.

> +       git add -

Broken &&-chain.

> +       test_must_fail git reset - 2>actual &&
> +       test_cmp ../expect actual
> +'
> +
> +cd ..

This is problematic. If the preceding test fails in git-init, before
the "cd new", then this "cd .." will change to the wrong place. Use of
a subshell, as explained above, avoids such problems.

> +rm -rf new
> +
> +cat >expect <<EOF
> +fatal: ambiguous argument '@{-1}': both revision and filename
> +Use '--' to separate paths from revisions, like this:
> +'git <command> [<revision>...] -- [<file>...]'
> +EOF

Rather than doing cleanup ("rm") and preparation ("cat >expect") at
the top-level, place them within the test which requires them, thus
making each test self-contained.

I'll stop reviewing here since the above comments also apply to the
rest of the tests.

> +test_expect_success 'reset - with @{-1} and file named @{-1}' '
> +       git init new --quiet &&
> +       cd new &&
> +       echo "Hello" >@{-1} &&
> +       git add @{-1} &&
> +       git commit -m "first_commit" &&
> +       git checkout -b new_branch &&
> +       touch @{-1} &&
> +       git add @{-1} &&
> +       test_must_fail git reset - 2>actual &&
> +       test_cmp ../expect actual
> +'
> +
> +cd ..
> +rm -rf new
> +
> +cat >expect <<EOF
> +fatal: ambiguous argument '-': both revision and filename
> +Use ./- for file named -
> +Use '--' to separate paths from revisions, like this:
> +'git <command> [<revision>...] -- [<file>...]'
> +EOF
> +
> +test_expect_success 'reset - with @{-1} and file named - ' '
> +       git init new --quiet &&
> +       cd new &&
> +       echo "Hello" > - &&
> +       git add - &&
> +       git commit -m "first_commit" &&
> +       git checkout -b new_branch &&
> +       touch - &&
> +       git add - &&
> +       test_must_fail git reset - 2>actual &&
> +       test_cmp ../expect actual
> +'
> +
> +cd ..
> +rm -rf new
> +
> +test_expect_success 'reset - with @{-1} and file named @{-1} and - ' '
> +       git init new --quiet &&
> +       cd new &&
> +       echo "Hello" > - &&
> +       git add - &&
> +       git commit -m "first_commit" &&
> +       git checkout -b new_branch
> +       echo "Hello" >@{-1} &&
> +       git add @{-1} &&
> +       test_must_fail git reset - 2>actual &&
> +       test_cmp ../expect actual
> +'
> +
> +cd ..
> +rm -rf new
> +
> +test_expect_success 'reset - with @{-1} and no file named - or @{-1} ' '
> +       git init new --quiet &&
> +       cd new &&
> +       echo "Hello" >new_file &&
> +       git add new_file &&
> +       git commit -m "first_commit" &&
> +       git checkout -b new_branch &&
> +       echo "Hey" >new_file &&
> +       git add new_file &&
> +       git reset - &&
> +       git status -uno >file1 &&
> +       git add new_file &&
> +       git reset @{-1} &&
> +       git status -uno >file2 &&
> +       test_cmp file1 file2
> +'
> +
>  test_done
> --
> 2.1.0
--
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]