On Fri, Aug 30, 2013 at 2:12 PM, Brad King <brad.k...@kitware.com> wrote:
> Extend t/t1400-update-ref.sh to cover cases using the --stdin option.
>
> Signed-off-by: Brad King <brad.k...@kitware.com>
> ---
>  t/t1400-update-ref.sh |  206 
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 206 insertions(+)
>
> diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
> index e415ee0..9fd03fc 100755
> --- a/t/t1400-update-ref.sh
> +++ b/t/t1400-update-ref.sh
> @@ -302,4 +302,210 @@ test_expect_success \
>         'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
>         'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
>
> +a=refs/heads/a
> +b=refs/heads/b
> +c=refs/heads/c
> +z=0000000000000000000000000000000000000000
> +e="''"
> +
> +test_expect_success 'stdin works with no input' '
> +       rm -f stdin &&
> +       touch stdin &&

Unless the timestamp of 'stdin' has particular significance, modern
git tests avoid 'touch' in favor of creating the empty file like this

    >stdin &&

> +       git update-ref --stdin < stdin &&

Style: Git test scripts omit whitespace following <, >, <<, and >>.

> +       git rev-parse --verify -q $m
> +'
> +
> +test_expect_success 'stdin fails with bad line lines' '
> +       echo " " > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: no ref on line:  " err &&
> +       echo "--" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: no ref on line: --" err &&
> +       echo "--bad-option" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: unknown option --bad-option" err &&
> +       echo "-\'"'"' $a $m" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: unknown option -'"'"'" err &&
> +       echo "~a $m" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: invalid ref format on line: ~a $m" err &&
> +       echo "$a '"'"'master" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: unterminated single-quote: '"'"'master" err &&
> +       echo "$a \master" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: unquoted backslash not escaping single-quote: 
> \\\\master" err &&
> +       echo "$a $m $m $m" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: too many arguments on line: $a $m $m $m" err &&
> +       echo "$a" > stdin &&
> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: missing new value on line: $a" err
> +'

Despite the semantic relationship between all these cases, if there is
a regression in one case, the person reading the verbose output has to
study it carefully to determine the offending case. If you decompose
this monolith so that each case is in its own test_expect_success,
then the regressed case becomes immediately obvious.

> +test_expect_success 'stdin fails with duplicate refs' '
> +       echo "$a $m" > stdin &&
> +       echo "$b $m" >> stdin &&
> +       echo "$a $m" >> stdin &&

These multi-line preparations of 'stdin' might be more readable with a heredoc:

    cat >stdin <<-EOF &&
    $a $m
    $b $m
    $a $m
    EOF

> +       test_must_fail git update-ref --stdin < stdin 2> err &&
> +       grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
> +'
--
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

Reply via email to