t6016: move to lib-log-graph.sh framework

t6016 manually reconstructs git log --graph output by using the reported commit hashes from `git rev-parse`. Each tag is converted into an environment variable manually, and then `echo`-ed to an expected output file, which is in turn compared to the actual output. The expected output is difficult to read and write, because, e.g., each line of output must be prefaced with echo, quoted, and properly escaped. Additionally, the test is sensitive to trailing whitespace, which may potentially be removed from graph log output in the future. In order to reduce duplication, ease troubleshooting of failed tests by improving readability, and ease the addition of more tests to this file, port the operations to `lib-log-graph.sh`, which is already used in several other tests, e.g., t4215. Give all merges a simple commit message, and use a common `check_graph` macro taking a heredoc of the expected output which does not required extensive escaping. Signed-off-by: Antonio Russo <aerusso@aerusso.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Antonio Russo committed Jan 3, 2021 at 19:30 UTC c8302c6c0027fb8714106b9365f3443a2d233f44
1 file changed +167 -187
t/t6016-rev-list-graph-simplify-history.sh
+167 -187
@@ -8,6 +8,12 @@
8 test_description='--graph and simplified history'
9
10 . ./test-lib.sh
11 +. "$TEST_DIRECTORY"/lib-log-graph.sh
12 +
13 +check_graph () {
14 + cat >expect &&
15 + lib_test_cmp_graph --format=%s "$@"
16 +}
17
18 test_expect_success 'set up rev-list --graph test' '
19 # 3 commits on branch A
@@ -28,7 +34,7 @@ test_expect_success 'set up rev-list --graph test' '
34
35 # Octopus merge B and C into branch A
36 git checkout A &&
31 - git merge B C &&
37 + git merge B C -m A4 &&
38 git tag A4 &&
39
40 test_commit A5 bar.txt &&
@@ -38,81 +44,64 @@ test_expect_success 'set up rev-list --graph test' '
44 test_commit C3 foo.txt &&
45 test_commit C4 bar.txt &&
46 git checkout A &&
41 - git merge -s ours C &&
47 + git merge -s ours C -m A6 &&
48 git tag A6 &&
49
44 - test_commit A7 bar.txt &&
45 -
46 - # Store commit names in variables for later use
47 - A1=$(git rev-parse --verify A1) &&
48 - A2=$(git rev-parse --verify A2) &&
49 - A3=$(git rev-parse --verify A3) &&
50 - A4=$(git rev-parse --verify A4) &&
51 - A5=$(git rev-parse --verify A5) &&
52 - A6=$(git rev-parse --verify A6) &&
53 - A7=$(git rev-parse --verify A7) &&
54 - B1=$(git rev-parse --verify B1) &&
55 - B2=$(git rev-parse --verify B2) &&
56 - C1=$(git rev-parse --verify C1) &&
57 - C2=$(git rev-parse --verify C2) &&
58 - C3=$(git rev-parse --verify C3) &&
59 - C4=$(git rev-parse --verify C4)
60 - '
50 + test_commit A7 bar.txt
51 +'
52
53 test_expect_success '--graph --all' '
63 - rm -f expected &&
64 - echo "* $A7" >> expected &&
65 - echo "* $A6" >> expected &&
66 - echo "|\\ " >> expected &&
67 - echo "| * $C4" >> expected &&
68 - echo "| * $C3" >> expected &&
69 - echo "* | $A5" >> expected &&
70 - echo "| | " >> expected &&
71 - echo "| \\ " >> expected &&
72 - echo "*-. | $A4" >> expected &&
73 - echo "|\\ \\| " >> expected &&
74 - echo "| | * $C2" >> expected &&
75 - echo "| | * $C1" >> expected &&
76 - echo "| * | $B2" >> expected &&
77 - echo "| * | $B1" >> expected &&
78 - echo "* | | $A3" >> expected &&
79 - echo "| |/ " >> expected &&
80 - echo "|/| " >> expected &&
81 - echo "* | $A2" >> expected &&
82 - echo "|/ " >> expected &&
83 - echo "* $A1" >> expected &&
84 - git rev-list --graph --all > actual &&
85 - test_cmp expected actual
86 - '
54 + check_graph --all <<-\EOF
55 + * A7
56 + * A6
57 + |\
58 + | * C4
59 + | * C3
60 + * | A5
61 + | |
62 + | \
63 + *-. | A4
64 + |\ \|
65 + | | * C2
66 + | | * C1
67 + | * | B2
68 + | * | B1
69 + * | | A3
70 + | |/
71 + |/|
72 + * | A2
73 + |/
74 + * A1
75 + EOF
76 +'
77
78 # Make sure the graph_is_interesting() code still realizes
79 # that undecorated merges are interesting, even with --simplify-by-decoration
80 test_expect_success '--graph --simplify-by-decoration' '
91 - rm -f expected &&
81 git tag -d A4 &&
93 - echo "* $A7" >> expected &&
94 - echo "* $A6" >> expected &&
95 - echo "|\\ " >> expected &&
96 - echo "| * $C4" >> expected &&
97 - echo "| * $C3" >> expected &&
98 - echo "* | $A5" >> expected &&
99 - echo "| | " >> expected &&
100 - echo "| \\ " >> expected &&
101 - echo "*-. | $A4" >> expected &&
102 - echo "|\\ \\| " >> expected &&
103 - echo "| | * $C2" >> expected &&
104 - echo "| | * $C1" >> expected &&
105 - echo "| * | $B2" >> expected &&
106 - echo "| * | $B1" >> expected &&
107 - echo "* | | $A3" >> expected &&
108 - echo "| |/ " >> expected &&
109 - echo "|/| " >> expected &&
110 - echo "* | $A2" >> expected &&
111 - echo "|/ " >> expected &&
112 - echo "* $A1" >> expected &&
113 - git rev-list --graph --all --simplify-by-decoration > actual &&
114 - test_cmp expected actual
115 - '
82 + check_graph --all --simplify-by-decoration <<-\EOF
83 + * A7
84 + * A6
85 + |\
86 + | * C4
87 + | * C3
88 + * | A5
89 + | |
90 + | \
91 + *-. | A4
92 + |\ \|
93 + | | * C2
94 + | | * C1
95 + | * | B2
96 + | * | B1
97 + * | | A3
98 + | |/
99 + |/|
100 + * | A2
101 + |/
102 + * A1
103 + EOF
104 +'
105
106 test_expect_success 'setup: get rid of decorations on B' '
107 git tag -d B2 &&
@@ -122,142 +111,133 @@ test_expect_success 'setup: get rid of decorations on B' '
111
112 # Graph with branch B simplified away
113 test_expect_success '--graph --simplify-by-decoration prune branch B' '
125 - rm -f expected &&
126 - echo "* $A7" >> expected &&
127 - echo "* $A6" >> expected &&
128 - echo "|\\ " >> expected &&
129 - echo "| * $C4" >> expected &&
130 - echo "| * $C3" >> expected &&
131 - echo "* | $A5" >> expected &&
132 - echo "* | $A4" >> expected &&
133 - echo "|\\| " >> expected &&
134 - echo "| * $C2" >> expected &&
135 - echo "| * $C1" >> expected &&
136 - echo "* | $A3" >> expected &&
137 - echo "|/ " >> expected &&
138 - echo "* $A2" >> expected &&
139 - echo "* $A1" >> expected &&
140 - git rev-list --graph --simplify-by-decoration --all > actual &&
141 - test_cmp expected actual
142 - '
114 + check_graph --simplify-by-decoration --all <<-\EOF
115 + * A7
116 + * A6
117 + |\
118 + | * C4
119 + | * C3
120 + * | A5
121 + * | A4
122 + |\|
123 + | * C2
124 + | * C1
125 + * | A3
126 + |/
127 + * A2
128 + * A1
129 + EOF
130 +'
131
132 test_expect_success '--graph --full-history -- bar.txt' '
145 - rm -f expected &&
146 - echo "* $A7" >> expected &&
147 - echo "* $A6" >> expected &&
148 - echo "|\\ " >> expected &&
149 - echo "| * $C4" >> expected &&
150 - echo "* | $A5" >> expected &&
151 - echo "* | $A4" >> expected &&
152 - echo "|\\| " >> expected &&
153 - echo "* | $A3" >> expected &&
154 - echo "|/ " >> expected &&
155 - echo "* $A2" >> expected &&
156 - git rev-list --graph --full-history --all -- bar.txt > actual &&
157 - test_cmp expected actual
158 - '
133 + check_graph --full-history --all -- bar.txt <<-\EOF
134 + * A7
135 + * A6
136 + |\
137 + | * C4
138 + * | A5
139 + * | A4
140 + |\|
141 + * | A3
142 + |/
143 + * A2
144 + EOF
145 +'
146
147 test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
161 - rm -f expected &&
162 - echo "* $A7" >> expected &&
163 - echo "* $A6" >> expected &&
164 - echo "|\\ " >> expected &&
165 - echo "| * $C4" >> expected &&
166 - echo "* | $A5" >> expected &&
167 - echo "* | $A3" >> expected &&
168 - echo "|/ " >> expected &&
169 - echo "* $A2" >> expected &&
170 - git rev-list --graph --full-history --simplify-merges --all \
171 - -- bar.txt > actual &&
172 - test_cmp expected actual
173 - '
148 + check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF
149 + * A7
150 + * A6
151 + |\
152 + | * C4
153 + * | A5
154 + * | A3
155 + |/
156 + * A2
157 + EOF
158 +'
159
160 test_expect_success '--graph -- bar.txt' '
176 - rm -f expected &&
177 - echo "* $A7" >> expected &&
178 - echo "* $A5" >> expected &&
179 - echo "* $A3" >> expected &&
180 - echo "| * $C4" >> expected &&
181 - echo "|/ " >> expected &&
182 - echo "* $A2" >> expected &&
183 - git rev-list --graph --all -- bar.txt > actual &&
184 - test_cmp expected actual
185 - '
161 + check_graph --all -- bar.txt <<-\EOF
162 + * A7
163 + * A5
164 + * A3
165 + | * C4
166 + |/
167 + * A2
168 + EOF
169 +'
170
171 test_expect_success '--graph --sparse -- bar.txt' '
188 - rm -f expected &&
189 - echo "* $A7" >> expected &&
190 - echo "* $A6" >> expected &&
191 - echo "* $A5" >> expected &&
192 - echo "* $A4" >> expected &&
193 - echo "* $A3" >> expected &&
194 - echo "| * $C4" >> expected &&
195 - echo "| * $C3" >> expected &&
196 - echo "| * $C2" >> expected &&
197 - echo "| * $C1" >> expected &&
198 - echo "|/ " >> expected &&
199 - echo "* $A2" >> expected &&
200 - echo "* $A1" >> expected &&
201 - git rev-list --graph --sparse --all -- bar.txt > actual &&
202 - test_cmp expected actual
203 - '
172 + check_graph --sparse --all -- bar.txt <<-\EOF
173 + * A7
174 + * A6
175 + * A5
176 + * A4
177 + * A3
178 + | * C4
179 + | * C3
180 + | * C2
181 + | * C1
182 + |/
183 + * A2
184 + * A1
185 + EOF
186 +'
187
188 test_expect_success '--graph ^C4' '
206 - rm -f expected &&
207 - echo "* $A7" >> expected &&
208 - echo "* $A6" >> expected &&
209 - echo "* $A5" >> expected &&
210 - echo "* $A4" >> expected &&
211 - echo "|\\ " >> expected &&
212 - echo "| * $B2" >> expected &&
213 - echo "| * $B1" >> expected &&
214 - echo "* $A3" >> expected &&
215 - git rev-list --graph --all ^C4 > actual &&
216 - test_cmp expected actual
217 - '
189 + check_graph --all ^C4 <<-\EOF
190 + * A7
191 + * A6
192 + * A5
193 + * A4
194 + |\
195 + | * B2
196 + | * B1
197 + * A3
198 + EOF
199 +'
200
201 test_expect_success '--graph ^C3' '
220 - rm -f expected &&
221 - echo "* $A7" >> expected &&
222 - echo "* $A6" >> expected &&
223 - echo "|\\ " >> expected &&
224 - echo "| * $C4" >> expected &&
225 - echo "* $A5" >> expected &&
226 - echo "* $A4" >> expected &&
227 - echo "|\\ " >> expected &&
228 - echo "| * $B2" >> expected &&
229 - echo "| * $B1" >> expected &&
230 - echo "* $A3" >> expected &&
231 - git rev-list --graph --all ^C3 > actual &&
232 - test_cmp expected actual
233 - '
202 + check_graph --all ^C3 <<-\EOF
203 + * A7
204 + * A6
205 + |\
206 + | * C4
207 + * A5
208 + * A4
209 + |\
210 + | * B2
211 + | * B1
212 + * A3
213 + EOF
214 +'
215
216 # I don't think the ordering of the boundary commits is really
217 # that important, but this test depends on it. If the ordering ever changes
218 # in the code, we'll need to update this test.
219 test_expect_success '--graph --boundary ^C3' '
239 - rm -f expected &&
240 - echo "* $A7" >> expected &&
241 - echo "* $A6" >> expected &&
242 - echo "|\\ " >> expected &&
243 - echo "| * $C4" >> expected &&
244 - echo "* | $A5" >> expected &&
245 - echo "| | " >> expected &&
246 - echo "| \\ " >> expected &&
247 - echo "*-. \\ $A4" >> expected &&
248 - echo "|\\ \\ \\ " >> expected &&
249 - echo "| * | | $B2" >> expected &&
250 - echo "| * | | $B1" >> expected &&
251 - echo "* | | | $A3" >> expected &&
252 - echo "o | | | $A2" >> expected &&
253 - echo "|/ / / " >> expected &&
254 - echo "o / / $A1" >> expected &&
255 - echo " / / " >> expected &&
256 - echo "| o $C3" >> expected &&
257 - echo "|/ " >> expected &&
258 - echo "o $C2" >> expected &&
259 - git rev-list --graph --boundary --all ^C3 > actual &&
260 - test_cmp expected actual
261 - '
220 + check_graph --boundary --all ^C3 <<-\EOF
221 + * A7
222 + * A6
223 + |\
224 + | * C4
225 + * | A5
226 + | |
227 + | \
228 + *-. \ A4
229 + |\ \ \
230 + | * | | B2
231 + | * | | B1
232 + * | | | A3
233 + o | | | A2
234 + |/ / /
235 + o / / A1
236 + / /
237 + | o C3
238 + |/
239 + o C2
240 + EOF
241 +'
242
243 test_done