git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 7/8] t4124: fix test for non-compliant diff(1)

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 23, 2020, 13:58 UTC
Message-ID
<nycvar.QRO.7.76.6.2003231456200.46@tvgsbejvaqbjf.bet>
In-Reply-To
<10f39c3d30d13e9141f081f985a0620954cc7493.1584838148.git.congdanhqx@gmail.com>
Hi,
On Sun, 22 Mar 2020, Đoàn Trần Công Danh wrote:
Show 30 quoted lines
> 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?

Ciao,
Dscho

>
>  	# the changed lines are all expected to change
>  	fixed_cnt=$(wc -l <fixed)
> --
> 2.26.0.rc2.310.g2932bb562d
>
>
>
Previous: Đoàn Trần Công DanhNext: Danh Doan
Message 16 of 36 in “fix test failure with busybox”
  1. 0/8 fix test failure with busyboxĐoàn Trần Công Danh, Mar 22, 2020
  2. 1/8 t4061: use POSIX compliant regex(7)Đoàn Trần Công Danh, Mar 22, 2020
  3. 3/8 t5003: drop the subshell in test_lazy_prereqĐoàn Trần Công Danh, Mar 22, 2020
  4. 2/8 test-lib-functions: test_cmp: eval $GIT_TEST_CMPĐoàn Trần Công Danh, Mar 22, 2020
  5. 4/8 t5003: skip conversion test if unzip -a is unavailableĐoàn Trần Công Danh, Mar 22, 2020
  6. 5/8 t5616: use rev-parse instead to get HEAD's object_idĐoàn Trần Công Danh, Mar 22, 2020
  7. 6/8 t7063: drop non-POSIX argument "-ls" from find(1)Đoàn Trần Công Danh, Mar 22, 2020
  8. Johannes SchindelinMar 23, 2020
  9. Torsten BögershausenMar 23, 2020
  10. Danh DoanMar 23, 2020
  11. Junio C HamanoMar 23, 2020
  12. Junio C HamanoMar 23, 2020
  13. Johannes SchindelinMar 24, 2020
  14. Junio C HamanoMar 24, 2020
  15. 7/8 t4124: fix test for non-compliant diff(1)Đoàn Trần Công Danh, Mar 22, 2020
  16. Johannes SchindelinMar 23, 2020
  17. Danh DoanMar 23, 2020
  18. Junio C HamanoMar 23, 2020
  19. Danh DoanMar 24, 2020
  20. Junio C HamanoMar 24, 2020
  21. Danh DoanMar 25, 2020
  22. Johannes SchindelinMar 24, 2020
  23. Junio C HamanoMar 24, 2020
  24. Johannes SchindelinMar 25, 2020
  25. 8/8 t5703: feed raw data into test-tool unpack-sidebandĐoàn Trần Công Danh, Mar 22, 2020
  26. Jeff KingMar 22, 2020
  27. 0/8 fix test failure with busyboxĐoàn Trần Công Danh, Mar 26, 2020
  28. 1/8 t4061: use POSIX compliant regex(7)Đoàn Trần Công Danh, Mar 26, 2020
  29. 2/8 test-lib-functions: test_cmp: eval $GIT_TEST_CMPĐoàn Trần Công Danh, Mar 26, 2020
  30. 3/8 t5003: drop the subshell in test_lazy_prereqĐoàn Trần Công Danh, Mar 26, 2020
  31. 4/8 t5003: skip conversion test if unzip -a is unavailableĐoàn Trần Công Danh, Mar 26, 2020
  32. 5/8 t5616: use rev-parse instead to get HEAD's object_idĐoàn Trần Công Danh, Mar 26, 2020
  33. 7/8 t4124: fix test for non-compliant diff(1)Đoàn Trần Công Danh, Mar 26, 2020
  34. Junio C HamanoMar 27, 2020
  35. 6/8 t7063: drop non-POSIX argument "-ls" from find(1)Đoàn Trần Công Danh, Mar 26, 2020
  36. 8/8 t5703: feed raw data into test-tool unpack-sidebandĐoàn Trần Công Danh, Mar 26, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.