提交 e1e7a771 编写于 作者: J Jeff King 提交者: Junio C Hamano

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: NRandall S. Becker <rsbecker@nexbridge.com>
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 026dd738
......@@ -170,31 +170,45 @@ NULL
'
test_expect_success 'iterate' '
test_hashmap "put key1 value1
put key2 value2
put fooBarFrotz value3
iterate" "NULL
NULL
NULL
key2 value2
key1 value1
fooBarFrotz value3"
test-tool hashmap >actual.raw <<-\EOF &&
put key1 value1
put key2 value2
put fooBarFrotz value3
iterate
EOF
cat >expect <<-\EOF &&
NULL
NULL
NULL
fooBarFrotz value3
key1 value1
key2 value2
EOF
sort <actual.raw >actual &&
test_cmp expect actual
'
test_expect_success 'iterate (case insensitive)' '
test_hashmap "put key1 value1
put key2 value2
put fooBarFrotz value3
iterate" "NULL
NULL
NULL
fooBarFrotz value3
key2 value2
key1 value1" ignorecase
test-tool hashmap ignorecase >actual.raw <<-\EOF &&
put key1 value1
put key2 value2
put fooBarFrotz value3
iterate
EOF
cat >expect <<-\EOF &&
NULL
NULL
NULL
fooBarFrotz value3
key1 value1
key2 value2
EOF
sort <actual.raw >actual &&
test_cmp expect actual
'
test_expect_success 'grow / shrink' '
......
......@@ -86,17 +86,25 @@ NULL"
'
test_expect_success 'iterate' '
test_oidmap "put one 1
put two 2
put three 3
iterate" "NULL
NULL
NULL
$(git rev-parse two) 2
$(git rev-parse one) 1
$(git rev-parse three) 3"
test-tool oidmap >actual.raw <<-\EOF &&
put one 1
put two 2
put three 3
iterate
EOF
# sort "expect" too so we do not rely on the order of particular oids
sort >expect <<-EOF &&
NULL
NULL
NULL
$(git rev-parse one) 1
$(git rev-parse two) 2
$(git rev-parse three) 3
EOF
sort <actual.raw >actual &&
test_cmp expect actual
'
test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册