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

Re: [PATCH v4 8/8] status: tests for --porcelain=v2

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 5, 2016, 18:12 UTC
Message-ID
<xmqq1t23xeyb.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1470147137-17498-9-git-send-email-git@jeffhostetler.com>
Jeff Hostetler <git@jeffhostetler.com> writes:
Show 5 quoted lines
> +##################################################################
> +## Confirm output prior to initial commit.
> +##################################################################
> +
> +test_expect_success pre_initial_commit_0 '
Bikeshedding, but our codebase seems to prefer "expect" vs "actual".
    $ git grep -e 'test_cmp expect ' t/ | wc -l
    1882
    $ git grep -e 'test_cmp expected ' t/ | wc -l
    888
Show 10 quoted lines
> +	cat >expected <<-EOF &&
> +	# branch.oid (initial)
> +	# branch.head master
> +	? actual
> +	? dir1/
> +	? expected
> +	? file_x
> +	? file_y
> +	? file_z
> +	EOF

Perhaps throw these two entries to .gitignore to allow new tests in the future could also use expect.1 vs actual.1 and somesuch?

	cat >.gitignore <<-\EOF &&
	expect*
        actual*
        EOF
Show 7 quoted lines
> +test_expect_success pre_initial_commit_1 '
> +	git add file_x file_y file_z dir1 &&
> +	SHA_A=`git hash-object -t blob -- dir1/file_a` &&
> +	SHA_B=`git hash-object -t blob -- dir1/file_b` &&
> +	SHA_X=`git hash-object -t blob -- file_x` &&
> +	SHA_Y=`git hash-object -t blob -- file_y` &&
> +	SHA_Z=`git hash-object -t blob -- file_z` &&

Please use $(commannd) instead of `command`. Also "SHA" is probably a bad prefix; either use "SHA_1" to be technically correct, or better yet use "OID", as we are moving towards abstracting the exact hash function name away.

> +	SHA_ZERO=0000000000000000000000000000000000000000 &&
I think we made $_z40 available to you from t/test-lib.sh.
Show 15 quoted lines
> +## Try -z on the above
> +test_expect_success pre_initial_commit_2 '
> +	cat >expected.lf <<-EOF &&
> +	# branch.oid (initial)
> +	# branch.head master
> +	1 A. N... 000000 100644 100644 $SHA_ZERO $SHA_A dir1/file_a
> +	1 A. N... 000000 100644 100644 $SHA_ZERO $SHA_B dir1/file_b
> +	1 A. N... 000000 100644 100644 $SHA_ZERO $SHA_X file_x
> +	1 A. N... 000000 100644 100644 $SHA_ZERO $SHA_Y file_y
> +	1 A. N... 000000 100644 100644 $SHA_ZERO $SHA_Z file_z
> +	? actual
> +	? expected
> +	EOF
> +	perl -pe y/\\012/\\000/ <expected.lf >expected &&
> +	rm expected.lf &&

As you immediately remove expected.lf, the first "cat" process is rather pointless. You can redirect here text <<-EOF directly into perl instead. Also it would probably help to add a new helper "lf_to_nul" in t/test-lib-functions.sh around the place where nul_to_q, ..., tz_to_tab_space helpers are defined, which would allow us to say

	lf_to_nul >expect <<-EOF &&
	...
        EOF
Show 15 quoted lines
> +test_expect_success initial_commit_3 '
> +	git mv file_y renamed_y &&
> +	H0=`git rev-parse HEAD` &&
> +
> +	cat >expected.q <<-EOF &&
> +	# branch.oid $H0
> +	# branch.head master
> +	1 M. N... 100644 100644 100644 $SHA_X $SHA_X1 file_x
> +	1 D. N... 100644 000000 000000 $SHA_Z $SHA_ZERO file_z
> +	2 R. N... 100644 100644 100644 $SHA_Y $SHA_Y R100 renamed_yQfile_y
> +	? actual
> +	? expected
> +	EOF
> +	q_to_tab <expected.q >expected &&
> +	rm expected.q &&
The same comment applies (redirect directly into q_to_tab).
Show 23 quoted lines
> +##################################################################
> +## Ignore a file
> +##################################################################
> +
> +test_expect_success ignore_file_0 '
> +	echo x.ign >.gitignore &&
> +	echo "ignore me" >x.ign &&
> +	H1=`git rev-parse HEAD` &&
> +
> +	cat >expected <<-EOF &&
> +	# branch.oid $H1
> +	# branch.head master
> +	? .gitignore
> +	? actual
> +	? expected
> +	! x.ign
> +	EOF
> +
> +	git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
> +	rm x.ign &&
> +	rm .gitignore &&
> +	test_cmp expected actual
> +'

You do not seem to be checking a feature is not triggered when not asked throughout this test, e.g. making sure the output does not have the "# branch.*" lines when --branch is not given, "! x.ign" is not shown when --ignored is not given, etc.

Show 16 quoted lines
> +##################################################################
> +## Test upstream fields in branch header
> +##################################################################
> +
> +test_expect_success 'upstream_fields_0' '
> +	git checkout master &&
> +	git clone . sub_repo &&
> +	(
> +		## Confirm local master tracks remote master.
> +		cd sub_repo &&
> +		HUF=`git rev-parse HEAD` &&
> + ...
> +		git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
> +		test_cmp expected actual
> +	) &&
> +	rm -rf sub_repo

It probably is a good idea to use test_when_finished immediately before "git clone . sub_repo" to arrange this to happen even when any test in the subshell fails.

Previous: Jeff HostetlerNext: Jeff Hostetler
Message 8 of 31 in “status: V2 porcelain status”
  1. 0/8 status: V2 porcelain statusJeff Hostetler, Aug 2, 2016
  2. 2/8 status: cleanup API to wt_status_printJeff Hostetler, Aug 2, 2016
  3. Junio C HamanoAug 3, 2016
  4. Jeff HostetlerAug 4, 2016
  5. 3/8 status: support --porcelain[=<version>]Jeff Hostetler, Aug 2, 2016
  6. Junio C HamanoAug 3, 2016
  7. 8/8 status: tests for --porcelain=v2Jeff Hostetler, Aug 2, 2016
  8. Junio C HamanoAug 5, 2016
  9. Jeff HostetlerAug 5, 2016
  10. 6/8 status: print branch info with --porcelain=v2 --branchJeff Hostetler, Aug 2, 2016
  11. Junio C HamanoAug 5, 2016
  12. Jeff HostetlerAug 5, 2016
  13. 5/8 status: print per-file porcelain v2 status dataJeff Hostetler, Aug 2, 2016
  14. Jeff KingAug 5, 2016
  15. Junio C HamanoAug 5, 2016
  16. Jeff KingAug 5, 2016
  17. Junio C HamanoAug 5, 2016
  18. Stefan BellerAug 5, 2016
  19. Stefan BellerAug 5, 2016
  20. Jeff HostetlerAug 5, 2016
  21. 7/8 git-status.txt: describe --porcelain=v2 formatJeff Hostetler, Aug 2, 2016
  22. Junio C HamanoAug 5, 2016
  23. Jeff HostetlerAug 5, 2016
  24. 1/8 status: rename long-format print routinesJeff Hostetler, Aug 2, 2016
  25. Junio C HamanoAug 3, 2016
  26. Jeff HostetlerAug 4, 2016
  27. 4/8 status: per-file data collection for --porcelain=v2Jeff Hostetler, Aug 2, 2016
  28. Johannes SchindelinAug 3, 2016
  29. Junio C HamanoAug 3, 2016
  30. Johannes SchindelinAug 3, 2016
  31. Junio C HamanoAug 3, 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.