git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Danh Doan <congdanhqx@gmail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 7/8] t4124: fix test for non-compliant diff(1)
Date: Mon, 23 Mar 2020 22:04:49 +0700	[thread overview]
Message-ID: <20200323150449.GC11801@danh.dev> (raw)
In-Reply-To: <nycvar.QRO.7.76.6.2003231456200.46@tvgsbejvaqbjf.bet>

On 2020-03-23 14:58:13+0100, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Hi,
> 
> On Sun, 22 Mar 2020, Đoàn Trần Công Danh wrote:
> 
> > POSIX's diff(1) requires output in normal diff format.
> > However, busybox's diff's output is written in unified format.
> >
> > POSIX requires no option for normal-diff format.
> >
> > A hint in test-lib-functions::test_cmp said `diff -u` isn't available
> > everywhere.
> >
> > Workaround this problem by assuming `diff(1)` output is unified
> > if we couldn't make anything from normal-diff format.
> >
> > Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
> > ---
> >  t/t4124-apply-ws-rule.sh | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
> > index 971a5a7512..075b1912be 100755
> > --- a/t/t4124-apply-ws-rule.sh
> > +++ b/t/t4124-apply-ws-rule.sh
> > @@ -52,6 +52,12 @@ test_fix () {
> >
> >  	# find touched lines
> >  	$DIFF file target | sed -n -e "s/^> //p" >fixed
> > +	# busybox's diff(1) output unified format
> > +	if ! test -s fixed; then
> > +		$DIFF file target |
> > +		grep -v '^+++ target' |
> > +		sed -e "/^+/s/+//" >fixed
> > +	fi
> 
> In my patches (which are too unpolished to contribute, I have not found
> time to clean them up in several years), I do this differently:
> 
> -- snip --
> commit cb2f3a28dbf40b92d3d9ca0f3177cd5afb7c4196
> Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Date:   Wed Jul 5 22:21:57 2017 +0200
> 
>     t4124: avoid using "normal" diff mode
> 
>     Everybody and their dogs, cats and other pets settled on using unified
>     diffs. It is a really quaint holdover from a long-gone era that GNU diff
>     outputs "normal" diff by default.
> 
>     Yet, t4124 relied on that mode.
> 
>     This mode is so out of fashion in the meantime, though, that e.g.
>     BusyBox' diff decided not even to bother to support it. It only supports
>     unified diffs.
> 
>     So let's just switch away from "normal" diffs and use unified diffs, as
>     we really are only interested in the `+` lines.
> 
>     Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
> index 971a5a7512ac..133557b99333 100755
> --- a/t/t4124-apply-ws-rule.sh
> +++ b/t/t4124-apply-ws-rule.sh
> @@ -51,7 +51,7 @@ test_fix () {
>         apply_patch --whitespace=fix || return 1
> 
>         # find touched lines
> -       $DIFF file target | sed -n -e "s/^> //p" >fixed
> +       $DIFF -u file target | sed -n -e "3,\$s/^+//p" >fixed
> 
>         # the changed lines are all expected to change
>         fixed_cnt=$(wc -l <fixed)
> -- snap --
> 
> Food for thought?

A comment in test-lib-functions::test_cmp mentions that
there _is_ a diff out there that doesn't understand "-u".
I don't know which one is it.

If we choose to use "diff -u" here, we've made a certain assumption,
should we flip the switch in test_cmp, too?

-- 
Danh

  reply	other threads:[~2020-03-23 15:04 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-22  0:55 [PATCH v2 0/8] fix test failure with busybox Đoàn Trần Công Danh
2020-03-22  0:55 ` [PATCH v2 1/8] t4061: use POSIX compliant regex(7) Đoàn Trần Công Danh
2020-03-22  0:55 ` [PATCH v2 2/8] test-lib-functions: test_cmp: eval $GIT_TEST_CMP Đoàn Trần Công Danh
2020-03-22  0:55 ` [PATCH v2 3/8] t5003: drop the subshell in test_lazy_prereq Đoàn Trần Công Danh
2020-03-22  0:55 ` [PATCH v2 4/8] t5003: skip conversion test if unzip -a is unavailable Đoàn Trần Công Danh
2020-03-22  0:55 ` [PATCH v2 5/8] t5616: use rev-parse instead to get HEAD's object_id Đoàn Trần Công Danh
2020-03-22  0:55 ` [PATCH v2 6/8] t7063: drop non-POSIX argument "-ls" from find(1) Đoàn Trần Công Danh
2020-03-23 14:11   ` Johannes Schindelin
2020-03-23 14:37     ` Torsten Bögershausen
2020-03-23 15:11     ` Danh Doan
2020-03-23 20:30       ` Junio C Hamano
2020-03-23 15:55     ` Junio C Hamano
2020-03-24 22:31       ` Johannes Schindelin
2020-03-24 23:46         ` Junio C Hamano
2020-03-22  0:55 ` [PATCH v2 7/8] t4124: fix test for non-compliant diff(1) Đoàn Trần Công Danh
2020-03-23 13:58   ` Johannes Schindelin
2020-03-23 15:04     ` Danh Doan [this message]
2020-03-23 20:50       ` Junio C Hamano
2020-03-24  3:40         ` Danh Doan
2020-03-24 18:47           ` Junio C Hamano
2020-03-25 14:24             ` Danh Doan
2020-03-24 22:29           ` Johannes Schindelin
2020-03-24 23:37             ` Junio C Hamano
2020-03-25 18:23               ` Johannes Schindelin
2020-03-22  0:55 ` [PATCH v2 8/8] t5703: feed raw data into test-tool unpack-sideband Đoàn Trần Công Danh
2020-03-22  6:08 ` [PATCH v2 0/8] fix test failure with busybox Jeff King
2020-03-26  4:37 ` [PATCH v4 " Đoàn Trần Công Danh
2020-03-26  4:37   ` [PATCH v4 1/8] t4061: use POSIX compliant regex(7) Đoàn Trần Công Danh
2020-03-26  4:37   ` [PATCH v4 2/8] test-lib-functions: test_cmp: eval $GIT_TEST_CMP Đoàn Trần Công Danh
2020-03-26  4:37   ` [PATCH v4 3/8] t5003: drop the subshell in test_lazy_prereq Đoàn Trần Công Danh
2020-03-26  4:37   ` [PATCH v4 4/8] t5003: skip conversion test if unzip -a is unavailable Đoàn Trần Công Danh
2020-03-26  4:37   ` [PATCH v4 5/8] t5616: use rev-parse instead to get HEAD's object_id Đoàn Trần Công Danh
2020-03-26  4:37   ` [PATCH v4 6/8] t7063: drop non-POSIX argument "-ls" from find(1) Đoàn Trần Công Danh
2020-03-26  4:37   ` [PATCH v4 7/8] t4124: fix test for non-compliant diff(1) Đoàn Trần Công Danh
2020-03-27  1:18     ` Junio C Hamano
2020-03-26  4:37   ` [PATCH v4 8/8] t5703: feed raw data into test-tool unpack-sideband Đoàn Trần Công Danh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200323150449.GC11801@danh.dev \
    --to=congdanhqx@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).