Re: [PATCH v2 23/27] userdiff tests: test hunk header selection with -U0
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Feb 15, 2021, 19:09 UTC
- Message-ID
- <d0dfc18a-1f22-f4f1-bf99-6dc829f3cf04@kdbg.org>
- In-Reply-To
- <20210215154427.32693-24-avarab@gmail.com>
Am 15.02.21 um 16:44 schrieb Ævar Arnfjörð Bjarmason:
Show 8 quoted lines
> The userdiff tests have used a custom -U1 context since > f12c66b9bb (userdiff/perl: anchor "sub" and "package" patterns on the > left, 2011-05-21). Changing it to -U0 doesn't change the results for > any of the tests, except one. > > Let's test for this case explicitly. I.e. that we go "beyond" the > selected context to find our hunk header. In many cases the desired > hunk header is part of the diff itself under -U1.
Is this intended as a sanity check of test cases? (Otherwise, I see only that we are running two diffs instead of just one against every test case, but not which problem this is solving.)
Show 51 quoted lines
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> t/t4018-diff-funcname.sh | 13 +++++++++++++
> t/t4018/custom.sh | 1 +
> 2 files changed, 14 insertions(+)
>
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index 8b4500037f..d41aed9ba2 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -57,6 +57,7 @@ test_diff_funcname () {
> cat <&8 >arg.header &&
> cat <&9 >arg.test &&
> what=$(cat arg.what) &&
> + arg_diff_U0=$2 &&
>
> test_expect_success "setup: $desc" '
> cp arg.test "$what" &&
> @@ -78,6 +79,18 @@ test_diff_funcname () {
> test_cmp expected actual
> ' &&
>
> + test_expect_success "$desc -U0" '
> + git diff -U0 "$what" >diff &&
> + last_diff_context_line diff >actual &&
> + if test -n "$arg_diff_U0"
> + then
> + echo "$arg_diff_U0" >new-expected &&
> + test_cmp new-expected actual
> + else
> + test_cmp expected actual
> + fi
> + ' &&
> +
> test_expect_success "$desc (accumulated)" '
> git diff -U1 "$what".acc >diff &&
> last_diff_context_line diff >actual.lines &&
> diff --git a/t/t4018/custom.sh b/t/t4018/custom.sh
> index 886de9cddb..a090f7bfc2 100755
> --- a/t/t4018/custom.sh
> +++ b/t/t4018/custom.sh
> @@ -10,6 +10,7 @@ test_expect_success 'custom: setup non-trivial custom' '
> '
>
> test_diff_funcname 'custom: non-trivial custom pattern' \
> + 'System.out.print(x + " bottles of beer on the wall "' \
> 8<<\EOF_HUNK 9<<\EOF_TEST
> int special, RIGHT;
> EOF_HUNK
> -- Hannes