From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "David Turner" <novalis@novalis.org>,
"Elijah Newren" <newren@gmail.com>,
"Matheus Tavares" <matheus.bernardino@usp.br>,
"Jeff King" <peff@peff.net>,
"Derrick Stolee" <derrickstolee@github.com>,
"Đoàn Trần Công Danh" <congdanhqx@gmail.com>
Subject: test-lib.sh musings: test_expect_failure considered harmful
Date: Tue, 12 Oct 2021 11:23:40 +0200 [thread overview]
Message-ID: <87tuhmk19c.fsf@evledraar.gmail.com> (raw)
On Mon, Oct 11 2021, Junio C Hamano wrote:
[Removed "In-reply-to: <xmqq5yu3b80j.fsf@gitster.g>" with the Subject
change]
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>> test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
>> test_when_finished "chmod 775 .git/objects .git/objects/??" &&
>> chmod a-w .git/objects .git/objects/?? &&
>> - test_must_fail git commit -m second
>> +
>> + cat >expect <<-\EOF &&
>> + error: insufficient permission for adding an object to repository database .git/objects
>> + error: insufficient permission for adding an object to repository database .git/objects
>> + error: Error building trees
>> + EOF
>
> This is odd. Shouldn't the test expect one message from write-tree
> and be marked as expecting a failure until the bug gets fixed?
Presumably with test_expect_failure.
I'll change it, in this case we'd end up with a test_expect_success at
the end, so it doesn't matter much & I don't care.
But FWIW $subject, or at least s/harmful/running with scissors/g :)
[CC'd some recent-ish users of test_expect_failure, and I'm no innocent
in that department :)]
In the Perl world (Test::More et al) the "#TODO" keyword we map
test_expect_failure to (and yeah, I know the latter pre-dates the
former...) doesn't generally lead to subtle breakages and mismatched
expectations, i.e. you do:
TODO: {
local $TODO = "not implemented yet";
is($a, $b, "this is why this in particular fails");
}
So you generally mark the *specific* thing that fails, as separate from
your test setup itself.
But our test-lib.sh API for it is the equivalent of marking an entire
logical test block and its setup as a TODO.
So the diff below "passes". But did we intend for the test_cmp to fail,
for the thing to segfault or hit a BUG?
Any of those conditions being hit will have the TODO test pass. So will
all of it succeeding.
=== snip ===
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index df544bb321f..15724e6a358 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -601,4 +601,13 @@ test_expect_success 'branch -m with the initial branch' '
test again = $(git -C rename-initial symbolic-ref --short HEAD)
'
+test_expect_failure 'do stuff' '
+ git config alias.fake-SEGV "!f() { echo Fake SEGV; exit 139; }; f" &&
+ git config alias.fake-BUG "!f() { echo Fake BUG; exit 99; }; f" &&
+
+ git fake-BUG >expect &&
+ git fake-SEGV >actual &&
+ test_cmp expect actual
+'
+
test_done
=== snip ===
(Although for the "suceeding" case we'll print out a summary from
"prove", but unless you're carefully eyeballing that...).
So I think "test_expect_failure" should be avoided, the only useful way
of holding it which works in combination with other test-lib.sh features
that I've come up with is:
test_expect_success 'setup flaky failure' '
[multi-line test code that passes here] &&
>setup-todo
'
if test -e setup-todo
then
test_expect_failure 'flaky failure due to XYZ' '
test_cmp todo.expect todo.actual
'
fi
I.e.:
* Don't say that the failure of your passing test setup is OK too.
* In doing that don't break --run=N, so that "test -e setup-todo" test
(or equivalent) is needed, in case the "setup" is skipped.
* Have *just* the "test_cmp" (or other specific failure test) in the
"test_expect_failure"
But it's only useful if you can't make that a "! test_cmp" (or rather, a
more specific positive & passing "test_cmp".
I.e. it's flaky, or the output/end state is otherwise unknown (but we
expect it to be once bugs are fixed).
We have ~150 uses of test_expect_failure in the test suite, I'm pretty
sure that <20 of them at most are "correct" under the above
criteria. E.g. this is ok-ish:
t7815-grep-binary.sh-# This test actually passes on platforms where regexec() supports the
t7815-grep-binary.sh-# flag REG_STARTEND.
t7815-grep-binary.sh-test_expect_success 'git grep ile a' '
t7815-grep-binary.sh- git grep ile a
t7815-grep-binary.sh-'
Although in that case we should make it a test_expect_success if we can
get a "REG_STARTEND" build flag exported to the test suite. Skimming the
grep hits *maybe* some of the ones in "t9602-cvsimport-branches-tags.sh"
(I haven't looked carefully).
But most of them I Consider Harmful, i.e. they're a bunch of setup code
that could be hiding an unexpected bug/segfault. Running into that with
some past WIP work (a thing I considered to "just fail a test_cmp"
started segfaulting) is why I try to avoid it.
next reply other threads:[~2021-10-12 10:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 9:23 Ævar Arnfjörð Bjarmason [this message]
2021-10-12 16:45 ` test-lib.sh musings: test_expect_failure considered harmful Junio C Hamano
2021-10-13 10:10 ` Ævar Arnfjörð Bjarmason
2021-10-13 13:05 ` Derrick Stolee
2021-10-13 17:16 ` Junio C Hamano
2021-10-14 17:11 ` Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tuhmk19c.fsf@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=congdanhqx@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=matheus.bernardino@usp.br \
--cc=newren@gmail.com \
--cc=novalis@novalis.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).