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

Re: [PATCH 3/6] t1006 (cat-file): use test_cmp

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Dec 8, 2011, 16:55 UTC
Message-ID
<20111208165512.GC2394@elie.hsd1.il.comcast.net>
In-Reply-To
<1323349817-15737-6-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra wrote:
> Use test_cmp in preference to repeatedly comparing command outputs by
> hand.
That could mean one of several things.
It could mean:
	1. Use test_cmp instead of open-coding it.
	2. Use test_cmp instead of using our knowledge of the underlying
	   filesystem to retrieve the files from the block device, instead
	   of relying on the perfectly good operating system facilities
	   that could take care of it for us
	3. Use test_cmp instead of calling a human over to compare command
	   outputs by eye, which idiomatically might be described as "by
	   hand".

What I mean is, I actually don't have much of a clue what you mean by "by hand". Usually it means "not automated sufficiently", but I think that is not the entire problem here (since

	test "$expect" = "$actual"
looks no less automatic than
	printf '%s\n' "$expect" >expect &&
	printf '%s\n' "$actual" >actual &&
	test_cmp expect actual
to me).
> 
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
[...]
> --- a/t/t1006-cat-file.sh
> +++ b/t/t1006-cat-file.sh
> @@ -36,66 +36,41 @@ $content"
[...]
Show 14 quoted lines
> -	expect="$(maybe_remove_timestamp "$content" $no_ts)"
> -	actual="$(maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts)"
> -
> -        if test "z$expect" = "z$actual"
> -	then
> -		: happy
> -	else
> -		echo "Oops: expected $expect"
> -		echo "but got $actual"
> -		false
> -        fi
> +	maybe_remove_timestamp "$content" $no_ts >expect &&
> +	maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
> +	test_cmp expect actual

Most of the early part of patch proper looks sane from a quick glance. Wow, the whitespace is a little strange in the original.

[...]
Show 14 quoted lines
> @@ -175,30 +153,41 @@ do
>  done
>  
>  test_expect_success "--batch-check for a non-existent named object" '
> -    test "foobar42 missing
> -foobar84 missing" = \
> -    "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
> +    cat >expect <<\-EOF &&
> +foobar42 missing
> +foobar84 missing
> +EOF
> +    $(echo foobar42; echo_without_newline foobar84) \
> +    | git cat-file --batch-check >actual &&
> +    test_cmp expect actual
Style: the | character goes at the end of the first line (think of it
as a way to save backslashes until they're needed).
How could this $(...) command substitution possibly work?
Later tests have the same problem, so I'm stopping here.

Ciao, Jonathan

Previous: Matthieu MoyNext: Ramkumar Ramachandra
Message 32 of 50 in “Fix '&&' chaining in tests”
  1. 0/6 Fix '&&' chaining in testsRamkumar Ramachandra, Dec 8, 2011
  2. 1/2 parse-options: introduce OPT_SUBCOMMANDRamkumar Ramachandra, Dec 8, 2011
  3. Jonathan NiederDec 8, 2011
  4. Ramkumar RamachandraDec 8, 2011
  5. 1/6 t3040 (subprojects-basic): modernize styleRamkumar Ramachandra, Dec 8, 2011
  6. Jonathan NiederDec 8, 2011
  7. Ramkumar RamachandraDec 9, 2011
  8. Junio C HamanoDec 9, 2011
  9. Ramkumar RamachandraDec 9, 2011
  10. 2/2 bundle: rewrite builtin to use parse-optionsRamkumar Ramachandra, Dec 8, 2011
  11. Jonathan NiederDec 8, 2011
  12. Ramkumar RamachandraDec 8, 2011
  13. Jonathan NiederDec 8, 2011
  14. Ramkumar RamachandraDec 8, 2011
  15. Jonathan NiederDec 8, 2011
  16. Ramkumar RamachandraDec 8, 2011
  17. Junio C HamanoDec 8, 2011
  18. Jakub NarebskiDec 9, 2011
  19. Junio C HamanoDec 9, 2011
  20. 0/2 Improve git-bundle builtinRamkumar Ramachandra, Dec 15, 2011
  21. 1/2 t5704 (bundle): rewrite for larger coverageRamkumar Ramachandra, Dec 15, 2011
  22. Jonathan NiederDec 15, 2011
  23. 2/2 bundle: rewrite builtin to use parse-optionsRamkumar Ramachandra, Dec 15, 2011
  24. Jonathan NiederDec 15, 2011
  25. Jonathan NiederDec 15, 2011
  26. Junio C HamanoDec 15, 2011
  27. 2/6 t3030 (merge-recursive): use test_expect_codeRamkumar Ramachandra, Dec 8, 2011
  28. 3/6 t1006 (cat-file): use test_cmpRamkumar Ramachandra, Dec 8, 2011
  29. Matthieu MoyDec 8, 2011
  30. Ramkumar RamachandraDec 8, 2011
  31. Matthieu MoyDec 8, 2011
  32. Jonathan NiederDec 8, 2011
  33. 4/6 t3200 (branch): fix '&&' chainingRamkumar Ramachandra, Dec 8, 2011
  34. Jonathan NiederDec 8, 2011
  35. 5/6 t1510 (worktree): fix '&&' chainingRamkumar Ramachandra, Dec 8, 2011
  36. Jonathan NiederDec 8, 2011
  37. Junio C HamanoDec 9, 2011
  38. 6/6 test: fix '&&' chainingRamkumar Ramachandra, Dec 8, 2011
  39. Jonathan NiederDec 8, 2011
  40. Junio C HamanoDec 8, 2011
  41. Ramkumar RamachandraDec 9, 2011
  42. 0/6 Fix '&&' chaining in testsRamkumar Ramachandra, Dec 9, 2011
  43. 1/6 t3040 (subprojects-basic): fix '&&' chaining, modernize styleRamkumar Ramachandra, Dec 9, 2011
  44. 2/6 t3030 (merge-recursive): use test_expect_codeRamkumar Ramachandra, Dec 9, 2011
  45. 3/6 t1006 (cat-file): use test_cmpRamkumar Ramachandra, Dec 9, 2011
  46. Junio C HamanoDec 9, 2011
  47. Ramkumar RamachandraDec 9, 2011
  48. 4/6 t3200 (branch): fix '&&' chainingRamkumar Ramachandra, Dec 9, 2011
  49. 5/6 t1510 (worktree): fix '&&' chainingRamkumar Ramachandra, Dec 9, 2011
  50. 6/6 tests: fix '&&' chainingRamkumar Ramachandra, Dec 9, 2011

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.