t5526: stop asserting on stderr literally

In the previous commit message, we noted that not all of the "git fetch"
stderr is relevant to the tests. Most of the test setup lines are
dedicated to these details of the stderr:

1. which repos (super/sub/deep) are involved in the fetch
2. the head of the remote-tracking branch before the fetch (i.e. $head1)
3. the head of the remote-tracking branch after the fetch (i.e. $head2)

1. and 3. are relevant because they tell us that the expected commit is
fetched by the expected repo, but 2. is completely irrelevant.

Stop asserting on $head1 by replacing it with a dummy value in the
actual and expected output. Do this by introducing test
helpers (write_expected_*()) that make it easier to construct the
expected output, and use sed to munge the actual output.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Glen Choo 2022-03-07 16:14:25 -08:00 committed by Junio C Hamano
parent f3117dfdd1
commit 6e94bd64f3

View File

@ -10,6 +10,32 @@ export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
pwd=$(pwd) pwd=$(pwd)
write_expected_sub () {
NEW_HEAD=$1 &&
cat >"$pwd/expect.err.sub" <<-EOF
Fetching submodule submodule
From $pwd/submodule
OLD_HEAD..$NEW_HEAD sub -> origin/sub
EOF
}
write_expected_deep () {
NEW_HEAD=$1 &&
cat >"$pwd/expect.err.deep" <<-EOF
Fetching submodule submodule/subdir/deepsubmodule
From $pwd/deepsubmodule
OLD_HEAD..$NEW_HEAD deep -> origin/deep
EOF
}
write_expected_super () {
NEW_HEAD=$1 &&
cat >"$pwd/expect.err.super" <<-EOF
From $pwd/.
OLD_HEAD..$NEW_HEAD super -> origin/super
EOF
}
# For each submodule in the test setup, this creates a commit and writes # For each submodule in the test setup, this creates a commit and writes
# a file that contains the expected err if that new commit were fetched. # a file that contains the expected err if that new commit were fetched.
# These output files get concatenated in the right order by # These output files get concatenated in the right order by
@ -17,27 +43,21 @@ pwd=$(pwd)
add_upstream_commit() { add_upstream_commit() {
( (
cd submodule && cd submodule &&
head1=$(git rev-parse --short HEAD) &&
echo new >> subfile && echo new >> subfile &&
test_tick && test_tick &&
git add subfile && git add subfile &&
git commit -m new subfile && git commit -m new subfile &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "Fetching submodule submodule" > ../expect.err.sub && write_expected_sub $new_head
echo "From $pwd/submodule" >> ../expect.err.sub &&
echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
) && ) &&
( (
cd deepsubmodule && cd deepsubmodule &&
head1=$(git rev-parse --short HEAD) &&
echo new >> deepsubfile && echo new >> deepsubfile &&
test_tick && test_tick &&
git add deepsubfile && git add deepsubfile &&
git commit -m new deepsubfile && git commit -m new deepsubfile &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "Fetching submodule submodule/subdir/deepsubmodule" > ../expect.err.deep write_expected_deep $new_head
echo "From $pwd/deepsubmodule" >> ../expect.err.deep &&
echo " $head1..$head2 deep -> origin/deep" >> ../expect.err.deep
) )
} }
@ -62,7 +82,8 @@ verify_fetch_result () {
then then
cat expect.err.deep >>expect.err.combined cat expect.err.deep >>expect.err.combined
fi && fi &&
test_cmp expect.err.combined $ACTUAL_ERR sed -e 's/[0-9a-f][0-9a-f]*\.\./OLD_HEAD\.\./' "$ACTUAL_ERR" >actual.err.cmp &&
test_cmp expect.err.combined actual.err.cmp
} }
test_expect_success setup ' test_expect_success setup '
@ -274,12 +295,10 @@ test_expect_success "Recursion doesn't happen when no new commits are fetched in
' '
test_expect_success "Recursion stops when no new submodule commits are fetched" ' test_expect_success "Recursion stops when no new submodule commits are fetched" '
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >>expect.err.super &&
rm expect.err.deep && rm expect.err.deep &&
( (
cd downstream && cd downstream &&
@ -291,13 +310,11 @@ test_expect_success "Recursion stops when no new submodule commits are fetched"
test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" ' test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
add_upstream_commit && add_upstream_commit &&
head1=$(git rev-parse --short HEAD) &&
echo a > file && echo a > file &&
git add file && git add file &&
git commit -m "new file" && git commit -m "new file" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >> expect.err.super &&
rm expect.err.sub && rm expect.err.sub &&
rm expect.err.deep && rm expect.err.deep &&
( (
@ -318,12 +335,10 @@ test_expect_success "Recursion picks up config in submodule" '
) )
) && ) &&
add_upstream_commit && add_upstream_commit &&
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >> expect.err.super &&
( (
cd downstream && cd downstream &&
git fetch >../actual.out 2>../actual.err && git fetch >../actual.out 2>../actual.err &&
@ -345,20 +360,15 @@ test_expect_success "Recursion picks up all submodules when necessary" '
git fetch && git fetch &&
git checkout -q FETCH_HEAD git checkout -q FETCH_HEAD
) && ) &&
head1=$(git rev-parse --short HEAD^) &&
git add subdir/deepsubmodule && git add subdir/deepsubmodule &&
git commit -m "new deepsubmodule" && git commit -m "new deepsubmodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "Fetching submodule submodule" > ../expect.err.sub && write_expected_sub $new_head
echo "From $pwd/submodule" >> ../expect.err.sub &&
echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
) && ) &&
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >> expect.err.super &&
( (
cd downstream && cd downstream &&
git fetch >../actual.out 2>../actual.err git fetch >../actual.out 2>../actual.err
@ -376,13 +386,10 @@ test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no ne
git fetch && git fetch &&
git checkout -q FETCH_HEAD git checkout -q FETCH_HEAD
) && ) &&
head1=$(git rev-parse --short HEAD^) &&
git add subdir/deepsubmodule && git add subdir/deepsubmodule &&
git commit -m "new deepsubmodule" && git commit -m "new deepsubmodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo Fetching submodule submodule > ../expect.err.sub && write_expected_sub $new_head
echo "From $pwd/submodule" >> ../expect.err.sub &&
echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
) && ) &&
( (
cd downstream && cd downstream &&
@ -395,12 +402,10 @@ test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no ne
' '
test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" ' test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >>expect.err.super &&
( (
cd downstream && cd downstream &&
git config fetch.recurseSubmodules false && git config fetch.recurseSubmodules false &&
@ -421,13 +426,11 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess
test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" ' test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
add_upstream_commit && add_upstream_commit &&
head1=$(git rev-parse --short HEAD) &&
echo a >> file && echo a >> file &&
git add file && git add file &&
git commit -m "new file" && git commit -m "new file" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >> expect.err.super &&
rm expect.err.sub && rm expect.err.sub &&
rm expect.err.deep && rm expect.err.deep &&
( (
@ -445,12 +448,10 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
) && ) &&
add_upstream_commit && add_upstream_commit &&
git config --global fetch.recurseSubmodules false && git config --global fetch.recurseSubmodules false &&
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >>expect.err.super &&
rm expect.err.deep && rm expect.err.deep &&
( (
cd downstream && cd downstream &&
@ -473,12 +474,10 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override
) && ) &&
add_upstream_commit && add_upstream_commit &&
git config fetch.recurseSubmodules false && git config fetch.recurseSubmodules false &&
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >>expect.err.super &&
rm expect.err.deep && rm expect.err.deep &&
( (
cd downstream && cd downstream &&
@ -499,12 +498,10 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea
cd submodule && cd submodule &&
git checkout -q HEAD^^ git checkout -q HEAD^^
) && ) &&
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git commit -m "submodule rewound" && git commit -m "submodule rewound" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." > expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >> expect.err.super &&
rm expect.err.sub && rm expect.err.sub &&
# This file does not exist, but rm -f for readability # This file does not exist, but rm -f for readability
rm -f expect.err.deep && rm -f expect.err.deep &&
@ -526,13 +523,11 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git
git fetch --recurse-submodules git fetch --recurse-submodules
) && ) &&
add_upstream_commit && add_upstream_commit &&
head1=$(git rev-parse --short HEAD) &&
git add submodule && git add submodule &&
git rm .gitmodules && git rm .gitmodules &&
git commit -m "new submodule without .gitmodules" && git commit -m "new submodule without .gitmodules" &&
head2=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
echo "From $pwd/." >expect.err.super && write_expected_super $new_head &&
echo " $head1..$head2 super -> origin/super" >>expect.err.super &&
rm expect.err.deep && rm expect.err.deep &&
( (
cd downstream && cd downstream &&