Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to parse a stream of more than one test set #39

Open
jcflack opened this issue Oct 12, 2015 · 2 comments
Open

A way to parse a stream of more than one test set #39

jcflack opened this issue Oct 12, 2015 · 2 comments

Comments

@jcflack
Copy link
Contributor

jcflack commented Oct 12, 2015

In my application I may have to parse from a stream of TAP produced by more than one test set. In looking around for prior work in that area, I found TAP::Stream and a message from someone working on Plan 9.

It would be nice to have a parse method that either returns a list of TestSet, or invokes a callback once for each TestSet when it comes out of the oven. It looks like TAP::Stream builds an über-testset with each set that it parsed as a subtest, though I've only glanced at it so I might not be right about that. In any case, even if tap4j's parser just returned a list or used a callback, it would be easy to build the rest of that on it.

The API as it stands is not so easy to build upon, because after seeing some input that probably means a new test set started, the caller can't easily get the preceding TestSet (an exception is thrown instead of returning it), and some of the next one has already been read from the stream, so unless the caller knows how much to push back, it isn't easy to start a new Parser to parse the next part.

It seems like the signs for one TestSet to come out of the oven would include:

  • seeing another TAP header
  • seeing another plan (if the prior one was beforeTestResult)
  • seeing anything after a plan that wasn't beforeTestResult (except maybe a footer)
  • seeing anything after a TAP footer

(By the way, what is a TAP footer? I see no mention in the spec here, is there a newer version I should be looking at?)

Those are the rules that pop into my head, though it might be better to try to match exactly what something else is doing, like TAP::Stream.

I ny my application, I might try to just put something in front of the parser that would try to match those events in the stream and feed the lines to a succession of parsers, but that has the code-duplication disadvantage of having to check for some of the exact same patterns the Parser already knows about.
and whatever I do there will probably be stupid about stuff in a YAML stream that looks like a TAP line, etc.) So it seems like really it should be in the parser and done right.

If the onPlan/onTestResult/etc. methods were virtual, a caller might be able to subclass the parser and get the wanted behavior by overriding some of them (it would start to look like SAX then), but they're currently private so that's not an option.

@kinow
Copy link
Member

kinow commented Oct 12, 2015

Hello again @jcflack

I had a quick look at your description (thanks again for being so clear about it) and I liked it :-) Looking again at the tap4j source code I'm a bit ashamed of a few things I did here and there, and that could be better.

I will have to re-read your description again, while reading the code. But at least I think I can answer this one now

(By the way, what is a TAP footer? I see no mention in the spec here, is there a newer version I should be looking at?)

The testanything.org website went down for a few months, and someone else fixed that (Jonathan I think?). Then created the github repository, and updated the CSS and page layout. The content also changed, as before the web site was hosted in a Media Wiki (if I remember correctly).

There was a mention to TAP footer in the specification in the old website, and I think some Perl module also mentioned that. I may be wrong, but I think there was some grammar with this TAP Footer... but I would have to look at the Internet archive wayback machine.

I will take a look at the parser to confirm later, but I think the footer is anything that you want to add and is a valid comment. For example

1..2
ok 1
not ok 2
# generated at 2014-09-22 01:10:08+12

@kinow
Copy link
Member

kinow commented Oct 12, 2015

By the way, if you feel like doing more changes and submitting pull requests, or even if you'd like to work on a branch, I can add you to the GitHub organisation and give you karma for that :-)

You previous change was really good, and we can move forward to another major release in case we make some binary incompatible changes in the parsers, consumers, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants