Changes compared to preview 2
- Incorporated v2 changes up to v2.13.2
- Some runtime performance improvements
- The static library compiles 20-30% faster
- The overhead of including catch_test_macros.hpp is 25-30% smaller
- Amalgamated, 1 .hpp + 1 .cpp, distribution is provided
- Reporter interface has slightly changed
- Listener base renamed
- Rewritten contributing documentation
- Primary development is now on
develbranch - v3 is now the primary development version
- Primary development is now on
Changes compared to v2 releases
Catch2 now uses statically compiled library as its distribution model.
This also means that to get all of Catch2's functionality in a test file,
you have to include multiple headers.
For quick'n'dirty migration, you can replace the old #include <catch2/catch.hpp>
with #include <catch2/catch_all.hpp>. This is a (one of) convenience
header(s) that brings in all of headers in Catch2. By doing this,
you should be able to migrate instantly, but at the cost of (significantly)
increased compilation times. You should prefer piecemeal including
headers that are actually required by your test code.
The basic set of functionality (TEST_CASE, SECTION, REQUIRE) is in
catch2/catch_test_macros.hpp. Matchers are in matchers subfolder,
generators in generators subfolder, and so on.
Note that documentation has not yet been updated to account for the
new design.
FAQ
- Why is Catch2 moving to separate headers?
- The short answer is future extensibility and scalability. The long answer is complex and can be found on my blog, but at the most basic level, it is that providing single-header distribution is at odds with providing variety of useful features. When Catch2 was distributed in a single header, adding a new Matcher would cause overhead for everyone, but was useful only to a subset of users. This meant that the barrier to entry for new Matchers/Generators/etc is high in single header model, but much smaller in the new model.
- Will Catch2 again distribute single-header version in the future?
- No. But we do provide sqlite-style amalgamated distribution option. This means that you can download just 1 .cpp file and 1 header and place them next to your own sources. However, doing this has downsides similar to using the
catch_all.hppheader.
- No. But we do provide sqlite-style amalgamated distribution option. This means that you can download just 1 .cpp file and 1 header and place them next to your own sources. However, doing this has downsides similar to using the
- Why the big breaking change caused by replacing
catch.hppwithcatch_all.hpp?- The convenience header
catch_all.hppexists for two reasons. One of them is to provide a way for quick migration from Catch2, the second one is to provide a simple way to test things with Catch2. Using it for migration has one drawback in that it is big. This means that including it will cause significant compile time drag, and so using it to migrate should be a concious decision by the user, not something they can just stumble into unknowingly.
- The convenience header
(Potentially) Breaking changes
- Catch2 now uses statically compiled library as its distribution model
- Including
catch.hppno longer works
- Including
ANON_TEST_CASEhas been removed, useTEST_CASEwith no arguments instead (#1220)--list*commands no longer have non-zero return code (#1410)--list-test-names-onlyhas been removed (#1190)- You should use verbosity-modifiers for
--list-testsinstead
- You should use verbosity-modifiers for
--list*commands are now piped through the reporters- The top-level reporter interface provides default implementation that works just as the old one
- XmlReporter outputs a machine-parseable XML
TEST_CASEdescription support has been removed- If the second argument has text outside tags, the text will be ignored.
- Hidden test cases are no longer included just because they don't match an exclusion tag
- Previously, a
TEST_CASE("A", "[.foo]")would be included by asking for~[bar].
- Previously, a
PredicateMatcheris no longer type erased.- This means that the type of the provided predicate is part of the
PredicateMatcher's type
- This means that the type of the provided predicate is part of the
SectionInfono longer contains section description as a member (#1319)- You can still write
SECTION("ShortName", "Long and wordy description"), but the description is thrown away - The description type now must be a
const char*or be implicitly convertible to it
- You can still write
- The
[!hide]tag has been removed.- Use
[.]or[.foo]instead.
- Use
- Lvalues of composed matchers cannot be composed further
- Uses of
REGISTER_TEST_CASEmacro need to be followed by a semicolon- This does not change
TEST_CASEand friends in any way
- This does not change
IStreamingReporter::IsMultimember function was removed- This is very unlikely to actually affect anyone, as it was default-implemented in the interface, and only used internally
- Various classes not designed for user-extension have been made final
ListeningReporteris nowfinal- Concrete Matchers (e.g.
UnorderedEqualsvector matcher) are nowfinal - All Generators are now
final
- Matcher namespacing has been redone
- Matcher types are no longer in deeply nested namespaces
- Matcher factory functions are no longer brought into
Catchnamespace - This means that all public-facing matcher-related functionality is now in
Catch::Matchersnamespace
- Defining
CATCH_CONFIG_MAINwill no longer create main in that TU.- Link with
libCatch2Main.a, or the proper CMake/pkg-config target - If you want to write custom main, include
catch2/catch_session.hpp
- Link with
CATCH_CONFIG_EXTERNAL_INTERFACEShas been removed.- You should instead include the appropriate headers as needed.
CATCH_CONFIG_IMPLhas been removed.- The implementation is now compiled into a static library.
- Event Listener interface has changed
TestEventListenerBasewas renamed toEventListenerBaseEventListenerBasenow directly derives fromIStreamingReporter, instead of deriving fromStreamingReporterBase
Improvements
- Matchers have been extended with the ability to use different signatures of
match(#1307, #1553, #1554, #1843)- This includes having templated
matchmember function - See the rewritten Matchers documentation for details
- Catch2 currently provides some generic matchers, but there should be more before final release of v3
- So far,
IsEmpty,SizeIs, andContainsare provided. - At least
ElementsAreandUnorderedElementsAreare planned.
- So far,
- This includes having templated
- Some runtime performance improvements
- Significant compilation time improvements
- including
catch_test_macros.hppis 80% cheaper than includingcatch.hpp
- including
Fixes
- The
INFOmacro no longer contains superfluous semicolon (#1456) - The
--list*family of command line flags now return 0 on success (#1410, #1146)
Other changes
CATCH_CONFIG_DISABLE_MATCHERSno longer exists.- If you do not want to use Matchers in a TU, do not include their header.
CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKERno longer exists.StringMakerspecializations for<chrono>are always provided
- Catch2's CMake now provides 2 targets,
Catch2andCatch2WithMain.Catch2is the statically compiled implementation by itselfCatch2WithMainalso links in the default main
- Catch2's pkg-config integration also provides 2 packages
catch2is the statically compiled implementation by itselfcatch2-with-mainalso links in the default main