mirror of
https://github.com/git/git
synced 2024-11-05 01:58:18 +00:00
a48a88019b
Unlike other test helper functions, 'test_oid' doesn't terminate its
output with a LF, but, alas, the reason for this, if any, is not
mentioned in 2c02b110da
(t: add test functions to translate
hash-related values, 2018-09-13)).
Now, in the vast majority of cases 'test_oid' is invoked in a command
substitution that is part of a heredoc or supplies an argument to a
command or the value to a variable, and the command substitution would
chop off any trailing LFs, so in these cases the lack or presence of a
trailing LF in its output doesn't matter. However:
- There appear to be only three cases where 'test_oid' is not
invoked in a command substitution:
$ git grep '\stest_oid ' -- ':/t/*.sh'
t0000-basic.sh: test_oid zero >actual &&
t0000-basic.sh: test_oid zero >actual &&
t0000-basic.sh: test_oid zero >actual &&
These are all in test cases checking that 'test_oid' actually
works, and that the size of its output matches the size of the
corresponding hash function with conditions like
test $(wc -c <actual) -eq 40
In these cases the lack of trailing LF does actually matter,
though they could be trivially updated to account for the presence
of a trailing LF.
- There are also a few cases where the lack of trailing LF in
'test_oid's output actually hurts, because tests need to compare
its output with LF terminated file contents, forcing developers to
invoke it as 'echo $(test_oid ...)' to append the missing LF:
$ git grep 'echo "\?$(test_oid ' -- ':/t/*.sh'
t1302-repo-version.sh: echo $(test_oid version) >expect &&
t1500-rev-parse.sh: echo "$(test_oid algo)" >expect &&
t4044-diff-index-unique-abbrev.sh: echo "$(test_oid val1)" > foo &&
t4044-diff-index-unique-abbrev.sh: echo "$(test_oid val2)" > foo &&
t5313-pack-bounds-checks.sh: echo $(test_oid oidfff) >file &&
And there is yet another similar case in an in-flight topic at:
https://public-inbox.org/git/813e81a058227bd373cec802e443fcd677042fb4.1670862677.git.gitgitgadget@gmail.com/
Arguably we would be better off if 'test_oid' terminated its output
with a LF. So let's update 'test_oid' accordingly, update its tests
in t0000 to account for the extra character in those size tests, and
remove the now unnecessary 'echo $(...)' command substitutions around
'test_oid' invocations as well.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
57 lines
1.2 KiB
Bash
Executable file
57 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='test unique sha1 abbreviation on "index from..to" line'
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
test_oid_cache <<-EOF &&
|
|
val1 sha1:4827
|
|
val1 sha256:5664
|
|
|
|
val2 sha1:11742
|
|
val2 sha256:10625
|
|
|
|
hash1 sha1:51d2738463ea4ca66f8691c91e33ce64b7d41bb1
|
|
hash1 sha256:ae31dfff0af93b2c62b0098a039b38569c43b0a7e97b873000ca42d128f27350
|
|
|
|
hasht1 sha1:51d27384
|
|
hasht1 sha256:ae31dfff
|
|
|
|
hash2 sha1:51d2738efb4ad8a1e40bed839ab8e116f0a15e47
|
|
hash2 sha256:ae31dffada88a46fd5f53c7ed5aa25a7a8951f1d5e88456c317c8d5484d263e5
|
|
|
|
hasht2 sha1:51d2738e
|
|
hasht2 sha256:ae31dffa
|
|
EOF
|
|
|
|
cat >expect_initial <<-EOF &&
|
|
100644 blob $(test_oid hash1) foo
|
|
EOF
|
|
|
|
cat >expect_update <<-EOF &&
|
|
100644 blob $(test_oid hash2) foo
|
|
EOF
|
|
|
|
test_oid val1 > foo &&
|
|
git add foo &&
|
|
git commit -m "initial" &&
|
|
git cat-file -p HEAD: > actual &&
|
|
test_cmp expect_initial actual &&
|
|
test_oid val2 > foo &&
|
|
git commit -a -m "update" &&
|
|
git cat-file -p HEAD: > actual &&
|
|
test_cmp expect_update actual
|
|
'
|
|
|
|
cat >expect <<EOF
|
|
index $(test_oid hasht1)..$(test_oid hasht2) 100644
|
|
EOF
|
|
|
|
test_expect_success 'diff does not produce ambiguous index line' '
|
|
git diff HEAD^..HEAD | grep index > actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|