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

Re: [PATCH 1/3 v5] diff --stat: tests for long filenames and big change counts

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 15, 2012, 17:12 UTC
Message-ID
<7vvcn810ml.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1329303808-16989-1-git-send-email-zbyszek@in.waw.pl>
Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> writes:
> Eleven tests for various combinations of a long filename and/or big
> change count and ways to specify widths for diff --stat.
> ---
Sign-off? 
> Tests added in previous version of 'diff --stat: use full terminal width'
> are extracted into a separate patch. The tests are usefull independently
> of that patch anyway.
Thanks.
Show 10 quoted lines
> +# 120 character name
> +name=aaaaaaaaaa
> +name=$name$name$name$name$name$name$name$name$name$name$name$name
> +test_expect_success 'preparation' "
> +	>\"$name\" &&
> +	git add \"$name\" &&
> +	git commit -m message &&
> +	echo a >\"$name\" &&
> +	git commit -m message \"$name\"
> +"
Just for future reference.

The last parameter to test_expect_success shell function is `eval`ed by the shell and $name is visible inside it; you do not have to use double quote around it and then use backquote to quote the inner double quote.

Show 8 quoted lines
> +cat >expect <<'EOF'
> + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |    1 +
> +EOF
> +test_expect_success 'format patch graph width defaults to 80 columns' '
> +	git format-patch --stat --stdout -1 >output &&
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'

Hrm, this does not seem to pass, making the result of applying [1/3] fail; I see that the elided name is shown much shorter than the above expects.

Perhaps this test found a bug in a "very long name, small changes" corner case? If that is the case, we'd mark it as test_expect_failure, and explain the tests that expect failure demonstrates a buggy behaviour, e.g.

	When a pathname is so long that it cannot fit on the column, the
	current code truncates it to make sure that the graph part has at
	least N columns (enough room to show a meaningful graph).  If the
	actual change is small (e.g. only one line changed), this results
	in the final output that is shorter than the width we aim for.  A
	couple of new tests marked with test_expect_failure demonstrate
	this bug.

in the log message (note that I am not sure if that is the nature of the bug, or what the actual value of N is).

And then a later patch [2/3] that updates the allocation between name and graph will turn test_expect_failure to test_expect_success; that will make it clear that your update fixed the bug.

Show 8 quoted lines
> +cat >expect <<'EOF'
> + ...aaaaaaaaaaaaaaaaaaaaaaaaaa |    1 +
> +EOF
> +test_expect_success 'format patch --stat=width with long name' '
> +	git format-patch --stat=40 --stdout -1 >output &&
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'
Likewise.
Show 5 quoted lines
> +test_expect_success 'format patch --stat-width=width works with long name' '
> +	git format-patch --stat-width=40 --stdout -1 >output &&
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'
Likewise.
Show 11 quoted lines
> +test_expect_success 'format patch --stat=...,name-width with long name' '
> +	git format-patch --stat=60,29 --stdout -1 >output &&
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'format patch --stat-name-width with long name' '
> +	git format-patch --stat-name-width=29 --stdout -1 >output &&
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'
Likewise.
> +test_expect_success 'preparation' '

There was another "preparation" in this script already, which originally threw me off while chasing which part of the test is failing. Can you reword/retitle this one?

Show 8 quoted lines
> +cat >expect <<'EOF'
> + abcd | 1000 ++++++++++++++++++++++++++++++++++++++++
> +EOF
> +test_expect_success 'format patch graph part width is 40 columns' '
> +	git format-patch --stat --stdout -1 >output &&
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'

This test shouldn't be added in [1/3] because "cap the graph to 40-col" is a new feature that is introduced in the later step.

Show 5 quoted lines
> +test_expect_success 'format patch ignores COLUMNS' '
> +	COLUMNS=200 git format-patch --stat --stdout -1 >output
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'

This is a good test to have in [1/3], but the expectation should not cap the graph part to 40 columns. The patch that updates diff.c to implement the cap in [2/3] should have an update to the expectation, whose diff hunk may look liks this:

@@ 
 cat >expect <<'EOF'
+ abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- abcd | 1000 ++++++++++++++++++++++++++++++++++++++++ 
 EOF
That would make the effect of the patch clearer.
Show 13 quoted lines
> +cat >expect <<'EOF'
> + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
> +EOF
> +test_expect_success 'format patch --stat=width with big change and long name' '
> +	cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
> +	git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
> +	git commit -m message &&
> +	git format-patch --stat-width=60 --stdout -1 >output &&
> +	grep " | " output >actual &&
> +	test_cmp expect actual
> +'
> +
>  test_done

The same comment as the previous one. Because you change the allocation to the graph part in your patch to diff.c, which hasn't happened in [1/3] yet, this should expect the existing behaviour (narrower graph) in this step, and then be updated to expect the output shown above in the [2/3] patch that changes the implementation in diff.c.

Previous: Nguyen Thai Ngoc DuyNext: Junio C Hamano
Message 38 of 46 in “(unknown)”
  1. Zbigniew Jędrzejewski-SzmekFeb 9, 2012
  2. 1/4 Move git_version_string to help.c in preparation for diff changesZbigniew Jędrzejewski-Szmek, Feb 9, 2012
  3. Junio C HamanoFeb 10, 2012
  4. 2/4 help.c: make term_columns() cached and export itZbigniew Jędrzejewski-Szmek, Feb 9, 2012
  5. Junio C HamanoFeb 10, 2012
  6. 3/4 diff --stat: use the real terminal widthZbigniew Jędrzejewski-Szmek, Feb 9, 2012
  7. Junio C HamanoFeb 10, 2012
  8. Nguyen Thai Ngoc DuyFeb 10, 2012
  9. Zbigniew Jędrzejewski-SzmekFeb 10, 2012
  10. Nguyen Thai Ngoc DuyFeb 10, 2012
  11. 0/3 diff --stat: use the real terminal widthZbigniew Jędrzejewski-Szmek, Feb 10, 2012
  12. 1/3 Move git_version_string to help.c before diff changesZbigniew Jędrzejewski-Szmek, Feb 10, 2012
  13. Junio C HamanoFeb 10, 2012
  14. 2/3 help.c: make term_columns() cached and export itZbigniew Jędrzejewski-Szmek, Feb 10, 2012
  15. Nguyen Thai Ngoc DuyFeb 11, 2012
  16. Zbigniew Jędrzejewski-SzmekFeb 11, 2012
  17. Junio C HamanoFeb 12, 2012
  18. 1/2 Save terminal width before setting up pager and export term_columns()Zbigniew Jędrzejewski-Szmek, Feb 12, 2012
  19. Junio C HamanoFeb 13, 2012
  20. Nguyen Thai Ngoc DuyFeb 14, 2012
  21. Zbigniew Jędrzejewski-SzmekFeb 14, 2012
  22. 2/2 Rename lineno_width to decimal_width and export itZbigniew Jędrzejewski-Szmek, Feb 12, 2012
  23. Junio C HamanoFeb 13, 2012
  24. make lineno_width() from blame reusable for othersZbigniew Jędrzejewski-Szmek, Feb 14, 2012
  25. 3/3 diff --stat: use the real terminal widthZbigniew Jędrzejewski-Szmek, Feb 10, 2012
  26. Junio C HamanoFeb 10, 2012
  27. diff --stat: use the full terminal widthZbigniew Jędrzejewski-Szmek, Feb 12, 2012
  28. Junio C HamanoFeb 14, 2012
  29. 1/3 diff --stat: use the full terminal widthZbigniew Jędrzejewski-Szmek, Feb 14, 2012
  30. 2/3 diff --stat: better alignment for binary filesZbigniew Jędrzejewski-Szmek, Feb 14, 2012
  31. 3/3 Update diff --stat output in tests and tutorialZbigniew Jędrzejewski-Szmek, Feb 14, 2012
  32. Junio C HamanoFeb 15, 2012
  33. 1/3 diff --stat: tests for long filenames and big change countsZbigniew Jędrzejewski-Szmek, Feb 15, 2012
  34. 2/3 diff --stat: use the full terminal widthZbigniew Jędrzejewski-Szmek, Feb 15, 2012
  35. Junio C HamanoFeb 15, 2012
  36. 3/3 diff --stat: use less columns for change countsZbigniew Jędrzejewski-Szmek, Feb 15, 2012
  37. Nguyen Thai Ngoc DuyFeb 15, 2012
  38. Junio C HamanoFeb 15, 2012
  39. Junio C HamanoFeb 15, 2012
  40. Zbigniew Jędrzejewski-SzmekFeb 16, 2012
  41. Junio C HamanoFeb 16, 2012
  42. Junio C HamanoFeb 15, 2012
  43. Junio C HamanoFeb 15, 2012
  44. Johannes SixtFeb 15, 2012
  45. 4/4 diff --stat: use most of the space for file namesZbigniew Jędrzejewski-Szmek, Feb 9, 2012
  46. Junio C HamanoFeb 10, 2012

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.