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

Re: [PATCH] diff-highlight: add some tests.

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 19, 2016, 20:44 UTC
Message-ID
<xmqqbn0o1ob7.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160819201837.GA18918@tci.corp.yp.com>
Brian Henderson <henderson.bj@gmail.com> writes:
Show 13 quoted lines
> Junio, how does this look?
> ...
> +# dh_test is a test helper function which takes 1) some file data, 2) some
> +# change of the file data, creates a diff and commit of the changes and passes
> +# that through diff-highlight.
> +# The optional 3rd parameter is the expected output of diff-highlight minus the
> +# diff/commit header. This parameter is given directly to printf as the format
> +# string (in order to properly handle ascii escape codes; CW, CR), so any '%'
> +# need to be doubled to protect it.
> +# Don't include a 3rd parameter if diff-highlight is supposed to leave the
> +# input unmodified.
> +# For convienence, the 3rd parameter can begin with a newline which will be
> +# stripped.

You seem to be stripping any and all empty lines with "perl -pe"; I am not sure if that is sensible.

I really do not see the point of being able to spell

" aaa bbb "

when you can perfectly well read

"aaa bbb"

or even "aaa\nbbb\n" for that matter. I personally do not think the difference is worth the cost of an extra invocation of Perl, but we already saw how stubborn you are, so there is no point spending my time on trying to convince you further. Assuming that it is so precious that the input can start with an extra blank line, what you wrote is a sensible implementation.

Show 15 quoted lines
> +dh_test () {
> +	a="$1" b="$2" &&
> +
> +	{
> +		printf "$a" >file &&
> +		git add file &&
> +		git commit -m "Add a file" &&
> +
> +		printf "$b" >file &&
> +		git diff file >diff.raw &&
> +		git commit -am "Update a file" &&
> +		git show >commit.raw
> +	} >/dev/null &&
> +
> +	if test $# -ge 3
I think
	if test $# = 3

is much better; you would want to catch bugs in a caller that gave you fourth parameter by mistake, instead of silently ignoring it.

> +test_strip_patch_header () {
> +	sed -e '1,/^@@/d' "$@"
> +}

While I think it is a great idea to hide the sed command behind a helper function for readability, I am not sure "strip patch header" is a great name that describes what it does. A natural expectation for an operation with that name done to this input:

    diff --git a/file b/file
    index fffffff..fffffff 100644
    --- a/file
    +++ b/file
    @@ -l,k +m,n @@ comments
     common
    -old
    +new
     common
    @@ -l,k +m,n @@ more comments
     common
    +added more
    +added even more
would be to remove the first four lines, not five.
Previous: Brian HendersonNext: Jeff King
Message 9 of 30 in “diff-highlight: add support for git log --graph output.”
  1. 0/3 diff-highlight: add support for git log --graph output.Brian Henderson, Aug 19, 2016
  2. 2/3 diff-highlight: add failing test for handling --graph output.Brian Henderson, Aug 19, 2016
  3. Junio C HamanoAug 19, 2016
  4. 1/3 diff-highlight: add some tests.Brian Henderson, Aug 19, 2016
  5. Junio C HamanoAug 19, 2016
  6. Brian HendersonAug 19, 2016
  7. Eric WongAug 19, 2016
  8. diff-highlight: add some tests.Brian Henderson, Aug 19, 2016
  9. Junio C HamanoAug 19, 2016
  10. Jeff KingAug 19, 2016
  11. Junio C HamanoAug 19, 2016
  12. diff-highlight: add some tests.Brian Henderson, Aug 22, 2016
  13. Jeff KingAug 23, 2016
  14. 0/3 diff-highlight: add support for --graph optionBrian Henderson, Aug 29, 2016
  15. 2/3 diff-highlight: add failing test for handling --graph output.Brian Henderson, Aug 29, 2016
  16. 1/3 diff-highlight: add some tests.Brian Henderson, Aug 29, 2016
  17. 3/3 diff-highlight: add support for --graph output.Brian Henderson, Aug 29, 2016
  18. Junio C HamanoAug 29, 2016
  19. 0/3 diff-highlight: add support for --graph optionBrian Henderson, Aug 30, 2016
  20. 1/3 diff-highlight: add some testsBrian Henderson, Aug 30, 2016
  21. 3/3 diff-highlight: add support for --graph outputBrian Henderson, Aug 30, 2016
  22. 2/3 diff-highlight: add failing test for handling --graph outputBrian Henderson, Aug 30, 2016
  23. Jeff KingAug 31, 2016
  24. 1/3 diff-highlight: ignore test cruftJeff King, Aug 31, 2016
  25. 2/3 diff-highlight: add multi-byte testsJeff King, Aug 31, 2016
  26. 3/3 diff-highlight: avoid highlighting combined diffsJeff King, Aug 31, 2016
  27. Jeff KingAug 30, 2016
  28. Junio C HamanoAug 19, 2016
  29. 3/3 diff-highlight: add support for --graph output.Brian Henderson, Aug 19, 2016
  30. Junio C HamanoAug 19, 2016

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.