cache-tree tests: refactor for modern test style

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 23, 2021 at 14:00 UTC 3f96d75ef548039632d48552d0e6bc4435b2382b
1 file changed +14 -14
t/t0090-cache-tree.sh
+14 -14
@@ -10,7 +10,8 @@ cache-tree extension.
10 cmp_cache_tree () {
11 test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual &&
12 sed "s/$OID_REGEX/SHA/" <actual >filtered &&
13 - test_cmp "$1" filtered
13 + test_cmp "$1" filtered &&
14 + rm filtered
15 }
16
17 # We don't bother with actually checking the SHA1:
@@ -54,7 +55,7 @@ test_invalid_cache_tree () {
55 }
56
57 test_no_cache_tree () {
57 - : >expect &&
58 + >expect &&
59 cmp_cache_tree expect
60 }
61
@@ -83,18 +84,6 @@ test_expect_success 'git-add in subdir invalidates cache-tree' '
84 test_invalid_cache_tree
85 '
86
86 -cat >before <<\EOF
87 -SHA (3 entries, 2 subtrees)
88 -SHA dir1/ (1 entries, 0 subtrees)
89 -SHA dir2/ (1 entries, 0 subtrees)
90 -EOF
91 -
92 -cat >expect <<\EOF
93 -invalid (2 subtrees)
94 -invalid dir1/ (0 subtrees)
95 -SHA dir2/ (1 entries, 0 subtrees)
96 -EOF
97 -
87 test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
88 git tag no-children &&
89 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' '
91 test_commit dir1/a &&
92 test_commit dir2/b &&
93 echo "I changed this file" >dir1/a &&
94 + test_when_finished "rm before" &&
95 + cat >before <<-\EOF &&
96 + SHA (3 entries, 2 subtrees)
97 + SHA dir1/ (1 entries, 0 subtrees)
98 + SHA dir2/ (1 entries, 0 subtrees)
99 + EOF
100 cmp_cache_tree before &&
101 echo "I changed this file" >dir1/a &&
102 git add dir1/a &&
103 + cat >expect <<-\EOF &&
104 + invalid (2 subtrees)
105 + invalid dir1/ (0 subtrees)
106 + SHA dir2/ (1 entries, 0 subtrees)
107 + EOF
108 cmp_cache_tree expect
109 '
110