diff mbox series

[v3,01/10] cache-tree tests: refactor for modern test style

Message ID 20210123130046.21975-2-avarab@gmail.com (mailing list archive)
State Accepted
Commit 3f96d75ef548039632d48552d0e6bc4435b2382b
Headers show
Series [v3,01/10] cache-tree tests: refactor for modern test style | expand

Commit Message

Ævar Arnfjörð Bjarmason Jan. 23, 2021, 1 p.m. UTC
Refactor the cache-tree test file to use our current recommended
patterns. This makes a subsequent meaningful change easier to read.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0090-cache-tree.sh | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

Comments

Junio C Hamano Jan. 23, 2021, 9:34 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
> index 5a633690bf..45e1cc82ed 100755
> --- a/t/t0090-cache-tree.sh
> +++ b/t/t0090-cache-tree.sh
> @@ -10,7 +10,8 @@ cache-tree extension.
>  cmp_cache_tree () {
>  	test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual &&
>  	sed "s/$OID_REGEX/SHA/" <actual >filtered &&
> -	test_cmp "$1" filtered
> +	test_cmp "$1" filtered &&
> +	rm filtered
>  }

OK.  Cleaning after itself is good, and not cleaning when there is
an error is probably a bit more helpful to those who debug, but I
think test_cmp would give them enough to work on.  A failure to
remove filtered at the end CAN mistakenly make the caller to think
that the expected output was not obtained, though.

> @@ -83,18 +84,6 @@ test_expect_success 'git-add in subdir invalidates cache-tree' '
>  	test_invalid_cache_tree
>  '
>  
> -cat >before <<\EOF
> -SHA  (3 entries, 2 subtrees)
> -SHA dir1/ (1 entries, 0 subtrees)
> -SHA dir2/ (1 entries, 0 subtrees)
> -EOF
> -
> -cat >expect <<\EOF
> -invalid                                   (2 subtrees)
> -invalid                                  dir1/ (0 subtrees)
> -SHA dir2/ (1 entries, 0 subtrees)
> -EOF
> -
>  test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
>  	git tag no-children &&
>  	test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
> @@ -102,9 +91,20 @@ test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
>  	test_commit dir1/a &&
>  	test_commit dir2/b &&
>  	echo "I changed this file" >dir1/a &&
> +	test_when_finished "rm before" &&
> +	cat >before <<-\EOF &&
> +	SHA  (3 entries, 2 subtrees)
> +	SHA dir1/ (1 entries, 0 subtrees)
> +	SHA dir2/ (1 entries, 0 subtrees)
> +	EOF
>  	cmp_cache_tree before &&
>  	echo "I changed this file" >dir1/a &&
>  	git add dir1/a &&
> +	cat >expect <<-\EOF &&
> +	invalid                                   (2 subtrees)
> +	invalid                                  dir1/ (0 subtrees)
> +	SHA dir2/ (1 entries, 0 subtrees)
> +	EOF
>  	cmp_cache_tree expect
>  '

Why remove only 'before' and not 'expect' in when-finished handler?
diff mbox series

Patch

diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 5a633690bf..45e1cc82ed 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -10,7 +10,8 @@  cache-tree extension.
 cmp_cache_tree () {
 	test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual &&
 	sed "s/$OID_REGEX/SHA/" <actual >filtered &&
-	test_cmp "$1" filtered
+	test_cmp "$1" filtered &&
+	rm filtered
 }
 
 # We don't bother with actually checking the SHA1:
@@ -54,7 +55,7 @@  test_invalid_cache_tree () {
 }
 
 test_no_cache_tree () {
-	: >expect &&
+	>expect &&
 	cmp_cache_tree expect
 }
 
@@ -83,18 +84,6 @@  test_expect_success 'git-add in subdir invalidates cache-tree' '
 	test_invalid_cache_tree
 '
 
-cat >before <<\EOF
-SHA  (3 entries, 2 subtrees)
-SHA dir1/ (1 entries, 0 subtrees)
-SHA dir2/ (1 entries, 0 subtrees)
-EOF
-
-cat >expect <<\EOF
-invalid                                   (2 subtrees)
-invalid                                  dir1/ (0 subtrees)
-SHA dir2/ (1 entries, 0 subtrees)
-EOF
-
 test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
 	git tag no-children &&
 	test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
@@ -102,9 +91,20 @@  test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
 	test_commit dir1/a &&
 	test_commit dir2/b &&
 	echo "I changed this file" >dir1/a &&
+	test_when_finished "rm before" &&
+	cat >before <<-\EOF &&
+	SHA  (3 entries, 2 subtrees)
+	SHA dir1/ (1 entries, 0 subtrees)
+	SHA dir2/ (1 entries, 0 subtrees)
+	EOF
 	cmp_cache_tree before &&
 	echo "I changed this file" >dir1/a &&
 	git add dir1/a &&
+	cat >expect <<-\EOF &&
+	invalid                                   (2 subtrees)
+	invalid                                  dir1/ (0 subtrees)
+	SHA dir2/ (1 entries, 0 subtrees)
+	EOF
 	cmp_cache_tree expect
 '