dropbox / json11

A tiny JSON library for C++11.
MIT License
2.55k stars 613 forks source link

Allow json11 tests to be customized with pre-processor defines #69

Closed artwyman closed 8 years ago

artwyman commented 8 years ago

This allows json11's test.cpp to be customized in order to make it fit into a specific testing framework, without making any particular framework a default dependency. The configuration is via pre-processor defines, which can disable the main() function and replace various code snippets. At Dropbox, I'm using this to turn test.cpp into a gtest test, but others can use their favorite framework.

I also made the DR1467 canary configurable in the same way, as well as from the command-line to make.

I'm putting this up as a PR so @j4cbo can comment before I merge.

j4cbo commented 8 years ago

Overall thoughts: I'm torn on the merits of generalizing this vs. just baking in an assumption of gtest. The library itself should remain minimal-dependency, but assuming a particular test framework feels different - if a user also uses gtest, they could bake these in to the same binary (as long as main is moved to a separate file), but if not they could build json11's tests and just invoke them.

That's not a hard veto - if you think the generality is worth the complexity, I'm fine with this.

artwyman commented 8 years ago

I'm not sure what you see as the easy path for a user who doesn't already use gtest. They wouldn't be able to build and run anything out of a clean json11 repo, without getting gtest from somewhere, right? There's no way for a hand-written main to just invoke them, and they won't build without gtest.h. I think it's best for new users to be able to just "make" and "./test" and see something happen out of the box.

j4cbo commented 8 years ago

Yeah, they'd need to get gtest from somewhere. I guess given that the test suite is also the first program one would run with json11, being able to just make has extra value.

push it (push it real good)

artwyman commented 8 years ago

Yeah, in theory I could separate the test suite from a sample program, but that seems like its own complexity. Pushing. Thanks for the rapid turn-around.