t6010 (merge-base): modernize style
Guard setup with test_expect_success, put the opening quote starting each test on the same line as the test_expect_* invocation, and combine related actions into single tests. While at it: - use test_cmp instead of expr or test $foo = $bar, for more helpful output with -v when tests fail; - use test_commit for brevity. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 17, 2010 at 01:57 UTC
9cbdd76e097b01fa434dec9fdbe73b9cb6361e26
1 file changed
+160
-143
t/t6010-merge-base.sh
+160
-143
@@ -8,170 +8,187 @@ test_description='Merge base computation.
8
9
. ./test-lib.sh
10
11
-T=$(git write-tree)
12
-
13
-M=1130000000
14
-Z=+0000
15
-
16
-GIT_COMMITTER_EMAIL=git@comm.iter.xz
17
-GIT_COMMITTER_NAME='C O Mmiter'
18
-GIT_AUTHOR_NAME='A U Thor'
19
-GIT_AUTHOR_EMAIL=git@au.thor.xz
20
-export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
21
-
22
-doit() {
23
- OFFSET=$1; shift
24
- NAME=$1; shift
25
- PARENTS=
26
- for P
27
- do
28
- PARENTS="${PARENTS}-p $P "
29
- done
30
- GIT_COMMITTER_DATE="$(($M + $OFFSET)) $Z"
31
- GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE
32
- export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
33
- commit=$(echo $NAME | git commit-tree $T $PARENTS)
34
- echo $commit >.git/refs/tags/$NAME
35
- echo $commit
36
-}
37
-
38
-# E---D---C---B---A
39
-# \'-_ \ \
40
-# \ `---------G \
41
-# \ \
42
-# F----------------H
43
-
44
-# Setup...
45
-E=$(doit 5 E)
46
-D=$(doit 4 D $E)
47
-F=$(doit 6 F $E)
48
-C=$(doit 3 C $D)
49
-B=$(doit 2 B $C)
50
-A=$(doit 1 A $B)
51
-G=$(doit 7 G $B $E)
52
-H=$(doit 8 H $A $F)
53
-
54
-test_expect_success 'compute merge-base (single)' \
55
- 'MB=$(git merge-base G H) &&
56
- expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
57
-
58
-test_expect_success 'compute merge-base (all)' \
59
- 'MB=$(git merge-base --all G H) &&
60
- expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
61
-
62
-test_expect_success 'compute merge-base with show-branch' \
63
- 'MB=$(git show-branch --merge-base G H) &&
64
- expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
65
-
66
-# Setup for second test to demonstrate that relying on timestamps in a
67
-# distributed SCM to provide a _consistent_ partial ordering of commits
68
-# leads to insanity.
69
-#
70
-# Relative
71
-# Structure timestamps
72
-#
73
-# PL PR +4 +4
74
-# / \/ \ / \/ \
75
-# L2 C2 R2 +3 -1 +3
76
-# | | | | | |
77
-# L1 C1 R1 +2 -2 +2
78
-# | | | | | |
79
-# L0 C0 R0 +1 -3 +1
80
-# \ | / \ | /
81
-# S 0
82
-#
83
-# The left and right chains of commits can be of any length and complexity as
84
-# long as all of the timestamps are greater than that of S.
85
-
86
-S=$(doit 0 S)
87
-
88
-C0=$(doit -3 C0 $S)
89
-C1=$(doit -2 C1 $C0)
90
-C2=$(doit -1 C2 $C1)
11
+test_expect_success 'setup' '
12
+ T=$(git write-tree) &&
13
+
14
+ M=1130000000 &&
15
+ Z=+0000 &&
16
+
17
+ GIT_COMMITTER_EMAIL=git@comm.iter.xz &&
18
+ GIT_COMMITTER_NAME="C O Mmiter" &&
19
+ GIT_AUTHOR_NAME="A U Thor" &&
20
+ GIT_AUTHOR_EMAIL=git@au.thor.xz &&
21
+ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
22
+
23
+ doit() {
24
+ OFFSET=$1 &&
25
+ NAME=$2 &&
26
+ shift 2 &&
27
+
28
+ PARENTS= &&
29
+ for P
30
+ do
31
+ PARENTS="${PARENTS}-p $P "
32
+ done &&
33
+
34
+ GIT_COMMITTER_DATE="$(($M + $OFFSET)) $Z" &&
35
+ GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE &&
36
+ export GIT_COMMITTER_DATE GIT_AUTHOR_DATE &&
37
+
38
+ commit=$(echo $NAME | git commit-tree $T $PARENTS) &&
39
+
40
+ echo $commit >.git/refs/tags/$NAME &&
41
+ echo $commit
42
+ }
43
+'
44
92
-L0=$(doit 1 L0 $S)
93
-L1=$(doit 2 L1 $L0)
94
-L2=$(doit 3 L2 $L1)
45
+test_expect_success 'set up G and H' '
46
+ # E---D---C---B---A
47
+ # \"-_ \ \
48
+ # \ `---------G \
49
+ # \ \
50
+ # F----------------H
51
+ E=$(doit 5 E) &&
52
+ D=$(doit 4 D $E) &&
53
+ F=$(doit 6 F $E) &&
54
+ C=$(doit 3 C $D) &&
55
+ B=$(doit 2 B $C) &&
56
+ A=$(doit 1 A $B) &&
57
+ G=$(doit 7 G $B $E) &&
58
+ H=$(doit 8 H $A $F)
59
+'
60
96
-R0=$(doit 1 R0 $S)
97
-R1=$(doit 2 R1 $R0)
98
-R2=$(doit 3 R2 $R1)
61
+test_expect_success 'merge-base G H' '
62
+ git name-rev $B >expected &&
63
100
-PL=$(doit 4 PL $L2 $C2)
101
-PR=$(doit 4 PR $C2 $R2)
64
+ MB=$(git merge-base G H) &&
65
+ git name-rev "$MB" >actual.single &&
66
103
-test_expect_success 'compute merge-base (single)' \
104
- 'MB=$(git merge-base PL PR) &&
105
- expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
67
+ MB=$(git merge-base --all G H) &&
68
+ git name-rev "$MB" >actual.all &&
69
107
-test_expect_success 'compute merge-base (all)' \
108
- 'MB=$(git merge-base --all PL PR) &&
109
- expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
70
+ MB=$(git show-branch --merge-base G H) &&
71
+ git name-rev "$MB" >actual.sb &&
72
111
-# Another set to demonstrate base between one commit and a merge
112
-# in the documentation.
113
-#
114
-# * C (MMC) * B (MMB) * A (MMA)
115
-# * o * o * o
116
-# * o * o * o
117
-# * o * o * o
118
-# * o | _______/
119
-# | |/
120
-# | * 1 (MM1)
121
-# | _______/
122
-# |/
123
-# * root (MMR)
73
+ test_cmp expected actual.single &&
74
+ test_cmp expected actual.all &&
75
+ test_cmp expected actual.sb
76
+'
77
78
+test_expect_success 'unsynchronized clocks' '
79
+ # This test is to demonstrate that relying on timestamps in a distributed
80
+ # SCM to provide a _consistent_ partial ordering of commits leads to
81
+ # insanity.
82
+ #
83
+ # Relative
84
+ # Structure timestamps
85
+ #
86
+ # PL PR +4 +4
87
+ # / \/ \ / \/ \
88
+ # L2 C2 R2 +3 -1 +3
89
+ # | | | | | |
90
+ # L1 C1 R1 +2 -2 +2
91
+ # | | | | | |
92
+ # L0 C0 R0 +1 -3 +1
93
+ # \ | / \ | /
94
+ # S 0
95
+ #
96
+ # The left and right chains of commits can be of any length and complexity as
97
+ # long as all of the timestamps are greater than that of S.
98
+
99
+ S=$(doit 0 S) &&
100
+
101
+ C0=$(doit -3 C0 $S) &&
102
+ C1=$(doit -2 C1 $C0) &&
103
+ C2=$(doit -1 C2 $C1) &&
104
+
105
+ L0=$(doit 1 L0 $S) &&
106
+ L1=$(doit 2 L1 $L0) &&
107
+ L2=$(doit 3 L2 $L1) &&
108
+
109
+ R0=$(doit 1 R0 $S) &&
110
+ R1=$(doit 2 R1 $R0) &&
111
+ R2=$(doit 3 R2 $R1) &&
112
+
113
+ PL=$(doit 4 PL $L2 $C2) &&
114
+ PR=$(doit 4 PR $C2 $R2)
115
+
116
+ git name-rev $C2 >expected &&
117
+
118
+ MB=$(git merge-base PL PR) &&
119
+ git name-rev "$MB" >actual.single &&
120
+
121
+ MB=$(git merge-base --all PL PR) &&
122
+ git name-rev "$MB" >actual.all &&
123
+
124
+ test_cmp expected actual.single &&
125
+ test_cmp expected actual.all
126
+'
127
128
test_expect_success 'merge-base for octopus-step (setup)' '
127
- test_tick && git commit --allow-empty -m root && git tag MMR &&
128
- test_tick && git commit --allow-empty -m 1 && git tag MM1 &&
129
- test_tick && git commit --allow-empty -m o &&
130
- test_tick && git commit --allow-empty -m o &&
131
- test_tick && git commit --allow-empty -m o &&
132
- test_tick && git commit --allow-empty -m A && git tag MMA &&
129
+ # Another set to demonstrate base between one commit and a merge
130
+ # in the documentation.
131
+ #
132
+ # * C (MMC) * B (MMB) * A (MMA)
133
+ # * o * o * o
134
+ # * o * o * o
135
+ # * o * o * o
136
+ # * o | _______/
137
+ # | |/
138
+ # | * 1 (MM1)
139
+ # | _______/
140
+ # |/
141
+ # * root (MMR)
142
+
143
+ test_commit MMR &&
144
+ test_commit MM1 &&
145
+ test_commit MM-o &&
146
+ test_commit MM-p &&
147
+ test_commit MM-q &&
148
+ test_commit MMA &&
149
git checkout MM1 &&
134
- test_tick && git commit --allow-empty -m o &&
135
- test_tick && git commit --allow-empty -m o &&
136
- test_tick && git commit --allow-empty -m o &&
137
- test_tick && git commit --allow-empty -m B && git tag MMB &&
150
+ test_commit MM-r &&
151
+ test_commit MM-s &&
152
+ test_commit MM-t &&
153
+ test_commit MMB &&
154
git checkout MMR &&
139
- test_tick && git commit --allow-empty -m o &&
140
- test_tick && git commit --allow-empty -m o &&
141
- test_tick && git commit --allow-empty -m o &&
142
- test_tick && git commit --allow-empty -m o &&
143
- test_tick && git commit --allow-empty -m C && git tag MMC
155
+ test_commit MM-u &&
156
+ test_commit MM-v &&
157
+ test_commit MM-w &&
158
+ test_commit MM-x &&
159
+ test_commit MMC
160
'
161
162
test_expect_success 'merge-base A B C' '
147
- MB=$(git merge-base --all MMA MMB MMC) &&
148
- MM1=$(git rev-parse --verify MM1) &&
149
- test "$MM1" = "$MB"
150
-'
163
+ git rev-parse --verify MM1 >expected &&
164
+ git rev-parse --verify MMR >expected.sb &&
165
152
-test_expect_success 'merge-base A B C using show-branch' '
153
- MB=$(git show-branch --merge-base MMA MMB MMC) &&
154
- MMR=$(git rev-parse --verify MMR) &&
155
- test "$MMR" = "$MB"
166
+ git merge-base --all MMA MMB MMC >actual &&
167
+ git show-branch --merge-base MMA MMB MMC >actual.sb &&
168
+
169
+ test_cmp expected actual &&
170
+ test_cmp expected.sb actual.sb
171
'
172
158
-test_expect_success 'criss-cross merge-base for octopus-step (setup)' '
173
+test_expect_success 'criss-cross merge-base for octopus-step' '
174
git reset --hard MMR &&
160
- test_tick && git commit --allow-empty -m 1 && git tag CC1 &&
175
+ test_commit CC1 &&
176
git reset --hard E &&
162
- test_tick && git commit --allow-empty -m 2 && git tag CC2 &&
163
- test_tick && git merge -s ours CC1 &&
164
- test_tick && git commit --allow-empty -m o &&
165
- test_tick && git commit --allow-empty -m B && git tag CCB &&
177
+ test_commit CC2 &&
178
+ test_tick &&
179
+ git merge -s ours CC1 &&
180
+ test_commit CC-o &&
181
+ test_commit CCB &&
182
git reset --hard CC1 &&
167
- test_tick && git merge -s ours CC2 &&
168
- test_tick && git commit --allow-empty -m A && git tag CCA
169
-'
183
+ git merge -s ours CC2 &&
184
+ test_commit CCA &&
185
+
186
+ git rev-parse CC1 CC2 >expected &&
187
+ git merge-base --all CCB CCA^^ CCA^^2 >actual &&
188
171
-test_expect_success 'merge-base B A^^ A^^2' '
172
- MB0=$(git merge-base --all CCB CCA^^ CCA^^2 | sort) &&
173
- MB1=$(git rev-parse CC1 CC2 | sort) &&
174
- test "$MB0" = "$MB1"
189
+ sort expected >expected.sorted &&
190
+ sort actual >actual.sorted &&
191
+ test_cmp expected.sorted actual.sorted
192
'
193
194
test_done