1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-15 14:48:00 +00:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Daniel Edwards
aba114d6fe Don't include CTest in non-development builds.
When Catch2 is used as a CMake subproject (via add_subdirectory) and is not built in development mode (CATCH_DEVELOPMENT_BUILD) CTest is not required for the build, as testing is off. When CTest is included it creates various targets (around 20) which are shown in IDEs such as Clion and pollute the list of configurations.

This patch conditionally includes CTest only if Catch2 is built in development mode.
2021-05-29 16:24:44 +02:00
Martin Hořeňovský
0221148ac3
Cleanup string escaping in XmlWriter with raw string literals 2021-05-29 14:11:50 +02:00
Martin Hořeňovský
9f091cbe9d
Remove some code duplication from default test listing impl 2021-05-29 14:06:40 +02:00
Martin Hořeňovský
4c1e896d47
Flush less in default test listing impl 2021-05-29 13:52:23 +02:00
Martin Hořeňovský
2c04850f88
Add some constexpr in compact reporter impl 2021-05-29 13:49:33 +02:00
Martin Hořeňovský
c9027375a3
Replace std::endl with \n and flush
In some places the `std::flush` was not added, as it was sufficiently
obvious that the flush semantics are not intended. There are likely
other places where the flush semantics aren't intended, but that
is a cleanup for later.
2021-05-29 13:15:46 +02:00
Martin Hořeňovský
2ae28fc852
Use make_unique instead of unique_ptr(new T) in more places 2021-05-28 23:43:15 +02:00
Martin Hořeňovský
f9ec34ce01
Make operator BenchmarkStats<Duration2> explicit 2021-05-28 23:19:07 +02:00
10 changed files with 42 additions and 39 deletions

View File

@ -41,7 +41,9 @@ project(Catch2 LANGUAGES CXX VERSION 3.0.0)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CTest)
if(CATCH_DEVELOPMENT_BUILD)
include(CTest)
endif()
# This variable is used in some subdirectories, so we need it here, rather
# than later in the install block

View File

@ -950,7 +950,7 @@ namespace Catch {
#include <iosfwd>
namespace Catch {
struct ITransientExpression;
class LazyExpression {
@ -1430,7 +1430,7 @@ namespace Catch {
double outlierVariance;
template <typename Duration2>
operator BenchmarkStats<Duration2>() const {
explicit operator BenchmarkStats<Duration2>() const {
std::vector<Duration2> samples2;
samples2.reserve(samples.size());
for (auto const& sample : samples) {
@ -2575,7 +2575,7 @@ namespace Catch {
analysis.outlier_variance,
};
} else {
std::vector<Duration> samples;
std::vector<Duration> samples;
samples.reserve(last - first);
Duration mean = Duration(0);

View File

@ -161,16 +161,16 @@ namespace Catch {
void Session::showHelp() const {
Catch::cout()
<< "\nCatch v" << libraryVersion() << "\n"
<< m_cli << std::endl
<< "For more detailed usage please see the project docs\n" << std::endl;
<< "\nCatch v" << libraryVersion() << '\n'
<< m_cli << '\n'
<< "For more detailed usage please see the project docs\n\n" << std::flush;
}
void Session::libIdentify() {
Catch::cout()
<< std::left << std::setw(16) << "description: " << "A Catch2 test executable\n"
<< std::left << std::setw(16) << "category: " << "testframework\n"
<< std::left << std::setw(16) << "framework: " << "Catch Test\n"
<< std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
<< std::left << std::setw(16) << "version: " << libraryVersion() << '\n' << std::flush;
}
int Session::applyCommandLine( int argc, char const * const * argv ) {
@ -186,7 +186,7 @@ namespace Catch {
<< "\nError(s) in input:\n"
<< TextFlow::Column( result.errorMessage() ).indent( 2 )
<< "\n\n";
Catch::cerr() << "Run with -? for usage\n" << std::endl;
Catch::cerr() << "Run with -? for usage\n\n" << std::flush;
return MaxExitCode;
}
@ -229,12 +229,12 @@ namespace Catch {
int Session::run() {
if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
Catch::cout() << "...waiting for enter/ return before starting\n" << std::flush;
static_cast<void>(std::getchar());
}
int exitCode = runInternal();
if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << '\n' << std::flush;
static_cast<void>(std::getchar());
}
return exitCode;
@ -296,7 +296,7 @@ namespace Catch {
}
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
catch( std::exception& ex ) {
Catch::cerr() << ex.what() << std::endl;
Catch::cerr() << ex.what() << '\n' << std::flush;
return MaxExitCode;
}
#endif

View File

@ -53,7 +53,7 @@
size = sizeof(info);
if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) {
Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n\n" << std::flush;
return false;
}

View File

@ -14,7 +14,7 @@
namespace Catch {
Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() ) {
return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsFunction( testAsFunction ));
return Detail::make_unique<TestInvokerAsFunction>( testAsFunction );
}
AutoReg::AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept {

View File

@ -42,7 +42,7 @@ Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
template<typename C>
Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsMethod<C>(testAsMethod) );
return Detail::make_unique<TestInvokerAsMethod<C>>( testAsMethod );
}
struct NameAndTags {

View File

@ -302,7 +302,7 @@ namespace {
}
void XmlWriter::writeStylesheetRef( std::string const& url ) {
m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n";
m_os << R"(<?xml-stylesheet type="text/xsl" href=")" << url << R"("?>)" << '\n';
}
XmlWriter& XmlWriter::writeBlankLine() {
@ -324,12 +324,12 @@ namespace {
}
void XmlWriter::writeDeclaration() {
m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
m_os << R"(<?xml version="1.0" encoding="UTF-8"?>)" << '\n';
}
void XmlWriter::newlineIfNecessary() {
if( m_needsNewline ) {
m_os << std::endl;
m_os << '\n' << std::flush;
m_needsNewline = false;
}
}

View File

@ -169,7 +169,7 @@ namespace Catch {
.width( CATCH_CONFIG_CONSOLE_WIDTH - 10 );
out << str << wrapper << '\n';
}
out << pluralise( tags.size(), "tag" ) << '\n' << std::endl;
out << pluralise(tags.size(), "tag") << "\n\n" << std::flush;
}
void defaultListTests(std::ostream& out, std::vector<TestCaseHandle> const& tests, bool isFiltered, Verbosity verbosity) {
@ -196,7 +196,7 @@ namespace Catch {
out << TextFlow::Column(testCaseInfo.name).initialIndent(2).indent(4) << '\n';
if (verbosity >= Verbosity::High) {
out << TextFlow::Column(Catch::Detail::stringify(testCaseInfo.lineInfo)).indent(4) << std::endl;
out << TextFlow::Column(Catch::Detail::stringify(testCaseInfo.lineInfo)).indent(4) << '\n';
}
if (!testCaseInfo.tags.empty() &&
verbosity > Verbosity::Quiet) {
@ -205,10 +205,11 @@ namespace Catch {
}
if (isFiltered) {
out << pluralise(tests.size(), "matching test case") << '\n' << std::endl;
out << pluralise(tests.size(), "matching test case");
} else {
out << pluralise(tests.size(), "test case") << '\n' << std::endl;
out << pluralise(tests.size(), "test case");
}
out << "\n\n" << std::flush;
}
} // namespace Catch

View File

@ -19,9 +19,9 @@
namespace {
// Colour::LightGrey
Catch::Colour::Code dimColour() { return Catch::Colour::FileName; }
constexpr Catch::Colour::Code dimColour() { return Catch::Colour::FileName; }
Catch::StringRef bothOrAll( std::size_t count ) {
constexpr Catch::StringRef bothOrAll( std::size_t count ) {
switch (count) {
case 1:
return Catch::StringRef{};
@ -259,7 +259,7 @@ private:
}
void CompactReporter::noMatchingTestCases( std::string const& spec ) {
stream << "No test cases matched '" << spec << '\'' << std::endl;
stream << "No test cases matched '" << spec << "'\n";
}
void CompactReporter::assertionStarting( AssertionInfo const& ) {}
@ -279,20 +279,20 @@ private:
AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
printer.print();
stream << std::endl;
stream << '\n' << std::flush;
return true;
}
void CompactReporter::sectionEnded(SectionStats const& _sectionStats) {
double dur = _sectionStats.durationInSeconds;
if ( shouldShowDuration( *m_config, dur ) ) {
stream << getFormattedDuration( dur ) << " s: " << _sectionStats.sectionInfo.name << std::endl;
stream << getFormattedDuration( dur ) << " s: " << _sectionStats.sectionInfo.name << '\n' << std::flush;
}
}
void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) {
printTotals( stream, _testRunStats.totals );
stream << '\n' << std::endl;
stream << "\n\n" << std::flush;
StreamingReporterBase::testRunEnded( _testRunStats );
}

View File

@ -310,7 +310,7 @@ public:
void close() {
if (m_isOpen) {
*this << RowBreak();
m_os << std::endl;
m_os << '\n' << std::flush;
m_isOpen = false;
}
}
@ -354,7 +354,7 @@ public:
ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
: StreamingReporterBase(config),
m_tablePrinter(new TablePrinter(config.stream(),
m_tablePrinter(Detail::make_unique<TablePrinter>(config.stream(),
[&config]() -> std::vector<ColumnInfo> {
if (config.fullConfig()->benchmarkNoAnalysis())
{
@ -382,11 +382,11 @@ std::string ConsoleReporter::getDescription() {
}
void ConsoleReporter::noMatchingTestCases(std::string const& spec) {
stream << "No test cases matched '" << spec << '\'' << std::endl;
stream << "No test cases matched '" << spec << "'\n";
}
void ConsoleReporter::reportInvalidArguments(std::string const&arg){
stream << "Invalid Filter: " << arg << std::endl;
void ConsoleReporter::reportInvalidArguments(std::string const& arg) {
stream << "Invalid Filter: " << arg << '\n';
}
void ConsoleReporter::assertionStarting(AssertionInfo const&) {}
@ -404,7 +404,7 @@ bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) {
ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults);
printer.print();
stream << std::endl;
stream << '\n' << std::flush;
return true;
}
@ -422,11 +422,11 @@ void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) {
stream << "\nNo assertions in section";
else
stream << "\nNo assertions in test case";
stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
stream << " '" << _sectionStats.sectionInfo.name << "'\n\n" << std::flush;
}
double dur = _sectionStats.durationInSeconds;
if (shouldShowDuration(*m_config, dur)) {
stream << getFormattedDuration(dur) << " s: " << _sectionStats.sectionInfo.name << std::endl;
stream << getFormattedDuration(dur) << " s: " << _sectionStats.sectionInfo.name << '\n' << std::flush;
}
if (m_headerPrinted) {
m_headerPrinted = false;
@ -490,14 +490,14 @@ void ConsoleReporter::testGroupEnded(TestGroupStats const& _testGroupStats) {
printSummaryDivider();
stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
printTotals(_testGroupStats.totals);
stream << '\n' << std::endl;
stream << "\n\n" << std::flush;
}
StreamingReporterBase::testGroupEnded(_testGroupStats);
}
void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) {
printTotalsDivider(_testRunStats.totals);
printTotals(_testRunStats.totals);
stream << std::endl;
stream << '\n' << std::flush;
StreamingReporterBase::testRunEnded(_testRunStats);
}
void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) {
@ -561,7 +561,7 @@ void ConsoleReporter::printTestCaseAndSectionHeader() {
stream << lineOfChars('-') << '\n';
Colour colourGuard(Colour::FileName);
stream << lineInfo << '\n';
stream << lineOfChars('.') << '\n' << std::endl;
stream << lineOfChars('.') << "\n\n" << std::flush;
}
void ConsoleReporter::printClosedHeader(std::string const& _name) {