mirror of
https://github.com/catchorg/Catch2.git
synced 2025-01-15 14:48:00 +00:00
Compare commits
5 Commits
8d6a1c27ef
...
c9371865d4
Author | SHA1 | Date | |
---|---|---|---|
|
c9371865d4 | ||
|
5741de9ccd | ||
|
0e2895934c | ||
|
a01073d871 | ||
|
02839ba934 |
@ -44,10 +44,10 @@ namespace Catch {
|
||||
|
||||
virtual auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0;
|
||||
|
||||
virtual void benchmarkPreparing( std::string const& name ) = 0;
|
||||
virtual void benchmarkPreparing( StringRef name ) = 0;
|
||||
virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
|
||||
virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
|
||||
virtual void benchmarkFailed( std::string const& error ) = 0;
|
||||
virtual void benchmarkFailed( StringRef error ) = 0;
|
||||
|
||||
virtual void pushScopedMessage( MessageInfo const& message ) = 0;
|
||||
virtual void popScopedMessage( MessageInfo const& message ) = 0;
|
||||
|
@ -201,10 +201,10 @@ namespace Catch {
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
|
||||
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
|
||||
|
||||
virtual void benchmarkPreparing( std::string const& ) {}
|
||||
virtual void benchmarkPreparing( StringRef ) {}
|
||||
virtual void benchmarkStarting( BenchmarkInfo const& ) {}
|
||||
virtual void benchmarkEnded( BenchmarkStats<> const& ) {}
|
||||
virtual void benchmarkFailed( std::string const& ) {}
|
||||
virtual void benchmarkFailed( StringRef ) {}
|
||||
|
||||
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
||||
|
||||
|
@ -316,7 +316,7 @@ namespace Catch {
|
||||
m_unfinishedSections.push_back(endInfo);
|
||||
}
|
||||
|
||||
void RunContext::benchmarkPreparing(std::string const& name) {
|
||||
void RunContext::benchmarkPreparing( StringRef name ) {
|
||||
m_reporter->benchmarkPreparing(name);
|
||||
}
|
||||
void RunContext::benchmarkStarting( BenchmarkInfo const& info ) {
|
||||
@ -325,8 +325,8 @@ namespace Catch {
|
||||
void RunContext::benchmarkEnded( BenchmarkStats<> const& stats ) {
|
||||
m_reporter->benchmarkEnded( stats );
|
||||
}
|
||||
void RunContext::benchmarkFailed(std::string const & error) {
|
||||
m_reporter->benchmarkFailed(error);
|
||||
void RunContext::benchmarkFailed( StringRef error ) {
|
||||
m_reporter->benchmarkFailed( error );
|
||||
}
|
||||
|
||||
void RunContext::pushScopedMessage(MessageInfo const & message) {
|
||||
|
@ -77,10 +77,10 @@ namespace Catch {
|
||||
|
||||
auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override;
|
||||
|
||||
void benchmarkPreparing( std::string const& name ) override;
|
||||
void benchmarkPreparing( StringRef name ) override;
|
||||
void benchmarkStarting( BenchmarkInfo const& info ) override;
|
||||
void benchmarkEnded( BenchmarkStats<> const& stats ) override;
|
||||
void benchmarkFailed( std::string const& error ) override;
|
||||
void benchmarkFailed( StringRef error ) override;
|
||||
|
||||
void pushScopedMessage( MessageInfo const& message ) override;
|
||||
void popScopedMessage( MessageInfo const& message ) override;
|
||||
|
@ -57,7 +57,6 @@ namespace Catch {
|
||||
|
||||
template <typename RangeLike>
|
||||
bool match(RangeLike&& rng) const {
|
||||
using std::begin; using std::endl;
|
||||
for (auto&& elem : rng) {
|
||||
if (m_matcher.match(elem)) {
|
||||
return true;
|
||||
|
@ -69,11 +69,13 @@ namespace Catch {
|
||||
// Save previous errno, to prevent sprintf from overwriting it
|
||||
ErrnoGuard guard;
|
||||
#ifdef _MSC_VER
|
||||
sprintf_s( buffer, "%.3f", duration );
|
||||
size_t printedLength = static_cast<size_t>(
|
||||
sprintf_s( buffer, "%.3f", duration ) );
|
||||
#else
|
||||
std::snprintf( buffer, maxDoubleSize, "%.3f", duration );
|
||||
size_t printedLength = static_cast<size_t>(
|
||||
std::snprintf( buffer, maxDoubleSize, "%.3f", duration ) );
|
||||
#endif
|
||||
return std::string( buffer );
|
||||
return std::string( buffer, printedLength );
|
||||
}
|
||||
|
||||
bool shouldShowDuration( IConfig const& config, double duration ) {
|
||||
|
@ -434,10 +434,12 @@ void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) {
|
||||
StreamingReporterBase::sectionEnded(_sectionStats);
|
||||
}
|
||||
|
||||
void ConsoleReporter::benchmarkPreparing(std::string const& name) {
|
||||
void ConsoleReporter::benchmarkPreparing( StringRef name ) {
|
||||
lazyPrintWithoutClosingBenchmarkTable();
|
||||
|
||||
auto nameCol = TextFlow::Column(name).width(static_cast<std::size_t>(m_tablePrinter->columnInfos()[0].width - 2));
|
||||
auto nameCol = TextFlow::Column( static_cast<std::string>( name ) )
|
||||
.width( static_cast<std::size_t>(
|
||||
m_tablePrinter->columnInfos()[0].width - 2 ) );
|
||||
|
||||
bool firstLine = true;
|
||||
for (auto line : nameCol) {
|
||||
@ -473,7 +475,7 @@ void ConsoleReporter::benchmarkEnded(BenchmarkStats<> const& stats) {
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleReporter::benchmarkFailed(std::string const& error) {
|
||||
void ConsoleReporter::benchmarkFailed( StringRef error ) {
|
||||
Colour colour(Colour::Red);
|
||||
(*m_tablePrinter)
|
||||
<< "Benchmark failed (" << error << ')'
|
||||
|
@ -42,10 +42,10 @@ namespace Catch {
|
||||
void sectionStarting(SectionInfo const& _sectionInfo) override;
|
||||
void sectionEnded(SectionStats const& _sectionStats) override;
|
||||
|
||||
void benchmarkPreparing(std::string const& name) override;
|
||||
void benchmarkPreparing( StringRef name ) override;
|
||||
void benchmarkStarting(BenchmarkInfo const& info) override;
|
||||
void benchmarkEnded(BenchmarkStats<> const& stats) override;
|
||||
void benchmarkFailed(std::string const& error) override;
|
||||
void benchmarkFailed( StringRef error ) override;
|
||||
|
||||
void testCaseEnded(TestCaseStats const& _testCaseStats) override;
|
||||
void testGroupEnded(TestGroupStats const& _testGroupStats) override;
|
||||
|
@ -38,7 +38,7 @@ namespace Catch {
|
||||
|
||||
std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
|
||||
|
||||
return std::string(timeStamp);
|
||||
return std::string(timeStamp, timeStampSize - 1);
|
||||
}
|
||||
|
||||
std::string fileNameTag(std::vector<Tag> const& tags) {
|
||||
|
@ -35,7 +35,7 @@ namespace Catch {
|
||||
m_reporter->reportInvalidArguments( arg );
|
||||
}
|
||||
|
||||
void ListeningReporter::benchmarkPreparing( std::string const& name ) {
|
||||
void ListeningReporter::benchmarkPreparing( StringRef name ) {
|
||||
for (auto& listener : m_listeners) {
|
||||
listener->benchmarkPreparing(name);
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace Catch {
|
||||
m_reporter->benchmarkEnded( benchmarkStats );
|
||||
}
|
||||
|
||||
void ListeningReporter::benchmarkFailed( std::string const& error ) {
|
||||
void ListeningReporter::benchmarkFailed( StringRef error ) {
|
||||
for (auto& listener : m_listeners) {
|
||||
listener->benchmarkFailed(error);
|
||||
}
|
||||
|
@ -34,10 +34,10 @@ namespace Catch {
|
||||
|
||||
void reportInvalidArguments(std::string const&arg) override;
|
||||
|
||||
void benchmarkPreparing(std::string const& name) override;
|
||||
void benchmarkPreparing( StringRef name ) override;
|
||||
void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
|
||||
void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
|
||||
void benchmarkFailed(std::string const&) override;
|
||||
void benchmarkFailed( StringRef error ) override;
|
||||
|
||||
void testRunStarting( TestRunInfo const& testRunInfo ) override;
|
||||
void testGroupStarting( GroupInfo const& groupInfo ) override;
|
||||
|
@ -113,26 +113,26 @@ namespace Catch {
|
||||
XmlWriter::ScopedElement e = xml.scopedElement(elementName);
|
||||
|
||||
ReusableStringStream messageRss;
|
||||
messageRss << result.getTestMacroName() << "(" << result.getExpression() << ")";
|
||||
messageRss << result.getTestMacroName() << '(' << result.getExpression() << ')';
|
||||
xml.writeAttribute("message"_sr, messageRss.str());
|
||||
|
||||
ReusableStringStream textRss;
|
||||
if (stats.totals.assertions.total() > 0) {
|
||||
textRss << "FAILED:\n";
|
||||
if (result.hasExpression()) {
|
||||
textRss << "\t" << result.getExpressionInMacro() << "\n";
|
||||
textRss << '\t' << result.getExpressionInMacro() << '\n';
|
||||
}
|
||||
if (result.hasExpandedExpression()) {
|
||||
textRss << "with expansion:\n\t" << result.getExpandedExpression() << "\n";
|
||||
textRss << "with expansion:\n\t" << result.getExpandedExpression() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.getMessage().empty())
|
||||
textRss << result.getMessage() << "\n";
|
||||
textRss << result.getMessage() << '\n';
|
||||
|
||||
for (auto const& msg : stats.infoMessages)
|
||||
if (msg.type == ResultWas::Info)
|
||||
textRss << msg.message << "\n";
|
||||
textRss << msg.message << '\n';
|
||||
|
||||
textRss << "at " << result.getSourceInfo();
|
||||
xml.writeText(textRss.str(), XmlFormatting::Newline);
|
||||
|
@ -229,9 +229,9 @@ namespace Catch {
|
||||
m_xml.endElement();
|
||||
}
|
||||
|
||||
void XmlReporter::benchmarkPreparing(std::string const& name) {
|
||||
void XmlReporter::benchmarkPreparing( StringRef name ) {
|
||||
m_xml.startElement("BenchmarkResults")
|
||||
.writeAttribute("name"_sr, name);
|
||||
.writeAttribute("name"_sr, name);
|
||||
}
|
||||
|
||||
void XmlReporter::benchmarkStarting(BenchmarkInfo const &info) {
|
||||
@ -266,7 +266,7 @@ namespace Catch {
|
||||
m_xml.endElement();
|
||||
}
|
||||
|
||||
void XmlReporter::benchmarkFailed(std::string const &error) {
|
||||
void XmlReporter::benchmarkFailed(StringRef error) {
|
||||
m_xml.scopedElement("failed").
|
||||
writeAttribute("message"_sr, error);
|
||||
m_xml.endElement();
|
||||
|
@ -51,10 +51,10 @@ namespace Catch {
|
||||
|
||||
void testRunEnded(TestRunStats const& testRunStats) override;
|
||||
|
||||
void benchmarkPreparing(std::string const& name) override;
|
||||
void benchmarkPreparing( StringRef name ) override;
|
||||
void benchmarkStarting(BenchmarkInfo const&) override;
|
||||
void benchmarkEnded(BenchmarkStats<> const&) override;
|
||||
void benchmarkFailed(std::string const&) override;
|
||||
void benchmarkFailed( StringRef error ) override;
|
||||
|
||||
void listReporters(std::vector<ReporterDescription> const& descriptions) override;
|
||||
void listTests(std::vector<TestCaseHandle> const& tests) override;
|
||||
|
@ -269,6 +269,7 @@ Message from section two
|
||||
:test-result: PASS X/level/1/a
|
||||
:test-result: PASS X/level/1/b
|
||||
:test-result: PASS XmlEncode
|
||||
:test-result: PASS XmlWriter writes boolean attributes as true/false
|
||||
:test-result: PASS analyse no analysis
|
||||
:test-result: PASS array<int, N> -> toString
|
||||
:test-result: PASS atomic if
|
||||
|
@ -1982,6 +1982,9 @@ Xml.tests.cpp:<line number>: passed: encode( stringWithQuotes, Catch::XmlEncode:
|
||||
"don't "quote" me on that"
|
||||
Xml.tests.cpp:<line number>: passed: encode( "[\x01]" ) == "[\\x01]" for: "[\x01]" == "[\x01]"
|
||||
Xml.tests.cpp:<line number>: passed: encode( "[\x7F]" ) == "[\\x7F]" for: "[\x7F]" == "[\x7F]"
|
||||
Xml.tests.cpp:<line number>: passed: stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") for: "<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Element1 attr1="true" attr2="false"/>
|
||||
" ( contains: "attr1="true"" and contains: "attr2="false"" )
|
||||
InternalBenchmark.tests.cpp:<line number>: passed: analysis.mean.point.count() == 23 for: 23.0 == 23
|
||||
InternalBenchmark.tests.cpp:<line number>: passed: analysis.mean.lower_bound.count() == 23 for: 23.0 == 23
|
||||
InternalBenchmark.tests.cpp:<line number>: passed: analysis.mean.upper_bound.count() == 23 for: 23.0 == 23
|
||||
|
@ -1386,6 +1386,6 @@ due to unexpected exception with message:
|
||||
Why would you throw a std::string?
|
||||
|
||||
===============================================================================
|
||||
test cases: 363 | 287 passed | 70 failed | 6 failed as expected
|
||||
assertions: 2090 | 1938 passed | 129 failed | 23 failed as expected
|
||||
test cases: 364 | 288 passed | 70 failed | 6 failed as expected
|
||||
assertions: 2091 | 1939 passed | 129 failed | 23 failed as expected
|
||||
|
||||
|
@ -14068,6 +14068,19 @@ Xml.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
"[\x7F]" == "[\x7F]"
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
XmlWriter writes boolean attributes as true/false
|
||||
-------------------------------------------------------------------------------
|
||||
Xml.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Xml.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") )
|
||||
with expansion:
|
||||
"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Element1 attr1="true" attr2="false"/>
|
||||
" ( contains: "attr1="true"" and contains: "attr2="false"" )
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
analyse no analysis
|
||||
-------------------------------------------------------------------------------
|
||||
@ -16830,6 +16843,6 @@ Misc.tests.cpp:<line number>
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 363 | 271 passed | 86 failed | 6 failed as expected
|
||||
assertions: 2107 | 1938 passed | 146 failed | 23 failed as expected
|
||||
test cases: 364 | 272 passed | 86 failed | 6 failed as expected
|
||||
assertions: 2108 | 1939 passed | 146 failed | 23 failed as expected
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="130" tests="2108" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="130" tests="2109" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
|
||||
<property name="random-seed" value="1"/>
|
||||
@ -1513,6 +1513,7 @@ Exception.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="XmlEncode/string with quotes" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="XmlEncode/string with control char (1)" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="XmlEncode/string with control char (x7F)" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="XmlWriter writes boolean attributes as true/false" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="analyse no analysis" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="array<int, N> -> toString" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="atomic if" time="{duration}" status="run"/>
|
||||
|
@ -253,6 +253,7 @@
|
||||
<testCase name="XmlEncode/string with quotes" duration="{duration}"/>
|
||||
<testCase name="XmlEncode/string with control char (1)" duration="{duration}"/>
|
||||
<testCase name="XmlEncode/string with control char (x7F)" duration="{duration}"/>
|
||||
<testCase name="XmlWriter writes boolean attributes as true/false" duration="{duration}"/>
|
||||
</file>
|
||||
<file path="tests/<exe-name>/UsageTests/Approx.tests.cpp">
|
||||
<testCase name="A comparison that uses literals instead of the normal constructor" duration="{duration}"/>
|
||||
|
@ -3541,6 +3541,8 @@ ok {test-number} - encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) =
|
||||
ok {test-number} - encode( "[\x01]" ) == "[\\x01]" for: "[\x01]" == "[\x01]"
|
||||
# XmlEncode
|
||||
ok {test-number} - encode( "[\x7F]" ) == "[\\x7F]" for: "[\x7F]" == "[\x7F]"
|
||||
# XmlWriter writes boolean attributes as true/false
|
||||
ok {test-number} - stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") for: "<?xml version="1.0" encoding="UTF-8"?> <Element1 attr1="true" attr2="false"/> " ( contains: "attr1="true"" and contains: "attr2="false"" )
|
||||
# analyse no analysis
|
||||
ok {test-number} - analysis.mean.point.count() == 23 for: 23.0 == 23
|
||||
# analyse no analysis
|
||||
@ -4216,5 +4218,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..2107
|
||||
1..2108
|
||||
|
||||
|
@ -662,6 +662,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "unexpe
|
||||
##teamcity[testFinished name='X/level/1/b' duration="{duration}"]
|
||||
##teamcity[testStarted name='XmlEncode']
|
||||
##teamcity[testFinished name='XmlEncode' duration="{duration}"]
|
||||
##teamcity[testStarted name='XmlWriter writes boolean attributes as true/false']
|
||||
##teamcity[testFinished name='XmlWriter writes boolean attributes as true/false' duration="{duration}"]
|
||||
##teamcity[testStarted name='analyse no analysis']
|
||||
##teamcity[testFinished name='analyse no analysis' duration="{duration}"]
|
||||
##teamcity[testStarted name='array<int, N> -> toString']
|
||||
|
@ -16544,6 +16544,19 @@ There is no extra whitespace here
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="XmlWriter writes boolean attributes as true/false" tags="[XML][XmlWriter]" filename="tests/<exe-name>/IntrospectiveTests/Xml.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/Xml.tests.cpp" >
|
||||
<Original>
|
||||
stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")")
|
||||
</Original>
|
||||
<Expanded>
|
||||
"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Element1 attr1="true" attr2="false"/>
|
||||
" ( contains: "attr1="true"" and contains: "attr2="false"" )
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="analyse no analysis" tags="[benchmark]" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
|
||||
<Original>
|
||||
@ -19802,9 +19815,9 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="1938" failures="147" expectedFailures="23"/>
|
||||
<OverallResultsCases successes="271" failures="86" expectedFailures="6"/>
|
||||
<OverallResults successes="1939" failures="147" expectedFailures="23"/>
|
||||
<OverallResultsCases successes="272" failures="86" expectedFailures="6"/>
|
||||
</Group>
|
||||
<OverallResults successes="1938" failures="146" expectedFailures="23"/>
|
||||
<OverallResultsCases successes="271" failures="86" expectedFailures="6"/>
|
||||
<OverallResults successes="1939" failures="146" expectedFailures="23"/>
|
||||
<OverallResultsCases successes="272" failures="86" expectedFailures="6"/>
|
||||
</Catch>
|
||||
|
@ -2,6 +2,9 @@
|
||||
#include <catch2/internal/catch_xmlwriter.hpp>
|
||||
|
||||
#include <catch2/internal/catch_stream.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
static std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) {
|
||||
Catch::ReusableStringStream oss;
|
||||
@ -112,3 +115,19 @@ TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8][approvals]") {
|
||||
}
|
||||
#undef ESC
|
||||
}
|
||||
|
||||
TEST_CASE("XmlWriter writes boolean attributes as true/false", "[XML][XmlWriter]") {
|
||||
using Catch::Matchers::Contains;
|
||||
std::stringstream stream;
|
||||
{
|
||||
Catch::XmlWriter xml(stream);
|
||||
|
||||
xml.scopedElement("Element1")
|
||||
.writeAttribute("attr1", true)
|
||||
.writeAttribute("attr2", false);
|
||||
}
|
||||
|
||||
REQUIRE_THAT( stream.str(),
|
||||
Contains(R"(attr1="true")") &&
|
||||
Contains(R"(attr2="false")") );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user