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

Already on GitHub? Sign in to your account

Add a JSON formatter #375

Merged
merged 9 commits into from Apr 24, 2013

Conversation

Projects
None yet
2 participants
Owner

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

@schwern schwern A formatter which dumps out JSON.
Potentially very handy for debugging or for IPC.  Could replace Test::Harness.
cf8b087
@schwern schwern 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.
9ef1086
@schwern schwern Ensure that events can round trip via as_hash. 5650b74
@schwern schwern Fix the docs for TB2::Event->keys_for_as_hash
Something I noticed.
2a3dacc
@schwern schwern 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.
0cdaa56
@schwern schwern Use TB2::Event::Generic to reconstitute JSON events. 118483f
Owner

schwern commented Apr 24, 2013

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

Contributor

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

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

Owner

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.

Owner

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

@schwern schwern 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.
53021f9
@schwern schwern 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.
9e5ed1a
@schwern schwern 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.
55f5314
Owner

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.

Contributor

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 :)

Owner

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 schwern added a commit that referenced this pull request Apr 24, 2013

@schwern schwern Merge pull request #375 from schwern/issue/159
Add a JSON formatter for #159
a3137e6

@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