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

Re: [PATCH 03/11] t: convert tests to use helpers for reference existence

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 18, 2023, 16:28 UTC
Message-ID
<xmqqcyxbuc71.fsf@gitster.g>
In-Reply-To
<ac6a49c7c84ad2b836f099557dd6989703ebda8f.1697607222.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 12 quoted lines
> Convert tests that use `test_path_is_file` and `test_path_is_missing` to
> instead use our new helpers `test_ref_exists` and `test_ref_missing`.
> These hook into the reference database directly and thus work indepently
> of the actual reference backend that is being used.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  t/t1430-bad-ref-name.sh | 27 ++++++++++++++++++---------
>  t/t3200-branch.sh       | 33 ++++++++++++++++++---------------
>  t/t5521-pull-options.sh |  4 ++--
>  t/t5605-clone-local.sh  |  2 +-
>  4 files changed, 39 insertions(+), 27 deletions(-)

I scanned through the changes, and all of them looked sensible. I also very much liked the added "now we have done something to create 'badname' branch, let's make sure it exists, before trying to see if the machinery to delete it works correctly" tests.

Looking good.
Thanks.
Show 254 quoted lines
> diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh
> index ff1c967d550..7b7d6953c62 100755
> --- a/t/t1430-bad-ref-name.sh
> +++ b/t/t1430-bad-ref-name.sh
> @@ -205,8 +205,9 @@ test_expect_success 'update-ref --no-deref -d can delete symref to broken name'
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" &&
>  	test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" &&
> +	test_ref_exists refs/heads/badname &&
>  	git update-ref --no-deref -d refs/heads/badname >output 2>error &&
> -	test_path_is_missing .git/refs/heads/badname &&
> +	test_ref_missing refs/heads/badname &&
>  	test_must_be_empty output &&
>  	test_must_be_empty error
>  '
> @@ -216,8 +217,9 @@ test_expect_success 'branch -d can delete symref to broken name' '
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" &&
>  	test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" &&
> +	test_ref_exists refs/heads/badname &&
>  	git branch -d badname >output 2>error &&
> -	test_path_is_missing .git/refs/heads/badname &&
> +	test_ref_missing refs/heads/badname &&
>  	test_i18ngrep "Deleted branch badname (was refs/heads/broken\.\.\.ref)" output &&
>  	test_must_be_empty error
>  '
> @@ -225,8 +227,9 @@ test_expect_success 'branch -d can delete symref to broken name' '
>  test_expect_success 'update-ref --no-deref -d can delete dangling symref to broken name' '
>  	test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" &&
> +	test_ref_exists refs/heads/badname &&
>  	git update-ref --no-deref -d refs/heads/badname >output 2>error &&
> -	test_path_is_missing .git/refs/heads/badname &&
> +	test_ref_missing refs/heads/badname &&
>  	test_must_be_empty output &&
>  	test_must_be_empty error
>  '
> @@ -234,8 +237,9 @@ test_expect_success 'update-ref --no-deref -d can delete dangling symref to brok
>  test_expect_success 'branch -d can delete dangling symref to broken name' '
>  	test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" &&
> +	test_ref_exists refs/heads/badname &&
>  	git branch -d badname >output 2>error &&
> -	test_path_is_missing .git/refs/heads/badname &&
> +	test_ref_missing refs/heads/badname &&
>  	test_i18ngrep "Deleted branch badname (was refs/heads/broken\.\.\.ref)" output &&
>  	test_must_be_empty error
>  '
> @@ -245,8 +249,9 @@ test_expect_success 'update-ref -d can delete broken name through symref' '
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" &&
>  	test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" &&
> +	test_ref_exists refs/heads/broken...ref &&
>  	git update-ref -d refs/heads/badname >output 2>error &&
> -	test_path_is_missing .git/refs/heads/broken...ref &&
> +	test_ref_missing refs/heads/broken...ref &&
>  	test_must_be_empty output &&
>  	test_must_be_empty error
>  '
> @@ -254,8 +259,9 @@ test_expect_success 'update-ref -d can delete broken name through symref' '
>  test_expect_success 'update-ref --no-deref -d can delete symref with broken name' '
>  	printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
> +	test_ref_exists refs/heads/broken...symref &&
>  	git update-ref --no-deref -d refs/heads/broken...symref >output 2>error &&
> -	test_path_is_missing .git/refs/heads/broken...symref &&
> +	test_ref_missing refs/heads/broken...symref &&
>  	test_must_be_empty output &&
>  	test_must_be_empty error
>  '
> @@ -263,8 +269,9 @@ test_expect_success 'update-ref --no-deref -d can delete symref with broken name
>  test_expect_success 'branch -d can delete symref with broken name' '
>  	printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
> +	test_ref_exists refs/heads/broken...symref &&
>  	git branch -d broken...symref >output 2>error &&
> -	test_path_is_missing .git/refs/heads/broken...symref &&
> +	test_ref_missing refs/heads/broken...symref &&
>  	test_i18ngrep "Deleted branch broken...symref (was refs/heads/main)" output &&
>  	test_must_be_empty error
>  '
> @@ -272,8 +279,9 @@ test_expect_success 'branch -d can delete symref with broken name' '
>  test_expect_success 'update-ref --no-deref -d can delete dangling symref with broken name' '
>  	printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
> +	test_ref_exists refs/heads/broken...symref &&
>  	git update-ref --no-deref -d refs/heads/broken...symref >output 2>error &&
> -	test_path_is_missing .git/refs/heads/broken...symref &&
> +	test_ref_missing refs/heads/broken...symref &&
>  	test_must_be_empty output &&
>  	test_must_be_empty error
>  '
> @@ -281,8 +289,9 @@ test_expect_success 'update-ref --no-deref -d can delete dangling symref with br
>  test_expect_success 'branch -d can delete dangling symref with broken name' '
>  	printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
>  	test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
> +	test_ref_exists refs/heads/broken...symref &&
>  	git branch -d broken...symref >output 2>error &&
> -	test_path_is_missing .git/refs/heads/broken...symref &&
> +	test_ref_missing refs/heads/broken...symref &&
>  	test_i18ngrep "Deleted branch broken...symref (was refs/heads/idonotexist)" output &&
>  	test_must_be_empty error
>  '
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 080e4f24a6e..bde4f1485b7 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -25,7 +25,7 @@ test_expect_success 'prepare a trivial repository' '
>  
>  test_expect_success 'git branch --help should not have created a bogus branch' '
>  	test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 &&
> -	test_path_is_missing .git/refs/heads/--help
> +	test_ref_missing refs/heads/--help
>  '
>  
>  test_expect_success 'branch -h in broken repository' '
> @@ -40,7 +40,8 @@ test_expect_success 'branch -h in broken repository' '
>  '
>  
>  test_expect_success 'git branch abc should create a branch' '
> -	git branch abc && test_path_is_file .git/refs/heads/abc
> +	git branch abc &&
> +	test_ref_exists refs/heads/abc
>  '
>  
>  test_expect_success 'git branch abc should fail when abc exists' '
> @@ -61,11 +62,13 @@ test_expect_success 'git branch --force abc should succeed when abc exists' '
>  '
>  
>  test_expect_success 'git branch a/b/c should create a branch' '
> -	git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
> +	git branch a/b/c &&
> +	test_ref_exists refs/heads/a/b/c
>  '
>  
>  test_expect_success 'git branch mb main... should create a branch' '
> -	git branch mb main... && test_path_is_file .git/refs/heads/mb
> +	git branch mb main... &&
> +	test_ref_exists refs/heads/mb
>  '
>  
>  test_expect_success 'git branch HEAD should fail' '
> @@ -78,14 +81,14 @@ EOF
>  test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
>  	GIT_COMMITTER_DATE="2005-05-26 23:30" \
>  	git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
> -	test_path_is_file .git/refs/heads/d/e/f &&
> +	test_ref_exists refs/heads/d/e/f &&
>  	test_path_is_file .git/logs/refs/heads/d/e/f &&
>  	test_cmp expect .git/logs/refs/heads/d/e/f
>  '
>  
>  test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
>  	git branch -d d/e/f &&
> -	test_path_is_missing .git/refs/heads/d/e/f &&
> +	test_ref_missing refs/heads/d/e/f &&
>  	test_must_fail git reflog exists refs/heads/d/e/f
>  '
>  
> @@ -213,7 +216,7 @@ test_expect_success 'git branch -M should leave orphaned HEAD alone' '
>  		test_commit initial &&
>  		git checkout --orphan lonely &&
>  		grep lonely .git/HEAD &&
> -		test_path_is_missing .git/refs/head/lonely &&
> +		test_ref_missing refs/head/lonely &&
>  		git branch -M main mistress &&
>  		grep lonely .git/HEAD
>  	)
> @@ -799,8 +802,8 @@ test_expect_success 'deleting a symref' '
>  	git symbolic-ref refs/heads/symref refs/heads/target &&
>  	echo "Deleted branch symref (was refs/heads/target)." >expect &&
>  	git branch -d symref >actual &&
> -	test_path_is_file .git/refs/heads/target &&
> -	test_path_is_missing .git/refs/heads/symref &&
> +	test_ref_exists refs/heads/target &&
> +	test_ref_missing refs/heads/symref &&
>  	test_cmp expect actual
>  '
>  
> @@ -809,16 +812,16 @@ test_expect_success 'deleting a dangling symref' '
>  	test_path_is_file .git/refs/heads/dangling-symref &&
>  	echo "Deleted branch dangling-symref (was nowhere)." >expect &&
>  	git branch -d dangling-symref >actual &&
> -	test_path_is_missing .git/refs/heads/dangling-symref &&
> +	test_ref_missing refs/heads/dangling-symref &&
>  	test_cmp expect actual
>  '
>  
>  test_expect_success 'deleting a self-referential symref' '
>  	git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
> -	test_path_is_file .git/refs/heads/self-reference &&
> +	test_ref_exists refs/heads/self-reference &&
>  	echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
>  	git branch -d self-reference >actual &&
> -	test_path_is_missing .git/refs/heads/self-reference &&
> +	test_ref_missing refs/heads/self-reference &&
>  	test_cmp expect actual
>  '
>  
> @@ -826,8 +829,8 @@ test_expect_success 'renaming a symref is not allowed' '
>  	git symbolic-ref refs/heads/topic refs/heads/main &&
>  	test_must_fail git branch -m topic new-topic &&
>  	git symbolic-ref refs/heads/topic &&
> -	test_path_is_file .git/refs/heads/main &&
> -	test_path_is_missing .git/refs/heads/new-topic
> +	test_ref_exists refs/heads/main &&
> +	test_ref_missing refs/heads/new-topic
>  '
>  
>  test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
> @@ -1142,7 +1145,7 @@ EOF
>  test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
>  	GIT_COMMITTER_DATE="2005-05-26 23:30" \
>  	git checkout -b g/h/i -l main &&
> -	test_path_is_file .git/refs/heads/g/h/i &&
> +	test_ref_exists refs/heads/g/h/i &&
>  	test_path_is_file .git/logs/refs/heads/g/h/i &&
>  	test_cmp expect .git/logs/refs/heads/g/h/i
>  '
> diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
> index 079b2f2536e..3681859f983 100755
> --- a/t/t5521-pull-options.sh
> +++ b/t/t5521-pull-options.sh
> @@ -143,7 +143,7 @@ test_expect_success 'git pull --dry-run' '
>  		cd clonedry &&
>  		git pull --dry-run ../parent &&
>  		test_path_is_missing .git/FETCH_HEAD &&
> -		test_path_is_missing .git/refs/heads/main &&
> +		test_ref_missing refs/heads/main &&
>  		test_path_is_missing .git/index &&
>  		test_path_is_missing file
>  	)
> @@ -157,7 +157,7 @@ test_expect_success 'git pull --all --dry-run' '
>  		git remote add origin ../parent &&
>  		git pull --all --dry-run &&
>  		test_path_is_missing .git/FETCH_HEAD &&
> -		test_path_is_missing .git/refs/remotes/origin/main &&
> +		test_ref_missing refs/remotes/origin/main &&
>  		test_path_is_missing .git/index &&
>  		test_path_is_missing file
>  	)
> diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh
> index 1d7b1abda1a..946c5751885 100755
> --- a/t/t5605-clone-local.sh
> +++ b/t/t5605-clone-local.sh
> @@ -69,7 +69,7 @@ test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
>  	git clone a d &&
>  	(cd d &&
>  	git fetch &&
> -	test ! -e .git/refs/remotes/origin/HEAD)
> +	test_ref_missing refs/remotes/origin/HEAD)
>  '
>  
>  test_expect_success 'bundle clone without .bundle suffix' '
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 12 of 59 in “t: reduce direct disk access to data structures”
  1. 00/11 t: reduce direct disk access to data structuresPatrick Steinhardt, Oct 18, 2023
  2. 01/11 t: add helpers to test for reference existencePatrick Steinhardt, Oct 18, 2023
  3. Junio C HamanoOct 18, 2023
  4. Patrick SteinhardtOct 23, 2023
  5. Eric SunshineOct 18, 2023
  6. Patrick SteinhardtOct 23, 2023
  7. 02/11 t: allow skipping expected object ID in `ref-store update-ref`Patrick Steinhardt, Oct 18, 2023
  8. Junio C HamanoOct 18, 2023
  9. Patrick SteinhardtOct 23, 2023
  10. Junio C HamanoOct 23, 2023
  11. 03/11 t: convert tests to use helpers for reference existencePatrick Steinhardt, Oct 18, 2023
  12. Junio C HamanoOct 18, 2023
  13. 04/11 t: convert tests to not write references via the filesystemPatrick Steinhardt, Oct 18, 2023
  14. Junio C HamanoOct 18, 2023
  15. Patrick SteinhardtOct 23, 2023
  16. Junio C HamanoOct 23, 2023
  17. Junio C HamanoOct 18, 2023
  18. Patrick SteinhardtOct 23, 2023
  19. 05/11 t: convert tests to not access symrefs via the filesystemPatrick Steinhardt, Oct 18, 2023
  20. Junio C HamanoOct 20, 2023
  21. 06/11 t: convert tests to not access reflog via the filesystemPatrick Steinhardt, Oct 18, 2023
  22. Junio C HamanoOct 21, 2023
  23. 07/11 t1450: convert tests to remove worktrees via git-worktree(1)Patrick Steinhardt, Oct 18, 2023
  24. 08/11 t4207: delete replace references via git-update-ref(1)Patrick Steinhardt, Oct 18, 2023
  25. Han-Wen NienhuysOct 18, 2023
  26. Patrick SteinhardtOct 23, 2023
  27. Taylor BlauOct 23, 2023
  28. Patrick SteinhardtOct 24, 2023
  29. 09/11 t7300: assert exact states of repoPatrick Steinhardt, Oct 18, 2023
  30. 10/11 t7900: assert the absence of refs via git-for-each-ref(1)Patrick Steinhardt, Oct 18, 2023
  31. 11/11 t: mark several tests that assume the files backend with REFFILESPatrick Steinhardt, Oct 18, 2023
  32. Patrick SteinhardtOct 18, 2023
  33. Junio C HamanoOct 18, 2023
  34. Patrick SteinhardtOct 23, 2023
  35. Junio C HamanoOct 18, 2023
  36. Han-Wen NienhuysOct 19, 2023
  37. Junio C HamanoOct 19, 2023
  38. Patrick SteinhardtOct 23, 2023
  39. 0/9 t: reduce direct disk access to data structuresPatrick Steinhardt, Oct 24, 2023
  40. 1/9 t: allow skipping expected object ID in `ref-store update-ref`Patrick Steinhardt, Oct 24, 2023
  41. 2/9 t: convert tests to not write references via the filesystemPatrick Steinhardt, Oct 24, 2023
  42. 3/9 t: convert tests to not access symrefs via the filesystemPatrick Steinhardt, Oct 24, 2023
  43. 4/9 t: convert tests to not access reflog via the filesystemPatrick Steinhardt, Oct 24, 2023
  44. 5/9 t1450: convert tests to remove worktrees via git-worktree(1)Patrick Steinhardt, Oct 24, 2023
  45. Eric SunshineOct 27, 2023
  46. 6/9 t4207: delete replace references via git-update-ref(1)Patrick Steinhardt, Oct 24, 2023
  47. 7/9 t7300: assert exact states of repoPatrick Steinhardt, Oct 24, 2023
  48. 8/9 t7900: assert the absence of refs via git-for-each-ref(1)Patrick Steinhardt, Oct 24, 2023
  49. 9/9 t: mark several tests that assume the files backend with REFFILESPatrick Steinhardt, Oct 24, 2023
  50. 0/9 t: reduce direct disk access to data structuresPatrick Steinhardt, Nov 2, 2023
  51. 1/9 t: allow skipping expected object ID in `ref-store update-ref`Patrick Steinhardt, Nov 2, 2023
  52. 2/9 t: convert tests to not write references via the filesystemPatrick Steinhardt, Nov 2, 2023
  53. 3/9 t: convert tests to not access symrefs via the filesystemPatrick Steinhardt, Nov 2, 2023
  54. 4/9 t: convert tests to not access reflog via the filesystemPatrick Steinhardt, Nov 2, 2023
  55. 5/9 t1450: convert tests to remove worktrees via git-worktree(1)Patrick Steinhardt, Nov 2, 2023
  56. 6/9 t4207: delete replace references via git-update-ref(1)Patrick Steinhardt, Nov 2, 2023
  57. 7/9 t7300: assert exact states of repoPatrick Steinhardt, Nov 2, 2023
  58. 8/9 t7900: assert the absence of refs via git-for-each-ref(1)Patrick Steinhardt, Nov 2, 2023
  59. 9/9 t: mark several tests that assume the files backend with REFFILESPatrick Steinhardt, Nov 2, 2023

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.