Re: [PATCH v4 01/21] fsck tests: refactor one test to use a sub-repo
flat view
From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-24 22:42:59
On Fri, Jun 25 2021, Andrei Rybak wrote:
On 24/06/2021 21:23, Ævar Arnfjörð Bjarmason wrote:quoted
Refactor one of the fsck tests to use a throwaway repository. It's a pervasive pattern in t1450-fsck.sh to spend a lot of effort on the teardown of a tests so we're not leaving corrupt content for the next test. We should instead simply use something like this test_create_repo pattern. It's both less verbose, and makes things easier to debug as a failing test can have their state left behind under -d without damaging the state for other tests. But let's punt on that general refactoring and just change this one test, I'm going to change it further in subsequent commits. Signed-off-by: Ævar Arnfjörð Bjarmason <redacted> --- t/t1450-fsck.sh | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 5071ac63a5b..1563b35f88c 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh@@ -48,24 +48,22 @@ remove_object () { rm "$(sha1_file "$1")" } -test_expect_success 'object with bad sha1' ' - sha=$(echo blob | git hash-object -w --stdin) && - old=$(test_oid_to_path "$sha") && - new=$(dirname $old)/$(test_oid ff_2) && - sha="$(dirname $new)$(basename $new)" && - mv .git/objects/$old .git/objects/$new && - test_when_finished "remove_object $sha" && - git update-index --add --cacheinfo 100644 $sha foo && - test_when_finished "git read-tree -u --reset HEAD" && - tree=$(git write-tree) && - test_when_finished "remove_object $tree" && - cmt=$(echo bogus | git commit-tree $tree) && - test_when_finished "remove_object $cmt" && - git update-ref refs/heads/bogus $cmt && - test_when_finished "git update-ref -d refs/heads/bogus" && - - test_must_fail git fsck 2>out && - test_i18ngrep "$sha.*corrupt" out +test_expect_success 'object with hash mismatch' ' + test_create_repo hash-mismatch &&This patch was originally sent to ML on 2021-03-28: https://lore.kernel.org/git/patch-2.6-3e547289408-20210328T025618Z-avarab@gmail.com/ (local) since then, however, commit f0d4d398e2 (test-lib: split up and deprecate test_create_repo(), 2021-05-10) has been merged ;-) so this line should be: git init hash-mismatch &&
Thanks, you'd think that the author of that code would be in a better position than most to get this right, but apparently not :) This series originally pre-dates that work, I see I have a couple of more test_create_repo() in other patches here, will fix for a v5 pending more discussion on v4, thanks!