Search code examples
c++unit-testingcommand-line-interfacecatch2

How do I make catch2 not print its annoying header?


I'm running some unit tests built with catch2. Its output begins with:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_suite is a Catch v2.13.6 host application.
Run with -? for options

well, I don't want to see that. Neither I nor other users/maintainers need to be reminded of the catch2 version or of the ability to run with -?, when we ran the unit test with proper arguments and know what we're doing.

But - the -? options don't seem to tell me how to disable this message. Can I? Or do I have to manually "bastardize" the catch2 header?


Solution

  • Catch2 is open-source

    If you go to src/catch2/reporters/catch_reporter_console.cpp, you'll find:

    void ConsoleReporter::lazyPrintRunInfo() {
        stream << '\n' << lineOfChars('~') << '\n';
        Colour colour(Colour::SecondaryText);
        stream << currentTestRunInfo->name
            << " is a Catch v" << libraryVersion() << " host application.\n"
            << "Run with -? for options\n\n";
    

    Just remove this last line. It should not break anything and fix your issue.

    Alternatively, you can edit src/catch2/interfaces/catch_interfaces_config.hpp and add a configuration option, virtual bool printHeader(); and submit a PR. This config is used just the line after printing the header, so it is available.