approvals / ApprovalTests.cpp

Native ApprovalTests for C++ on Linux, Mac and Windows
https://approvaltestscpp.readthedocs.io/en/latest/
Apache License 2.0
318 stars 51 forks source link

Boost test support #119

Closed claremacrae closed 4 years ago

claremacrae commented 4 years ago

Work in progress, with experimental code - there will be more commits!

I'd like an easy way for Boost Test users to be able to comment on the changes for #41 ...

So I've started this pull request to provide an easy way to see and respond to comments, and to review the changes...

jwillikers commented 4 years ago

The approved file currently generated is called

main.Sample.Suite.return_true.approved.txt

so SourceName.ModuleName.TestCaseName

Does this seem reasonable? Would it scale with larger volumes of Boost Test code?

The suite name will need to be included because test case names could potentially conflict if they are in different test suites within the same module. The test suites are effectively just namespaces.

I believe that Boost Test allows nested test suites, so the Suite portion of the name would need to contain all of the suites.

That ends up looking something like the following. SourceName.ModuleName[.Suite...].TestCaseName

jwillikers commented 4 years ago

We have not yet succeeded in setup of developer and CI builds for all platforms, so for now we ended pulling in Boost's test header via its "single header" version: <boost/test/included/unit_test.hpp>

When we actually release this, I imagine many of our users will have a compiled boost unit_test installation, but some will have header-only...

I assume this means in our wrapper we will need to know from the user which form they want to include:

#if defined(APPROVALS_BOOST_TEST_COMPILED)
    #include <boost/test/unit_test.hpp>
#elif defined(APPROVALS_BOOST_TEST_SOMETHING_ELSE)
    #include <boost/test/included/unit_test.hpp>
#endif

Am I over-thinking this?

Eww, this is a sticky point in using Boost Test, and will probably be important. Boost Test has three different configurations: header-only, static, and shared. I link to the shared version. Their documentation on this is pretty good: https://www.boost.org/doc/libs/1_72_0/libs/test/doc/html/boost_test/adv_scenarios.html. You should be able to detect this with existing Boost macros. The ones to be aware of are BOOST_TEST_DYN_LINK, BOOST_TEST_STATIC_LINK, BOOST_ALL_DYN_LINK, BOOST_ALL_STATIC_LINK, and BOOST_TEST_INCLUDED.

claremacrae commented 4 years ago

I believe that Boost Test allows nested test suites, so the Suite portion of the name would need to contain all of the suites.

That ends up looking something like the following. SourceName.ModuleName[.Suite...].TestCaseName

Thank you - I was wrong in my comment - the above is actually how it currently names the outputs.

I wasn't aware of there being nested test suites - so this was really helpful. I added a new test, with a nested namespace, and it all just worked... The approved file was:

tests/Boost_Tests/main.ModuleName.SuiteName.NestedSuiteName.TestCaseName.approved.txt

(Note to self: I'll have to check whether this filename is too long for checking out on windows...)

claremacrae commented 4 years ago

Eww, this is a sticky point in using Boost Test, and will probably be important. Boost Test has three different configurations: header-only, static, an shared. I link to the shared version. Their documentation on this is pretty good: https://www.boost.org/doc/libs/1_72_0/libs/test/doc/html/boost_test/adv_scenarios.html. You should be able to detect this with existing Boost macros. The ones to be aware of are BOOST_TEST_DYN_LINK, BOOST_TEST_STATIC_LINK, BOOST_ALL_DYN_LINK, BOOST_ALL_STATIC_LINK, and BOOST_TEST_INCLUDED.

This is fantastic - thank you very much!

jwillikers commented 4 years ago

No problem. I will look more into this soon.