Add a JSON formatter #375

merged 9 commits into from Apr 24, 2013


None yet
2 participants

schwern commented Apr 24, 2013

For #159

The formatter was easy.

I also thought about the deserialization process and added TB2::Event::Generic to act as a bucket for the deserialized events. This avoids the user needing a mapping of event types to classes which avoids having an event class registry.

This would be really neat as a replacement for TAP as the communication channel with the test harness.

schwern added some commits Apr 23, 2013

A formatter which dumps out JSON.
Potentially very handy for debugging or for IPC.  Could replace Test::Harness.
Add TB2::Events->event_classes
Some tests want a list of all the event classes, so make it a public method
of TB2::Events.  Don't see the need to make it publicly documented.
Add TB2::Event::Generic.
A generic event bucket useful for reconstituting events from serialization.

It will accept anything and turn it into an attribute.

This isn't 100% for all events.  For example, subtest_end has a history
object and a result.  Might have to add in some special cases later.

schwern commented Apr 24, 2013

Ping @AndyA for a review. Then we can get to writing a new test harness!


AndyA commented on lib/TB2/Formatter/ in cf8b087 Apr 24, 2013

Does it need to allow_blessed? That implies that it's not pure JSON on the wire.


schwern replied Apr 24, 2013

A handful of events have objects in them, like TB2::Event::SubtestEnd has a TB2::History and TB2::Result object. Not sure how to deal with that more gracefully. That may be the only exception. Everything in TB2::Event::SubtestEnd->history and ->result can be derived from the event stream.


schwern replied Apr 24, 2013

I'm going to make as_hash go recursive and add an as_hash method to TB2::History.

schwern added some commits Apr 24, 2013

Move as_hash out of TB2::Event and into a role.
We're going to need it in TB2::History and other objects to do proper
recursive dumping.
Make TB2::History->in_test and done_testing always return a boolean
This is important when as_hash is added to TB2::History so in_test
and done_testing are always defined and thus always dumped.
Add TB2::History->as_hash and make as_hash recursive.
This makes dumping the event stream as_hash have the complete information.

I decided not to dump last_result or last_event because that seemed redundant
if you're looking at the whole event stream.  You're normally only looking
at the history object as part of a subtest_end event.

Decided not to dump the event storage, that would get large and recursive.

Decided not to dump store_events as that is not information about the
state of the test, but the state of the history object.  This is just data.

schwern commented Apr 24, 2013

@AndyA What do you think of those revisions? I left allow_blessed in just in case somebody subclasses an event and shoves an object in which doesn't can("as_hash"). Better to dump it as null than blow up.


AndyA commented Apr 24, 2013

Is it not better to blow up if someone tries to serialise an object as JSON? It implies that the thing on the receiving end knows what to do with it. Other than that it looks great to me :)


schwern commented Apr 24, 2013

@AndyA allow_blessed turns objects into "null", so rogue objects will never make into the JSON stream.

My assumptions are...

  1. I don't want Event authors to be constantly worrying about serialization
  2. The party altering an Event may not be related to the party using the JSON formatter

The first may be a bad assumption, but I'm fairly convinced of the second. I don't want the JSON formatter spuriously blowing up because of what somebody unrelated did.

schwern added a commit that referenced this pull request Apr 24, 2013

@schwern schwern merged commit a3137e6 into Test-Builder1.5 Apr 24, 2013

@schwern schwern deleted the issue/159 branch Apr 24, 2013

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