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

Add a JSON formatter #375

Merged
merged 9 commits into from Apr 24, 2013
Merged

Add a JSON formatter #375

merged 9 commits into from Apr 24, 2013

Conversation

schwern
Copy link
Contributor

@schwern 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.

Potentially very handy for debugging or for IPC.  Could replace Test::Harness.
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.
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
Copy link
Contributor Author

schwern commented Apr 24, 2013

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

We're going to need it in TB2::History and other objects to do proper
recursive dumping.
This is important when as_hash is added to TB2::History so in_test
and done_testing are always defined and thus always dumped.
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
Copy link
Contributor Author

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

@schwern
Copy link
Contributor Author

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 April 24, 2013 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants