Skip to content

Commit e1e7a77

Browse files
peffgitster
authored andcommitted
t: sort output of hashmap iteration
The iteration order of a hashmap is undefined, and may depend on things like the exact set of items added, or the table has been grown or shrunk. In the case of an oidmap, it even depends on endianness, because we take the oid hash by casting sha1 bytes directly into an unsigned int. Let's sort the test-tool output from any hash iterators. In the case of t0011, this is just future-proofing. But for t0016, it actually fixes a reported failure on the big-endian s390 and nonstop ports. I didn't bother to teach the helper functions to optionally sort output. They are short enough that it's simpler to just repeat them inline for the iteration tests than it is to add a --sort option. Reported-by: Randall S. Becker <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 026dd73 commit e1e7a77

File tree

2 files changed

+55
-33
lines changed

2 files changed

+55
-33
lines changed

t/t0011-hashmap.sh

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,31 +170,45 @@ NULL
170170
'
171171

172172
test_expect_success 'iterate' '
173-
174-
test_hashmap "put key1 value1
175-
put key2 value2
176-
put fooBarFrotz value3
177-
iterate" "NULL
178-
NULL
179-
NULL
180-
key2 value2
181-
key1 value1
182-
fooBarFrotz value3"
183-
173+
test-tool hashmap >actual.raw <<-\EOF &&
174+
put key1 value1
175+
put key2 value2
176+
put fooBarFrotz value3
177+
iterate
178+
EOF
179+
180+
cat >expect <<-\EOF &&
181+
NULL
182+
NULL
183+
NULL
184+
fooBarFrotz value3
185+
key1 value1
186+
key2 value2
187+
EOF
188+
189+
sort <actual.raw >actual &&
190+
test_cmp expect actual
184191
'
185192

186193
test_expect_success 'iterate (case insensitive)' '
187-
188-
test_hashmap "put key1 value1
189-
put key2 value2
190-
put fooBarFrotz value3
191-
iterate" "NULL
192-
NULL
193-
NULL
194-
fooBarFrotz value3
195-
key2 value2
196-
key1 value1" ignorecase
197-
194+
test-tool hashmap ignorecase >actual.raw <<-\EOF &&
195+
put key1 value1
196+
put key2 value2
197+
put fooBarFrotz value3
198+
iterate
199+
EOF
200+
201+
cat >expect <<-\EOF &&
202+
NULL
203+
NULL
204+
NULL
205+
fooBarFrotz value3
206+
key1 value1
207+
key2 value2
208+
EOF
209+
210+
sort <actual.raw >actual &&
211+
test_cmp expect actual
198212
'
199213

200214
test_expect_success 'grow / shrink' '

t/t0016-oidmap.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,25 @@ NULL"
8686
'
8787

8888
test_expect_success 'iterate' '
89-
90-
test_oidmap "put one 1
91-
put two 2
92-
put three 3
93-
iterate" "NULL
94-
NULL
95-
NULL
96-
$(git rev-parse two) 2
97-
$(git rev-parse one) 1
98-
$(git rev-parse three) 3"
99-
89+
test-tool oidmap >actual.raw <<-\EOF &&
90+
put one 1
91+
put two 2
92+
put three 3
93+
iterate
94+
EOF
95+
96+
# sort "expect" too so we do not rely on the order of particular oids
97+
sort >expect <<-EOF &&
98+
NULL
99+
NULL
100+
NULL
101+
$(git rev-parse one) 1
102+
$(git rev-parse two) 2
103+
$(git rev-parse three) 3
104+
EOF
105+
106+
sort <actual.raw >actual &&
107+
test_cmp expect actual
100108
'
101109

102110
test_done

0 commit comments

Comments
 (0)