mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 05:16:10 +01:00
Fix various useful clang-tidy warnings
* bugprone-branch-clone * bugprone-copy-constructor-init * bugprone-empty-catch * bugprone-sizeof-expression * bugprone-switch-missing-default-case * bugprone-unused-local-non-trivial-variable * clang-analyzer-core.uninitialized.Assign * clang-analyzer-cplusplus.Move * clang-analyzer-optin.cplusplus.VirtualCall * modernize-loop-convert * modernize-raw-string-literal * modernize-use-equals-default * modernize-use-override * modernize-use-using * performance-avoid-endl * performance-inefficient-string-concatenation * performance-inefficient-vector-operation * performance-noexcept-move-constructor * performance-unnecessary-value-param (and improve generator example) * readability-duplicate-include * readability-inconsistent-declaration-parameter-name * readability-non-const-parameter * readability-redundant-casting * readability-redundant-member-init * readability-redundant-smartptr-get * readability-static-accessed-through-instance * unused variable in amalgamted tests
This commit is contained in:
parent
7677c1658e
commit
cde3509664
@ -385,8 +385,7 @@ struct MyListener : Catch::EventListenerBase {
|
|||||||
CATCH_REGISTER_LISTENER( MyListener )
|
CATCH_REGISTER_LISTENER( MyListener )
|
||||||
|
|
||||||
// Get rid of Wweak-tables
|
// Get rid of Wweak-tables
|
||||||
MyListener::~MyListener() {}
|
MyListener::~MyListener() = default;
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// 3. Test cases:
|
// 3. Test cases:
|
||||||
|
@ -22,7 +22,7 @@ class out_buff : public std::stringbuf {
|
|||||||
std::FILE* m_stream;
|
std::FILE* m_stream;
|
||||||
public:
|
public:
|
||||||
out_buff(std::FILE* stream):m_stream(stream) {}
|
out_buff(std::FILE* stream):m_stream(stream) {}
|
||||||
~out_buff();
|
~out_buff() override;
|
||||||
int sync() override {
|
int sync() override {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
for (unsigned char c : str()) {
|
for (unsigned char c : str()) {
|
||||||
|
@ -35,7 +35,7 @@ int main(int argc, char** argv) {
|
|||||||
return returnCode;
|
return returnCode;
|
||||||
|
|
||||||
// if set on the command line then 'height' is now set at this point
|
// if set on the command line then 'height' is now set at this point
|
||||||
std::cout << "height: " << height << std::endl;
|
std::cout << "height: " << height << '\n';
|
||||||
|
|
||||||
return session.run();
|
return session.run();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// This class shows how to implement a simple generator for Catch tests
|
// This class shows how to implement a simple generator for Catch tests
|
||||||
class RandomIntGenerator : public Catch::Generators::IGenerator<int> {
|
class RandomIntGenerator final : public Catch::Generators::IGenerator<int> {
|
||||||
std::minstd_rand m_rand;
|
std::minstd_rand m_rand;
|
||||||
std::uniform_int_distribution<> m_dist;
|
std::uniform_int_distribution<> m_dist;
|
||||||
int current_number;
|
int current_number;
|
||||||
|
@ -24,12 +24,12 @@ namespace {
|
|||||||
// Returns a line from a stream. You could have it e.g. read lines from
|
// Returns a line from a stream. You could have it e.g. read lines from
|
||||||
// a file, but to avoid problems with paths in examples, we will use
|
// a file, but to avoid problems with paths in examples, we will use
|
||||||
// a fixed stringstream.
|
// a fixed stringstream.
|
||||||
class LineGenerator : public Catch::Generators::IGenerator<std::string> {
|
class LineGenerator final : public Catch::Generators::IGenerator<std::string> {
|
||||||
std::string m_line;
|
std::string m_line;
|
||||||
std::stringstream m_stream;
|
std::stringstream m_stream;
|
||||||
public:
|
public:
|
||||||
LineGenerator() {
|
explicit LineGenerator( std::string const& lines ) {
|
||||||
m_stream.str("1\n2\n3\n4\n");
|
m_stream.str( lines );
|
||||||
if (!next()) {
|
if (!next()) {
|
||||||
Catch::Generators::Detail::throw_generator_exception("Couldn't read a single line");
|
Catch::Generators::Detail::throw_generator_exception("Couldn't read a single line");
|
||||||
}
|
}
|
||||||
@ -49,18 +49,19 @@ std::string const& LineGenerator::get() const {
|
|||||||
// This helper function provides a nicer UX when instantiating the generator
|
// This helper function provides a nicer UX when instantiating the generator
|
||||||
// Notice that it returns an instance of GeneratorWrapper<std::string>, which
|
// Notice that it returns an instance of GeneratorWrapper<std::string>, which
|
||||||
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
|
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
|
||||||
Catch::Generators::GeneratorWrapper<std::string> lines(std::string /* ignored for example */) {
|
Catch::Generators::GeneratorWrapper<std::string>
|
||||||
|
lines( std::string const& lines ) {
|
||||||
return Catch::Generators::GeneratorWrapper<std::string>(
|
return Catch::Generators::GeneratorWrapper<std::string>(
|
||||||
new LineGenerator()
|
new LineGenerator( lines ) );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("filter can convert types inside the generator expression", "[example][generator]") {
|
TEST_CASE("filter can convert types inside the generator expression", "[example][generator]") {
|
||||||
auto num = GENERATE(map<int>([](std::string const& line) { return std::stoi(line); },
|
auto num = GENERATE(
|
||||||
lines("fake-file")));
|
map<int>( []( std::string const& line ) { return std::stoi( line ); },
|
||||||
|
lines( "1\n2\n3\n4\n" ) ) );
|
||||||
|
|
||||||
REQUIRE(num > 0);
|
REQUIRE(num > 0);
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ namespace Catch {
|
|||||||
m_messages.back().message += " := ";
|
m_messages.back().message += " := ";
|
||||||
start = pos;
|
start = pos;
|
||||||
}
|
}
|
||||||
|
default:; // noop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(openings.empty() && "Mismatched openings");
|
assert(openings.empty() && "Mismatched openings");
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <catch2/internal/catch_noncopyable.hpp>
|
#include <catch2/internal/catch_noncopyable.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
||||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||||
#include <catch2/internal/catch_reporter_registry.hpp>
|
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ namespace Catch {
|
|||||||
struct TestCaseInfo : Detail::NonCopyable {
|
struct TestCaseInfo : Detail::NonCopyable {
|
||||||
|
|
||||||
TestCaseInfo(StringRef _className,
|
TestCaseInfo(StringRef _className,
|
||||||
NameAndTags const& _tags,
|
NameAndTags const& _nameAndTags,
|
||||||
SourceLineInfo const& _lineInfo);
|
SourceLineInfo const& _lineInfo);
|
||||||
|
|
||||||
bool isHidden() const;
|
bool isHidden() const;
|
||||||
|
@ -54,13 +54,13 @@ namespace Detail {
|
|||||||
}
|
}
|
||||||
} // end unnamed namespace
|
} // end unnamed namespace
|
||||||
|
|
||||||
std::string convertIntoString(StringRef string, bool escape_invisibles) {
|
std::string convertIntoString(StringRef string, bool escapeInvisibles) {
|
||||||
std::string ret;
|
std::string ret;
|
||||||
// This is enough for the "don't escape invisibles" case, and a good
|
// This is enough for the "don't escape invisibles" case, and a good
|
||||||
// lower bound on the "escape invisibles" case.
|
// lower bound on the "escape invisibles" case.
|
||||||
ret.reserve(string.size() + 2);
|
ret.reserve(string.size() + 2);
|
||||||
|
|
||||||
if (!escape_invisibles) {
|
if (!escapeInvisibles) {
|
||||||
ret += '"';
|
ret += '"';
|
||||||
ret += string;
|
ret += string;
|
||||||
ret += '"';
|
ret += '"';
|
||||||
@ -138,7 +138,7 @@ std::string StringMaker<char const*>::convert(char const* str) {
|
|||||||
return{ "{null string}" };
|
return{ "{null string}" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string StringMaker<char*>::convert(char* str) {
|
std::string StringMaker<char*>::convert(char* str) { // NOLINT(readability-non-const-parameter)
|
||||||
if (str) {
|
if (str) {
|
||||||
return Detail::convertIntoString( str );
|
return Detail::convertIntoString( str );
|
||||||
} else {
|
} else {
|
||||||
@ -235,8 +235,8 @@ std::string StringMaker<signed char>::convert(signed char value) {
|
|||||||
std::string StringMaker<char>::convert(char c) {
|
std::string StringMaker<char>::convert(char c) {
|
||||||
return ::Catch::Detail::stringify(static_cast<signed char>(c));
|
return ::Catch::Detail::stringify(static_cast<signed char>(c));
|
||||||
}
|
}
|
||||||
std::string StringMaker<unsigned char>::convert(unsigned char c) {
|
std::string StringMaker<unsigned char>::convert(unsigned char value) {
|
||||||
return ::Catch::Detail::stringify(static_cast<char>(c));
|
return ::Catch::Detail::stringify(static_cast<char>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
int StringMaker<float>::precision = 5;
|
int StringMaker<float>::precision = 5;
|
||||||
|
@ -279,11 +279,11 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct StringMaker<signed char> {
|
struct StringMaker<signed char> {
|
||||||
static std::string convert(signed char c);
|
static std::string convert(signed char value);
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct StringMaker<unsigned char> {
|
struct StringMaker<unsigned char> {
|
||||||
static std::string convert(unsigned char c);
|
static std::string convert(unsigned char value);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -47,7 +47,7 @@ namespace Catch {
|
|||||||
line = trim(line);
|
line = trim(line);
|
||||||
if( !line.empty() && !startsWith( line, '#' ) ) {
|
if( !line.empty() && !startsWith( line, '#' ) ) {
|
||||||
if( !startsWith( line, '"' ) )
|
if( !startsWith( line, '"' ) )
|
||||||
line = '"' + line + '"';
|
line = '"' + CATCH_MOVE(line) + '"';
|
||||||
config.testsOrTags.push_back( line );
|
config.testsOrTags.push_back( line );
|
||||||
config.testsOrTags.emplace_back( "," );
|
config.testsOrTags.emplace_back( "," );
|
||||||
}
|
}
|
||||||
|
@ -230,21 +230,21 @@ namespace {
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode implSelection,
|
Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
|
||||||
IStream* stream ) {
|
IStream* stream ) {
|
||||||
#if defined( CATCH_CONFIG_COLOUR_WIN32 )
|
#if defined( CATCH_CONFIG_COLOUR_WIN32 )
|
||||||
if ( implSelection == ColourMode::Win32 ) {
|
if ( colourSelection == ColourMode::Win32 ) {
|
||||||
return Detail::make_unique<Win32ColourImpl>( stream );
|
return Detail::make_unique<Win32ColourImpl>( stream );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ( implSelection == ColourMode::ANSI ) {
|
if ( colourSelection == ColourMode::ANSI ) {
|
||||||
return Detail::make_unique<ANSIColourImpl>( stream );
|
return Detail::make_unique<ANSIColourImpl>( stream );
|
||||||
}
|
}
|
||||||
if ( implSelection == ColourMode::None ) {
|
if ( colourSelection == ColourMode::None ) {
|
||||||
return Detail::make_unique<NoColourImpl>( stream );
|
return Detail::make_unique<NoColourImpl>( stream );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( implSelection == ColourMode::PlatformDefault) {
|
if ( colourSelection == ColourMode::PlatformDefault) {
|
||||||
#if defined( CATCH_CONFIG_COLOUR_WIN32 )
|
#if defined( CATCH_CONFIG_COLOUR_WIN32 )
|
||||||
if ( Win32ColourImpl::useImplementationForStream( *stream ) ) {
|
if ( Win32ColourImpl::useImplementationForStream( *stream ) ) {
|
||||||
return Detail::make_unique<Win32ColourImpl>( stream );
|
return Detail::make_unique<Win32ColourImpl>( stream );
|
||||||
@ -256,7 +256,7 @@ namespace Catch {
|
|||||||
return Detail::make_unique<NoColourImpl>( stream );
|
return Detail::make_unique<NoColourImpl>( stream );
|
||||||
}
|
}
|
||||||
|
|
||||||
CATCH_ERROR( "Could not create colour impl for selection " << static_cast<int>(implSelection) );
|
CATCH_ERROR( "Could not create colour impl for selection " << static_cast<int>(colourSelection) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isColourImplAvailable( ColourMode colourSelection ) {
|
bool isColourImplAvailable( ColourMode colourSelection ) {
|
||||||
|
@ -24,7 +24,7 @@ namespace Catch {
|
|||||||
|
|
||||||
std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos;
|
std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos;
|
||||||
|
|
||||||
EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
|
EnumInfo const& registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<StringRef> parseEnums( StringRef enums );
|
std::vector<StringRef> parseEnums( StringRef enums );
|
||||||
|
@ -31,7 +31,7 @@ namespace Catch {
|
|||||||
m_os{ os }, m_indent_level{ indent_level } {
|
m_os{ os }, m_indent_level{ indent_level } {
|
||||||
m_os << '{';
|
m_os << '{';
|
||||||
}
|
}
|
||||||
JsonObjectWriter::JsonObjectWriter( JsonObjectWriter&& source ):
|
JsonObjectWriter::JsonObjectWriter( JsonObjectWriter&& source ) noexcept:
|
||||||
m_os{ source.m_os },
|
m_os{ source.m_os },
|
||||||
m_indent_level{ source.m_indent_level },
|
m_indent_level{ source.m_indent_level },
|
||||||
m_should_comma{ source.m_should_comma },
|
m_should_comma{ source.m_should_comma },
|
||||||
@ -62,7 +62,7 @@ namespace Catch {
|
|||||||
m_os{ os }, m_indent_level{ indent_level } {
|
m_os{ os }, m_indent_level{ indent_level } {
|
||||||
m_os << '[';
|
m_os << '[';
|
||||||
}
|
}
|
||||||
JsonArrayWriter::JsonArrayWriter( JsonArrayWriter&& source ):
|
JsonArrayWriter::JsonArrayWriter( JsonArrayWriter&& source ) noexcept:
|
||||||
m_os{ source.m_os },
|
m_os{ source.m_os },
|
||||||
m_indent_level{ source.m_indent_level },
|
m_indent_level{ source.m_indent_level },
|
||||||
m_should_comma{ source.m_should_comma },
|
m_should_comma{ source.m_should_comma },
|
||||||
|
@ -65,7 +65,7 @@ namespace Catch {
|
|||||||
JsonObjectWriter( std::ostream& os );
|
JsonObjectWriter( std::ostream& os );
|
||||||
JsonObjectWriter( std::ostream& os, std::uint64_t indent_level );
|
JsonObjectWriter( std::ostream& os, std::uint64_t indent_level );
|
||||||
|
|
||||||
JsonObjectWriter( JsonObjectWriter&& source );
|
JsonObjectWriter( JsonObjectWriter&& source ) noexcept;
|
||||||
JsonObjectWriter& operator=( JsonObjectWriter&& source ) = delete;
|
JsonObjectWriter& operator=( JsonObjectWriter&& source ) = delete;
|
||||||
|
|
||||||
~JsonObjectWriter();
|
~JsonObjectWriter();
|
||||||
@ -84,7 +84,7 @@ namespace Catch {
|
|||||||
JsonArrayWriter( std::ostream& os );
|
JsonArrayWriter( std::ostream& os );
|
||||||
JsonArrayWriter( std::ostream& os, std::uint64_t indent_level );
|
JsonArrayWriter( std::ostream& os, std::uint64_t indent_level );
|
||||||
|
|
||||||
JsonArrayWriter( JsonArrayWriter&& source );
|
JsonArrayWriter( JsonArrayWriter&& source ) noexcept;
|
||||||
JsonArrayWriter& operator=( JsonArrayWriter&& source ) = delete;
|
JsonArrayWriter& operator=( JsonArrayWriter&& source ) = delete;
|
||||||
|
|
||||||
~JsonArrayWriter();
|
~JsonArrayWriter();
|
||||||
|
@ -117,7 +117,7 @@ namespace Catch {
|
|||||||
auto kv = splitKVPair( parts[i] );
|
auto kv = splitKVPair( parts[i] );
|
||||||
auto key = kv.key, value = kv.value;
|
auto key = kv.key, value = kv.value;
|
||||||
|
|
||||||
if ( key.empty() || value.empty() ) {
|
if ( key.empty() || value.empty() ) { // NOLINT(bugprone-branch-clone)
|
||||||
return {};
|
return {};
|
||||||
} else if ( key[0] == 'X' ) {
|
} else if ( key[0] == 'X' ) {
|
||||||
// This is a reporter-specific option, we don't check these
|
// This is a reporter-specific option, we don't check these
|
||||||
|
@ -97,8 +97,8 @@ namespace Catch {
|
|||||||
constexpr const_iterator end() const { return m_start + m_size; }
|
constexpr const_iterator end() const { return m_start + m_size; }
|
||||||
|
|
||||||
|
|
||||||
friend std::string& operator += (std::string& lhs, StringRef sr);
|
friend std::string& operator += (std::string& lhs, StringRef rhs);
|
||||||
friend std::ostream& operator << (std::ostream& os, StringRef sr);
|
friend std::ostream& operator << (std::ostream& os, StringRef str);
|
||||||
friend std::string operator+(StringRef lhs, StringRef rhs);
|
friend std::string operator+(StringRef lhs, StringRef rhs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -520,8 +520,8 @@ void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) {
|
|||||||
m_stream << '\n' << std::flush;
|
m_stream << '\n' << std::flush;
|
||||||
StreamingReporterBase::testRunEnded(_testRunStats);
|
StreamingReporterBase::testRunEnded(_testRunStats);
|
||||||
}
|
}
|
||||||
void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) {
|
void ConsoleReporter::testRunStarting(TestRunInfo const& _testRunInfo) {
|
||||||
StreamingReporterBase::testRunStarting(_testInfo);
|
StreamingReporterBase::testRunStarting(_testRunInfo);
|
||||||
if ( m_config->testSpec().hasFilters() ) {
|
if ( m_config->testSpec().hasFilters() ) {
|
||||||
m_stream << m_colour->guardColour( Colour::BrightYellow ) << "Filters: "
|
m_stream << m_colour->guardColour( Colour::BrightYellow ) << "Filters: "
|
||||||
<< m_config->testSpec() << '\n';
|
<< m_config->testSpec() << '\n';
|
||||||
|
@ -16,8 +16,7 @@ namespace Catch {
|
|||||||
namespace {
|
namespace {
|
||||||
struct BySectionInfo {
|
struct BySectionInfo {
|
||||||
BySectionInfo( SectionInfo const& other ): m_other( other ) {}
|
BySectionInfo( SectionInfo const& other ): m_other( other ) {}
|
||||||
BySectionInfo( BySectionInfo const& other ):
|
BySectionInfo( BySectionInfo const& other ) = default;
|
||||||
m_other( other.m_other ) {}
|
|
||||||
bool operator()(
|
bool operator()(
|
||||||
Detail::unique_ptr<CumulativeReporterBase::SectionNode> const&
|
Detail::unique_ptr<CumulativeReporterBase::SectionNode> const&
|
||||||
node ) const {
|
node ) const {
|
||||||
|
@ -133,8 +133,8 @@ namespace Catch {
|
|||||||
return "Outputs listings as JSON. Test listing is Work-in-Progress!";
|
return "Outputs listings as JSON. Test listing is Work-in-Progress!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonReporter::testRunStarting( TestRunInfo const& testInfo ) {
|
void JsonReporter::testRunStarting( TestRunInfo const& runInfo ) {
|
||||||
StreamingReporterBase::testRunStarting( testInfo );
|
StreamingReporterBase::testRunStarting( runInfo );
|
||||||
endListing();
|
endListing();
|
||||||
|
|
||||||
assert( isInside( Writer::Object ) );
|
assert( isInside( Writer::Object ) );
|
||||||
|
@ -74,7 +74,7 @@ namespace Catch {
|
|||||||
|
|
||||||
static void normalizeNamespaceMarkers(std::string& str) {
|
static void normalizeNamespaceMarkers(std::string& str) {
|
||||||
std::size_t pos = str.find( "::" );
|
std::size_t pos = str.find( "::" );
|
||||||
while ( pos != str.npos ) {
|
while ( pos != std::string::npos ) {
|
||||||
str.replace( pos, 2, "." );
|
str.replace( pos, 2, "." );
|
||||||
pos += 1;
|
pos += 1;
|
||||||
pos = str.find( "::", pos );
|
pos = str.find( "::", pos );
|
||||||
|
@ -53,7 +53,7 @@ namespace Catch {
|
|||||||
|
|
||||||
void assertionEnded( AssertionStats const& assertionStats ) override;
|
void assertionEnded( AssertionStats const& assertionStats ) override;
|
||||||
void sectionEnded( SectionStats const& sectionStats ) override;
|
void sectionEnded( SectionStats const& sectionStats ) override;
|
||||||
void testCasePartialEnded(TestCaseStats const& testInfo, uint64_t partNumber) override;
|
void testCasePartialEnded(TestCaseStats const& testStats, uint64_t partNumber) override;
|
||||||
void testCaseEnded( TestCaseStats const& testCaseStats ) override;
|
void testCaseEnded( TestCaseStats const& testCaseStats ) override;
|
||||||
void testRunEnded( TestRunStats const& testRunStats ) override;
|
void testRunEnded( TestRunStats const& testRunStats ) override;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ namespace Catch {
|
|||||||
xml.endElement();
|
xml.endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeRun( TestRunNode const& groupNode );
|
void writeRun( TestRunNode const& runNode );
|
||||||
|
|
||||||
void writeTestFile(StringRef filename, std::vector<TestCaseNode const*> const& testCaseNodes);
|
void writeTestFile(StringRef filename, std::vector<TestCaseNode const*> const& testCaseNodes);
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ namespace Catch {
|
|||||||
return "Reports test results as TeamCity service messages"s;
|
return "Reports test results as TeamCity service messages"s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testRunStarting( TestRunInfo const& groupInfo ) override;
|
void testRunStarting( TestRunInfo const& runInfo ) override;
|
||||||
void testRunEnded( TestRunStats const& testGroupStats ) override;
|
void testRunEnded( TestRunStats const& runStats ) override;
|
||||||
|
|
||||||
|
|
||||||
void assertionEnded(AssertionStats const& assertionStats) override;
|
void assertionEnded(AssertionStats const& assertionStats) override;
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
return "Custom reporter for testing cumulative reporter base";
|
return "Custom reporter for testing cumulative reporter base";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void testRunEndedCumulative() override;
|
void testRunEndedCumulative() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
CATCH_REGISTER_REPORTER("testReporter", CumulativeBenchmarkReporter)
|
CATCH_REGISTER_REPORTER("testReporter", CumulativeBenchmarkReporter)
|
||||||
|
@ -36,6 +36,7 @@ public:
|
|||||||
|
|
||||||
void testRunStarting( Catch::TestRunInfo const& ) override {
|
void testRunStarting( Catch::TestRunInfo const& ) override {
|
||||||
std::vector<std::pair<std::string, std::string>> options;
|
std::vector<std::pair<std::string, std::string>> options;
|
||||||
|
options.reserve( m_customOptions.size() );
|
||||||
for ( auto const& kv : m_customOptions ) {
|
for ( auto const& kv : m_customOptions ) {
|
||||||
options.push_back( kv );
|
options.push_back( kv );
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
TEST_CASE("Just a dummy test") {
|
TEST_CASE("Just a dummy test") {
|
||||||
auto i = GENERATE(1, 2, 3);
|
auto i = GENERATE(1, 2, 3);
|
||||||
SECTION("a") {
|
SECTION("a") {
|
||||||
REQUIRE(1 != 4);
|
REQUIRE(i != 4);
|
||||||
}
|
}
|
||||||
SECTION("b") {
|
SECTION("b") {
|
||||||
CHECK(1 != 5);
|
CHECK(i != 5);
|
||||||
}
|
}
|
||||||
REQUIRE_THAT(1,
|
REQUIRE_THAT(1,
|
||||||
Catch::Matchers::Predicate<int>([](int i) {
|
Catch::Matchers::Predicate<int>([](int i) {
|
||||||
|
@ -120,13 +120,13 @@ TEST_CASE( "Optional supports move ops", "[optional][approvals]" ) {
|
|||||||
}
|
}
|
||||||
SECTION( "Move construction from optional" ) {
|
SECTION( "Move construction from optional" ) {
|
||||||
Optional<MoveChecker> opt_B( CATCH_MOVE( opt_A ) );
|
Optional<MoveChecker> opt_B( CATCH_MOVE( opt_A ) );
|
||||||
REQUIRE( opt_A->has_moved );
|
REQUIRE( opt_A->has_moved ); // NOLINT(clang-analyzer-cplusplus.Move)
|
||||||
}
|
}
|
||||||
SECTION( "Move assignment from optional" ) {
|
SECTION( "Move assignment from optional" ) {
|
||||||
Optional<MoveChecker> opt_B( opt_A );
|
Optional<MoveChecker> opt_B( opt_A );
|
||||||
REQUIRE_FALSE( opt_A->has_moved );
|
REQUIRE_FALSE( opt_A->has_moved );
|
||||||
opt_B = CATCH_MOVE( opt_A );
|
opt_B = CATCH_MOVE( opt_A );
|
||||||
REQUIRE( opt_A->has_moved );
|
REQUIRE( opt_A->has_moved ); // NOLINT(clang-analyzer-cplusplus.Move)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
#include <catch2/generators/catch_generators_adapters.hpp>
|
||||||
#include <catch2/generators/catch_generators_random.hpp>
|
#include <catch2/generators/catch_generators_random.hpp>
|
||||||
#include <catch2/generators/catch_generators_range.hpp>
|
#include <catch2/generators/catch_generators_range.hpp>
|
||||||
#include <catch2/generators/catch_generator_exception.hpp>
|
|
||||||
|
|
||||||
// Tests of generator implementation details
|
// Tests of generator implementation details
|
||||||
TEST_CASE("Generators internals", "[generators][internals]") {
|
TEST_CASE("Generators internals", "[generators][internals]") {
|
||||||
|
@ -107,7 +107,7 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) {
|
|||||||
for (auto const& factory : factories) {
|
for (auto const& factory : factories) {
|
||||||
INFO("Tested reporter: " << factory.first);
|
INFO("Tested reporter: " << factory.first);
|
||||||
auto sstream = Catch::Detail::make_unique<StringIStream>();
|
auto sstream = Catch::Detail::make_unique<StringIStream>();
|
||||||
auto& sstreamRef = *sstream.get();
|
auto& sstreamRef = *sstream;
|
||||||
|
|
||||||
Catch::ConfigData cfg_data;
|
Catch::ConfigData cfg_data;
|
||||||
cfg_data.rngSeed = 1234;
|
cfg_data.rngSeed = 1234;
|
||||||
|
@ -236,7 +236,7 @@ TEST_CASE( "Parse test names and tags", "[command-line][test-spec][approvals]" )
|
|||||||
CHECK( spec.matches( *tcD ) == false );
|
CHECK( spec.matches( *tcD ) == false );
|
||||||
}
|
}
|
||||||
SECTION( "two wildcarded names" ) {
|
SECTION( "two wildcarded names" ) {
|
||||||
TestSpec spec = parseTestSpec( "\"longer*\"\"*spaces\"" );
|
TestSpec spec = parseTestSpec( R"("longer*""*spaces")" );
|
||||||
CHECK( spec.hasFilters() == true );
|
CHECK( spec.hasFilters() == true );
|
||||||
CHECK( spec.matches( *tcA ) == false );
|
CHECK( spec.matches( *tcA ) == false );
|
||||||
CHECK( spec.matches( *tcB ) == false );
|
CHECK( spec.matches( *tcB ) == false );
|
||||||
|
@ -152,7 +152,7 @@ TEST_CASE( "TextFlow::Column respects indentation for empty lines",
|
|||||||
|
|
||||||
std::string written = as_written(col);
|
std::string written = as_written(col);
|
||||||
|
|
||||||
REQUIRE(as_written(col) == " \n \n third line");
|
REQUIRE(written == " \n \n third line");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "TextFlow::Column leading/trailing whitespace",
|
TEST_CASE( "TextFlow::Column leading/trailing whitespace",
|
||||||
|
@ -90,14 +90,14 @@ TEST_CASE("Benchmark containers", "[!benchmark]") {
|
|||||||
};
|
};
|
||||||
REQUIRE(v.size() == size);
|
REQUIRE(v.size() == size);
|
||||||
|
|
||||||
int array[size];
|
int array[size] {};
|
||||||
BENCHMARK("A fixed size array that should require no allocations") {
|
BENCHMARK("A fixed size array that should require no allocations") {
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
array[i] = i;
|
array[i] = i;
|
||||||
};
|
};
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int i = 0; i < size; ++i)
|
for (int val : array)
|
||||||
sum += array[i];
|
sum += val;
|
||||||
REQUIRE(sum > size);
|
REQUIRE(sum > size);
|
||||||
|
|
||||||
SECTION("XYZ") {
|
SECTION("XYZ") {
|
||||||
@ -121,8 +121,8 @@ TEST_CASE("Benchmark containers", "[!benchmark]") {
|
|||||||
runs = benchmarkIndex;
|
runs = benchmarkIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < v.size(); ++i) {
|
for (int val : v) {
|
||||||
REQUIRE(v[i] == runs);
|
REQUIRE(val == runs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,8 +135,8 @@ TEST_CASE("Benchmark containers", "[!benchmark]") {
|
|||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
v[i] = generated;
|
v[i] = generated;
|
||||||
};
|
};
|
||||||
for (size_t i = 0; i < v.size(); ++i) {
|
for (int val : v) {
|
||||||
REQUIRE(v[i] == generated);
|
REQUIRE(val == generated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct Template_Fixture_2 {
|
template <typename T> struct Template_Fixture_2 {
|
||||||
Template_Fixture_2() {}
|
Template_Fixture_2() = default;
|
||||||
|
|
||||||
T m_a;
|
T m_a;
|
||||||
};
|
};
|
||||||
|
@ -119,7 +119,7 @@ TEST_CASE( "When unchecked exceptions are thrown, but caught, they do not affect
|
|||||||
try {
|
try {
|
||||||
throw std::domain_error( "unexpected exception" );
|
throw std::domain_error( "unexpected exception" );
|
||||||
}
|
}
|
||||||
catch(...) {}
|
catch(...) {} // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ TEST_CASE( "Custom exceptions can be translated when testing for throwing as som
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Unexpected exceptions can be translated", "[.][failing][!throws]" ) {
|
TEST_CASE( "Unexpected exceptions can be translated", "[.][failing][!throws]" ) {
|
||||||
throw double( 3.14 );
|
throw double( 3.14 ); // NOLINT(readability-redundant-casting): the type is important here, so we want to be explicit
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Thrown string literals are translated", "[.][failing][!throws]") {
|
TEST_CASE("Thrown string literals are translated", "[.][failing][!throws]") {
|
||||||
|
@ -1027,7 +1027,6 @@ TEST_CASE( "Combining MatchNotOfGeneric does not nest",
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct EvilAddressOfOperatorUsed : std::exception {
|
struct EvilAddressOfOperatorUsed : std::exception {
|
||||||
EvilAddressOfOperatorUsed() {}
|
|
||||||
const char* what() const noexcept override {
|
const char* what() const noexcept override {
|
||||||
return "overloaded address-of operator of matcher was used instead of "
|
return "overloaded address-of operator of matcher was used instead of "
|
||||||
"std::addressof";
|
"std::addressof";
|
||||||
@ -1035,7 +1034,6 @@ struct EvilAddressOfOperatorUsed : std::exception {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct EvilCommaOperatorUsed : std::exception {
|
struct EvilCommaOperatorUsed : std::exception {
|
||||||
EvilCommaOperatorUsed() {}
|
|
||||||
const char* what() const noexcept override {
|
const char* what() const noexcept override {
|
||||||
return "overloaded comma operator of matcher was used";
|
return "overloaded comma operator of matcher was used";
|
||||||
}
|
}
|
||||||
@ -1073,7 +1071,6 @@ struct ImmovableMatcher : Catch::Matchers::MatcherGenericBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct MatcherWasMovedOrCopied : std::exception {
|
struct MatcherWasMovedOrCopied : std::exception {
|
||||||
MatcherWasMovedOrCopied() {}
|
|
||||||
const char* what() const noexcept override {
|
const char* what() const noexcept override {
|
||||||
return "attempted to copy or move a matcher";
|
return "attempted to copy or move a matcher";
|
||||||
}
|
}
|
||||||
@ -1081,17 +1078,20 @@ struct MatcherWasMovedOrCopied : std::exception {
|
|||||||
|
|
||||||
struct ThrowOnCopyOrMoveMatcher : Catch::Matchers::MatcherGenericBase {
|
struct ThrowOnCopyOrMoveMatcher : Catch::Matchers::MatcherGenericBase {
|
||||||
ThrowOnCopyOrMoveMatcher() = default;
|
ThrowOnCopyOrMoveMatcher() = default;
|
||||||
[[noreturn]] ThrowOnCopyOrMoveMatcher( ThrowOnCopyOrMoveMatcher const& ):
|
|
||||||
Catch::Matchers::MatcherGenericBase() {
|
[[noreturn]] ThrowOnCopyOrMoveMatcher( ThrowOnCopyOrMoveMatcher const& other ):
|
||||||
|
Catch::Matchers::MatcherGenericBase( other ) {
|
||||||
throw MatcherWasMovedOrCopied();
|
throw MatcherWasMovedOrCopied();
|
||||||
}
|
}
|
||||||
[[noreturn]] ThrowOnCopyOrMoveMatcher( ThrowOnCopyOrMoveMatcher&& ):
|
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
|
||||||
Catch::Matchers::MatcherGenericBase() {
|
[[noreturn]] ThrowOnCopyOrMoveMatcher( ThrowOnCopyOrMoveMatcher&& other ):
|
||||||
|
Catch::Matchers::MatcherGenericBase( CATCH_MOVE(other) ) {
|
||||||
throw MatcherWasMovedOrCopied();
|
throw MatcherWasMovedOrCopied();
|
||||||
}
|
}
|
||||||
ThrowOnCopyOrMoveMatcher& operator=( ThrowOnCopyOrMoveMatcher const& ) {
|
ThrowOnCopyOrMoveMatcher& operator=( ThrowOnCopyOrMoveMatcher const& ) {
|
||||||
throw MatcherWasMovedOrCopied();
|
throw MatcherWasMovedOrCopied();
|
||||||
}
|
}
|
||||||
|
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
|
||||||
ThrowOnCopyOrMoveMatcher& operator=( ThrowOnCopyOrMoveMatcher&& ) {
|
ThrowOnCopyOrMoveMatcher& operator=( ThrowOnCopyOrMoveMatcher&& ) {
|
||||||
throw MatcherWasMovedOrCopied();
|
throw MatcherWasMovedOrCopied();
|
||||||
}
|
}
|
||||||
|
@ -80,20 +80,20 @@ TEST_CASE( "Output from all sections is reported", "[failing][messages][.]" ) {
|
|||||||
|
|
||||||
TEST_CASE( "Standard output from all sections is reported", "[messages][.]" ) {
|
TEST_CASE( "Standard output from all sections is reported", "[messages][.]" ) {
|
||||||
SECTION( "one" ) {
|
SECTION( "one" ) {
|
||||||
std::cout << "Message from section one" << std::endl;
|
std::cout << "Message from section one\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "two" ) {
|
SECTION( "two" ) {
|
||||||
std::cout << "Message from section two" << std::endl;
|
std::cout << "Message from section two\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Standard error is reported and redirected", "[messages][.][approvals]" ) {
|
TEST_CASE( "Standard error is reported and redirected", "[messages][.][approvals]" ) {
|
||||||
SECTION( "std::cerr" ) {
|
SECTION( "std::cerr" ) {
|
||||||
std::cerr << "Write to std::cerr" << std::endl;
|
std::cerr << "Write to std::cerr\n";
|
||||||
}
|
}
|
||||||
SECTION( "std::clog" ) {
|
SECTION( "std::clog" ) {
|
||||||
std::clog << "Write to std::clog" << std::endl;
|
std::clog << "Write to std::clog\n";
|
||||||
}
|
}
|
||||||
SECTION( "Interleaved writes to cerr and clog" ) {
|
SECTION( "Interleaved writes to cerr and clog" ) {
|
||||||
std::cerr << "Inter";
|
std::cerr << "Inter";
|
||||||
@ -101,7 +101,7 @@ TEST_CASE( "Standard error is reported and redirected", "[messages][.][approvals
|
|||||||
std::cerr << ' ';
|
std::cerr << ' ';
|
||||||
std::clog << "writes";
|
std::clog << "writes";
|
||||||
std::cerr << " to error";
|
std::cerr << " to error";
|
||||||
std::clog << " streams" << std::endl;
|
std::clog << " streams\n" << std::flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,9 +158,9 @@ TEST_CASE( "looped tests", "[.][failing]" ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Sends stuff to stdout and stderr", "[.]" ) {
|
TEST_CASE( "Sends stuff to stdout and stderr", "[.]" ) {
|
||||||
std::cout << "A string sent directly to stdout" << std::endl;
|
std::cout << "A string sent directly to stdout\n" << std::flush;
|
||||||
std::cerr << "A string sent directly to stderr" << std::endl;
|
std::cerr << "A string sent directly to stderr\n" << std::flush;
|
||||||
std::clog << "A string sent to stderr via clog" << std::endl;
|
std::clog << "A string sent to stderr via clog\n" << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "null strings" ) {
|
TEST_CASE( "null strings" ) {
|
||||||
@ -396,7 +396,7 @@ TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities", "[template][product
|
|||||||
using MyTypes = std::tuple<int, char, float>;
|
using MyTypes = std::tuple<int, char, float>;
|
||||||
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std::tuple", "[template][list]", MyTypes)
|
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std::tuple", "[template][list]", MyTypes)
|
||||||
{
|
{
|
||||||
REQUIRE(sizeof(TestType) > 0);
|
REQUIRE(std::is_arithmetic<TestType>::value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NonDefaultConstructibleType {
|
struct NonDefaultConstructibleType {
|
||||||
@ -406,7 +406,7 @@ struct NonDefaultConstructibleType {
|
|||||||
using MyNonDefaultConstructibleTypes = std::tuple<NonDefaultConstructibleType, float>;
|
using MyNonDefaultConstructibleTypes = std::tuple<NonDefaultConstructibleType, float>;
|
||||||
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside non-default-constructible std::tuple", "[template][list]", MyNonDefaultConstructibleTypes)
|
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside non-default-constructible std::tuple", "[template][list]", MyNonDefaultConstructibleTypes)
|
||||||
{
|
{
|
||||||
REQUIRE(sizeof(TestType) > 0);
|
REQUIRE(std::is_trivially_copyable<TestType>::value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NonCopyableAndNonMovableType {
|
struct NonCopyableAndNonMovableType {
|
||||||
@ -421,7 +421,7 @@ struct NonCopyableAndNonMovableType {
|
|||||||
using NonCopyableAndNonMovableTypes = std::tuple<NonCopyableAndNonMovableType, float>;
|
using NonCopyableAndNonMovableTypes = std::tuple<NonCopyableAndNonMovableType, float>;
|
||||||
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside non-copyable and non-movable std::tuple", "[template][list]", NonCopyableAndNonMovableTypes)
|
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside non-copyable and non-movable std::tuple", "[template][list]", NonCopyableAndNonMovableTypes)
|
||||||
{
|
{
|
||||||
REQUIRE(sizeof(TestType) > 0);
|
REQUIRE(std::is_default_constructible<TestType>::value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/philsquared/Catch/issues/166
|
// https://github.com/philsquared/Catch/issues/166
|
||||||
|
@ -261,7 +261,7 @@ TEST_CASE( "non streamable - with conv. op", "[Tricky]" )
|
|||||||
|
|
||||||
inline void foo() {}
|
inline void foo() {}
|
||||||
|
|
||||||
typedef void (*fooptr_t)();
|
using fooptr_t = void (*)();
|
||||||
|
|
||||||
TEST_CASE( "Comparing function pointers", "[Tricky][function pointer]" )
|
TEST_CASE( "Comparing function pointers", "[Tricky][function pointer]" )
|
||||||
{
|
{
|
||||||
@ -281,7 +281,7 @@ struct S
|
|||||||
|
|
||||||
TEST_CASE( "Comparing member function pointers", "[Tricky][member function pointer][approvals]" )
|
TEST_CASE( "Comparing member function pointers", "[Tricky][member function pointer][approvals]" )
|
||||||
{
|
{
|
||||||
typedef void (S::*MF)();
|
using MF = void (S::*)();
|
||||||
MF m = &S::f;
|
MF m = &S::f;
|
||||||
|
|
||||||
CHECK( m == &S::f );
|
CHECK( m == &S::f );
|
||||||
|
Loading…
Reference in New Issue
Block a user