A "why TAP?" manifesto (was: [PATCH] test-lib: have --immediate emit valid TAP on failure)
[I guess that warrants a $subject change]
A few things, grouped by heading:
== It "can be parsed"
First, the "[TAP ]can['t] be parsed" part of that is wrong.
As your own CI patch series[1] shows we currently parse the entire TAP
output of our test suite on every CI run. Otherwise prove(1) couldn't
have come up with this (quoting from your [1]):
Test Summary Report
-------------------
t1092-sparse-checkout-compatibility.sh (Wstat: 256 Tests: 53 Failed: 1)
Failed test: 49
Non-zero exit status: 1
t3701-add-interactive.sh (Wstat: 0 Tests: 71 Failed: 0)
TODO passed: 45, 47
That's the result of a compliant TAP parser parsing all of our test output, which has worked for all our tests (sans edge cases like the one being fixed here) for a long time.
Let's not go into how you don't like that summary output, that's not the point.
That's a UX layer presenting something from the fully parsed output, the point is that it *is* not only parsable, but it's currently *being parsed* by our toolchain on every CI run.
== Human readable
Unless you're expecting us to eyeball something like this verbose XML on
ad-hoc runs like:
$ ./t0013-sha1dc.sh --write-junit-xml --tee
ok 1 - test-sha1 detects shattered pdf
# passed all 1 test(s)
1..1
Which for JUnit is:
$ cat out/TEST-t0013-sha1dc.xml
<testsuites>
<testsuite name="t0013-sha1dc" timestamp="2022-03-24T14:20:27" time="0.065762">
<testcase name="t0013.1 test-sha1 detects shattered pdf
" classname="t0013" time="0.029818">
</testcase>
</testsuite>
</testsuites>
You're going to end up with 2 output formats, a human readable one and some secondary also-machine-readable output.
TAP isn't perfect, but it's uniquely suitable as a format for the sort of testing we do, because it's explicitly machine-readable format that's designed to also be human readable.
Which isn't a goal with JUnit. Perhaps some XML enthusiasts would argue that point. Sure, you *can* read it, but it's not exactly pleasing nor aiming to reduce verbosity.
The JUnit we currently emit is >2x the verbosity of TAP by lines, and
~3x as much by byte count (all of which a human needs to occasionally
skim):
$ rm -rf out; ./t0001-init.sh --write-junit-xml --tee |wc ; wc <out/*xml
63 488 2553
130 615 7592
== It's trivial to produce
Most output formats are way more picky about what constitutes a valid
payload than TAP is, which is why for the TAP v.s. JUnit output the
number of syscalls we need shows this drastic difference:
$ strace --summary-only -f ./t0001-init.sh --tee 2>&1 | tail -n 1
100.00 3.703689 21 171581 13587 total
$ strace --summary-only -f ./t0001-init.sh --tee --write-junit-xml 2>&1 | tail -n 1
100.00 6.424080 22 285903 21097 total
I.e. the implementation of it just needs an "echo" or whatever, whereas the XML one is shelling out for pretty much every line it prints to escape things.
I'm you might argue about the hatefulness about shellscripting there and how we should rewrite everything in C.
I don't disagree with that point in the abstract, but realistically we'll be needing to deal with the shellscript-based test suite for the foreseeable future.
== It's more flexible
The JUnit we write out is just the summary output, but when you run a test with e.g. "--verbose -x" the result is valid TAP. I.e. TAP parser will take this:
$ ./t0013-sha1dc.sh -vx 2>&1|wc
38 165 1104
And grab the lines matching "ok" "not ok" etc., and *ignore everything else*.
This means that we're able to use it for things that you just couldn't use JUnit for, e.g. the POC I have here where we pair up our "--verbose -x" output with the failure summary, i.e. show what specific test things belongs t [2]:
== It doesn't matter if nobody else uses it
Or: "we don't need a 2nd machine-parsable format".
I think your "the world has moved on to more powerful file formats to represent test output" is a valid concern.
I.e. we don't want to have a test suite output that we can't pretty render on whatever the latest fancy test CI renderer is is a completely valid concern, whether that's Azure or GitHub CI.
But the implicit assumption there seems to be that TAP isn't rather trivially machine-parsable, and that we aren't already running a parser for it. It is, and we are.
Because of that we can just have a post-transformation step of changing TAP into whatever other format you'd like.
So you can have JUnit, GitHub CI Markdown or whatever, it should just be produced from the TAP output.
I think that your addition of JUnit & GitHub CI Markdown (in [1]) is much better done like that. It avoids the complexity of N output formats in test-lib.sh. A transformer for your desired format probably exists already (or could trivially be adjusted for a new format):
https://metacpan.org/search?q=TAP%3A%3AFormatter
== Everyone uses it
Well, <citation needed>, but while per the above I don't think wide use of TAP even matters I think being concerned about lack of tooling support for it is strange.
I'm fairly sure it's the single most widely supported test output format of any kind. Because of how trivial it is to parse and implement I'm pretty sure it's the most widely-supported machine-readable test output format of any kind.
*Maybe* something like JUnit has (near) parity if we're counting format transformers-to-transformers, but I'm fairly sure not if it wouldn't be allowed to "cheat" by making use of TAP as an intermediate format.
== Cases where TAP isn't good enough currently
Someone familiar with our test tooling might thing "wait, TAP with --verbose is valid TAP?" because since 614fe015212 (test-lib: bail out when "-v" used under "prove", 2016-10-22) we have been refusing to produce it in that case:
$ prove t0013-sha1dc.sh :: --verbose
Bailout called. Further testing stopped: verbose mode forbidden under TAP harness; try --verbose-log
FAILED--Further testing stopped: verbose mode forbidden under TAP harness; try --verbose-logFixing that is needed for the approach in [2] to work 100% of the time, I have working patches to that (which as it happens, are currently blocking on conflicts with your [1]).
I.e. the problem is that if we're expecting a line starting with "ok" or whatever the firehose --verbose output from the test itself might emit such a line, and confuse the parser.
The solution was rather trivial in the case of TAP, just have test-lib.sh emit a configurable prefix string before any TAP syntax it emits, then have a "tee" tool we ship as a test helper munge that after the fact:
https://github.com/avar/git/commit/2358ff8c3a7
https://github.com/avar/git/commit/2ae430bfce7== Handling the long-tail of machine-readability
Continuing the above: I don't think a solution to that sort of thing is really viable with anything that doesn't behave like TAP.
We have tests doing things like starting a background daemon that will racily emit output its output *in the middle of another* test.
As in not theoretically, it's a case I actually had to debug & test to get the above commits working. The JUnit emitter punts on it entirely by not including the "--verbose -x" output at all.
The rather easy solution for TAP explicitly relies on its "non-syntax" of considering every line it doesn't explicitly classify as syntax as something it'll pass through as "output".
Those lines thenh need no further escaping. They can pretty much be latin-1, UTF-8, your favorite bits from /dev/urandom etc.. It doesn't matter.
Whereas for e.g. any XML, JSON etc. format where things are syntax by default you'd need to intercept all that output to strip "<" and the like from it.
Even if you did that you probably wouldn't have anywhere sensible to stick that output, you probably already emitted the beginning/end markers for "here's the verbose output for test N" already, which would require complexity a TAP emitter wouldn't need.