diff --git a/src/catch2/reporters/catch_reporter_json.cpp b/src/catch2/reporters/catch_reporter_json.cpp index 9489f01466..a44302d04c 100644 --- a/src/catch2/reporters/catch_reporter_json.cpp +++ b/src/catch2/reporters/catch_reporter_json.cpp @@ -38,43 +38,47 @@ namespace Catch { if ( info.throws() ) { writer.write( "throws" ); } } - void writeCounts( JsonObjectWriter writer, Counts const& counts ) { - writer.write( "passed" ).write( counts.passed ); - writer.write( "failed" ).write( counts.failed ); - writer.write( "fail-but-ok" ).write( counts.failedButOk ); - writer.write( "skipped" ).write( counts.skipped ); - } - - void writeTestInfo( JsonObjectWriter writer, - TestCaseInfo const& info ) { - writer.write( "name" ).write( info.name ); - writeTags( writer.write( "tags" ).writeArray(), info.tags ); - writeSourceInfo( writer, info.lineInfo ); - writeProperties( writer.write( "properties" ).writeArray(), info ); - } - - void writeSection( JsonObjectWriter& writer, - CumulativeReporterBase::SectionNode const& section, - bool selfWrite ) { - if ( selfWrite ) { - writer.write( "name" ).write( section.stats.sectionInfo.name ); - writeSourceInfo( writer, section.stats.sectionInfo.lineInfo ); - writeCounts( writer.write( "assertions-stats" ).writeObject(), - section.stats.assertions ); - } - if ( section.childSections.empty() ) { return; } - auto sectionsWriter = writer.write( "sections" ).writeArray(); - for ( auto const& childPtr : section.childSections ) { - auto childSectionWriter = sectionsWriter.writeObject(); - writeSection( childSectionWriter, *childPtr, true ); - } - } + //void writeCounts( JsonObjectWriter writer, Counts const& counts ) { + // writer.write( "passed" ).write( counts.passed ); + // writer.write( "failed" ).write( counts.failed ); + // writer.write( "fail-but-ok" ).write( counts.failedButOk ); + // writer.write( "skipped" ).write( counts.skipped ); + //} + + //void writeTestInfo( JsonObjectWriter writer, + // TestCaseInfo const& info ) { + // writer.write( "name" ).write( info.name ); + // writeTags( writer.write( "tags" ).writeArray(), info.tags ); + // writeSourceInfo( writer, info.lineInfo ); + // writeProperties( writer.write( "properties" ).writeArray(), info ); + //} + + //void writeSection( JsonObjectWriter& writer, + // CumulativeReporterBase::SectionNode const& section, + // bool selfWrite ) { + // if ( selfWrite ) { + // writer.write( "name" ).write( section.stats.sectionInfo.name ); + // writeSourceInfo( writer, section.stats.sectionInfo.lineInfo ); + // writeCounts( writer.write( "assertions-stats" ).writeObject(), + // section.stats.assertions ); + // } + // if ( section.childSections.empty() ) { return; } + // auto sectionsWriter = writer.write( "sections" ).writeArray(); + // for ( auto const& childPtr : section.childSections ) { + // auto childSectionWriter = sectionsWriter.writeObject(); + // writeSection( childSectionWriter, *childPtr, true ); + // } + //} } // namespace JsonReporter::JsonReporter( ReporterConfig&& config ): - CumulativeReporterBase{ CATCH_MOVE( config ) } { + StreamingReporterBase{ CATCH_MOVE( config ) } { m_preferences.shouldRedirectStdOut = true; + // TBD: Do we want to report all assertions? XML reporter does + // not, but for machine-parseable reporters I think the answer + // should be yes. + m_preferences.shouldReportAllAssertions = true; m_objectWriters.emplace( m_stream ); m_writers.emplace( Writer::Object ); @@ -95,17 +99,13 @@ namespace Catch { } JsonReporter::~JsonReporter() { - while ( !m_writers.empty() ) { - switch ( m_writers.top() ) { - case Writer::Object: - endObject(); - break; - case Writer::Array: - endArray(); - break; - } - } - m_stream << std::endl; + endListing(); + // TODO: Ensure this closes the top level object, add asserts + assert( m_writers.size() == 1 && "Only the top level object should be open" ); + assert( m_writers.top() == Writer::Object ); + endObject(); + m_stream << '\n' << std::flush; + assert( m_writers.empty() ); } JsonArrayWriter& JsonReporter::startArray() { @@ -133,12 +133,12 @@ namespace Catch { } void JsonReporter::endObject() { - if ( !isInside( Writer::Object ) ) { return; } + assert( isInside( Writer::Object ) ); m_objectWriters.pop(); m_writers.pop(); } void JsonReporter::endArray() { - if ( !isInside( Writer::Array ) ) { return; } + assert( isInside( Writer::Array ) ); m_arrayWriters.pop(); m_writers.pop(); } @@ -148,35 +148,186 @@ namespace Catch { } void JsonReporter::startListing() { + if ( !m_startedListing ) { startObject( "listings" ); } m_startedListing = true; - startObject( "listings" ); + } + void JsonReporter::endListing() { + if ( m_startedListing ) { endObject(); } + m_startedListing = false; } std::string JsonReporter::getDescription() { - return "Reports test results as a JSON document"; + return "WIP! Reports test results as a JSON document. WIP!"; } - void JsonReporter::testRunStarting( TestRunInfo const& /*testInfo*/ ) { - if ( !isInside( Writer::Object ) ) { return; } - if ( m_startedListing ) { endObject(); } + void JsonReporter::testRunStarting( TestRunInfo const& testInfo ) { + StreamingReporterBase::testRunStarting( testInfo ); + endListing(); + assert( isInside( Writer::Object ) ); + startObject( "test-run" ); startArray( "test-cases" ); } - void JsonReporter::testRunEndedCumulative() { - for ( auto const& testCase : m_testRun->children ) { - assert( testCase->children.size() == 1 ); + static void writeCounts( JsonObjectWriter&& writer, Counts const& counts ) { + writer.write( "passed" ).write( counts.passed ); + writer.write( "failed" ).write( counts.failed ); + writer.write( "fail-but-ok" ).write( counts.failedButOk ); + writer.write( "skipped" ).write( counts.skipped ); + } + + void JsonReporter::testRunEnded(TestRunStats const& runStats) { + assert( isInside( Writer::Array ) ); + // End "test-cases" + endArray(); + + { + auto totals = m_objectWriters.top().write( "totals" ).writeObject(); + writeCounts( totals.write( "assertions" ).writeObject(), + runStats.totals.assertions ); + writeCounts( totals.write( "test-cases" ).writeObject(), + runStats.totals.testCases ); + } + + // End the "test-run" object + endObject(); + } + + void JsonReporter::testCaseStarting( TestCaseInfo const& tcInfo ) { + StreamingReporterBase::testCaseStarting( tcInfo ); + + assert( isInside( Writer::Array ) && + "We should be in the 'test-cases' array" ); + startObject(); + // "test-info" prelude + { + auto testInfo = + m_objectWriters.top().write( "test-info" ).writeObject(); + // TODO: handle testName vs className!! + testInfo.write( "name" ).write( tcInfo.name ); + writeSourceInfo(testInfo, tcInfo.lineInfo); + writeTags( testInfo.write( "tags" ).writeArray(), tcInfo.tags ); + writeProperties( testInfo.write( "properties" ).writeArray(), + tcInfo ); + } + + + // Start the array for individual test runs (testCasePartial pairs) + startArray( "runs" ); + } + + void JsonReporter::testCaseEnded( TestCaseStats const& tcStats ) { + StreamingReporterBase::testCaseEnded( tcStats ); - auto writer = m_arrayWriters.top().writeObject(); + // We need to close the 'runs' array before finishing the test case + assert( isInside( Writer::Array ) ); + endArray(); - writeTestInfo( writer.write( "test-info" ).writeObject(), - *testCase->value.testInfo ); - writeCounts( writer.write( "totals" ).writeObject(), - testCase->value.totals.assertions ); - writeSection( writer, *testCase->children.front(), false ); + { + auto totals = m_objectWriters.top().write( "totals" ).writeObject(); + writeCounts( totals.write( "assertions" ).writeObject(), + tcStats.totals.assertions ); + // We do not write the test case totals, because there will always be just one test case here. + // TODO: overall "result" -> success, skip, fail here? Or in partial result? + } + // We do not write out stderr/stdout, because we instead wrote those out in partial runs + + // TODO: aborting? + + // And we also close this test case's object + assert( isInside( Writer::Object ) ); + endObject(); + } + + void JsonReporter::testCasePartialStarting( TestCaseInfo const& /*tcInfo*/, + size_t index ) { + startObject(); + m_objectWriters.top().write( "run-idx" ).write( index ); + startArray( "path" ); + //startObject( "path" ); + // TODO: we want to delay most of the printing to the 'root' section + // TODO: childSection key name? + } + + void JsonReporter::testCasePartialEnded( TestCaseStats const& tcStats, + size_t /*index*/ ) { + // Fixme: the top level section handles this. + //// path object + endArray(); + if ( !tcStats.stdOut.empty() ) { + m_objectWriters.top() + .write( "captured-stdout" ) + .write( tcStats.stdOut ); + } + if ( !tcStats.stdErr.empty() ) { + m_objectWriters.top() + .write( "captured-stderr" ) + .write( tcStats.stdErr ); + } + { + auto totals = m_objectWriters.top().write( "totals" ).writeObject(); + writeCounts( totals.write( "assertions" ).writeObject(), + tcStats.totals.assertions ); + // We do not write the test case totals, because there will + // always be just one test case here. + // TODO: overall "result" -> success, skip, fail here? Or in + // partial result? } + // TODO: aborting? + // run object + endObject(); } + void JsonReporter::sectionStarting( SectionInfo const& sectionInfo ) { + assert( isInside( Writer::Array ) && + "Section should always start inside an object" ); + // We want to nest top level sections, even though it shares name + // and source loc with the TEST_CASE + auto& sectionObject = startObject(); + sectionObject.write( "kind" ).write( "section" ); + sectionObject.write( "name" ).write( sectionInfo.name ); + writeSourceInfo( m_objectWriters.top(), sectionInfo.lineInfo ); + + + // TBD: Do we want to create this event lazily? It would become + // rather complex, but we could do it, and it would look + // better for empty sections. OTOH, empty sections should + // be rare. + startArray( "path" ); + } + void JsonReporter::sectionEnded( SectionStats const& /*sectionStats */) { + // End the subpath array + endArray(); + // TODO: metadata + // TODO: what info do we have here? + + // End the section object + endObject(); + } + + void JsonReporter::assertionStarting( AssertionInfo const& /*assertionInfo*/ ) {} + void JsonReporter::assertionEnded( AssertionStats const& assertionStats ) { + // TODO: There is lot of different things to handle here, but + // we can fill it in later, after we show that the basic + // outline and streaming reporter impl works well enough. + //if ( !m_config->includeSuccessfulResults() + // && assertionStats.assertionResult.isOk() ) { + // return; + //} + assert( isInside( Writer::Array ) ); + auto assertionObject = m_arrayWriters.top().writeObject(); + + assertionObject.write( "kind" ).write( "assertion" ); + writeSourceInfo( assertionObject, + assertionStats.assertionResult.getSourceInfo() ); + assertionObject.write( "status" ) + .write( assertionStats.assertionResult.isOk() ); + // TODO: handling of result. + // TODO: messages + // TODO: totals? + } + + void JsonReporter::benchmarkPreparing( StringRef name ) { (void)name; } void JsonReporter::benchmarkStarting( BenchmarkInfo const& ) {} void JsonReporter::benchmarkEnded( BenchmarkStats<> const& ) {} @@ -184,11 +335,7 @@ namespace Catch { void JsonReporter::listReporters( std::vector const& descriptions ) { - if ( !m_startedListing ) { - startListing(); - } - - if ( !isInside( Writer::Object ) ) { return; } + startListing(); auto writer = m_objectWriters.top().write( "reporters" ).writeArray(); for ( auto const& desc : descriptions ) { @@ -199,10 +346,7 @@ namespace Catch { } void JsonReporter::listListeners( std::vector const& descriptions ) { - if ( !m_startedListing) { - startListing(); - } - if ( !isInside( Writer::Object ) ) { return; } + startListing(); auto writer = m_objectWriters.top().write( "listeners" ).writeArray(); @@ -213,12 +357,7 @@ namespace Catch { } } void JsonReporter::listTests( std::vector const& tests ) { - if ( !m_startedListing ) { - startListing(); - } - - // TODO: Why? This should just assert. If the object is not there, there is a bug. - if ( !isInside( Writer::Object ) ) { return; } + startListing(); auto writer = m_objectWriters.top().write( "tests" ).writeArray(); @@ -238,10 +377,7 @@ namespace Catch { } } void JsonReporter::listTags( std::vector const& tags ) { - if ( !m_startedListing ) { - startListing(); - } - if ( !isInside( Writer::Object ) ) { return; } + startListing(); auto writer = m_objectWriters.top().write( "tags" ).writeArray(); for ( auto const& tag : tags ) { diff --git a/src/catch2/reporters/catch_reporter_json.hpp b/src/catch2/reporters/catch_reporter_json.hpp index f54dfb7e72..f9ce4dcd4d 100644 --- a/src/catch2/reporters/catch_reporter_json.hpp +++ b/src/catch2/reporters/catch_reporter_json.hpp @@ -11,12 +11,12 @@ #include #include -#include +#include #include namespace Catch { - class JsonReporter : public CumulativeReporterBase { + class JsonReporter : public StreamingReporterBase { public: JsonReporter( ReporterConfig&& config ); @@ -25,9 +25,23 @@ namespace Catch { static std::string getDescription(); public: // StreamingReporterBase - void testRunStarting( TestRunInfo const& testInfo ) override; + void testRunStarting( TestRunInfo const& runInfo ) override; + void testRunEnded( TestRunStats const& runStats ) override; - void testRunEndedCumulative() override; + void testCaseStarting( TestCaseInfo const& tcInfo ) override; + void testCaseEnded( TestCaseStats const& tcStats ) override; + + void testCasePartialStarting( TestCaseInfo const& tcInfo, size_t index ) override; + void testCasePartialEnded( TestCaseStats const& tcStats, + size_t index ) override; + + void sectionStarting( SectionInfo const& sectionInfo ) override; + void sectionEnded( SectionStats const& sectionStats ) override; + + void assertionStarting( AssertionInfo const& assertionInfo ) override; + void assertionEnded( AssertionStats const& assertionStats ) override; + + //void testRunEndedCumulative() override; void benchmarkPreparing( StringRef name ) override; void benchmarkStarting( BenchmarkInfo const& ) override; @@ -60,6 +74,7 @@ namespace Catch { bool isInside( Writer writer ); void startListing(); + void endListing(); // Invariant: // When m_writers is not empty and its top element is diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 6748c0ecb2..0f029e6d28 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -170,6 +170,7 @@ Nor would this :test-result: XFAIL Incomplete AssertionHandler :test-result: XFAIL Inequality checks that should fail :test-result: PASS Inequality checks that should succeed +:test-result: PASS JsonWriter :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons :test-result: PASS ManuallyRegistered diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index a8bdcfa1bd..a3af0658ff 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -168,6 +168,7 @@ :test-result: XFAIL Incomplete AssertionHandler :test-result: XFAIL Inequality checks that should fail :test-result: PASS Inequality checks that should succeed +:test-result: PASS JsonWriter :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons :test-result: PASS ManuallyRegistered diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 0873d5f225..a8e649dd3f 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -979,6 +979,164 @@ Condition.tests.cpp:: passed: data.str_hello != "goodbye" for: "hel Condition.tests.cpp:: passed: data.str_hello != "hell" for: "hello" != "hell" Condition.tests.cpp:: passed: data.str_hello != "hello1" for: "hello" != "hello1" Condition.tests.cpp:: passed: data.str_hello.size() != 6 for: 5 != 6 +Json.tests.cpp:: passed: stream.str() == R"json( +)json" for: " +" +== +" +" +Json.tests.cpp:: passed: stream.str() == R"json( +{ +})json" for: " +{ +}" +== +" +{ +}" +Json.tests.cpp:: passed: stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" for: " +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" +== +" +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" +Json.tests.cpp:: passed: stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" for: " +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" +== +" +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" +Json.tests.cpp:: passed: stream.str() == R"json( +[ +])json" for: " +[ +]" +== +" +[ +]" +Json.tests.cpp:: passed: stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" for: " +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" +== +" +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" +Json.tests.cpp:: passed: stream.str() == R"json( +{ +})json" for: " +{ +}" +== +" +{ +}" +Json.tests.cpp:: passed: stream.str() == R"json( +[ +])json" for: " +[ +]" +== +" +[ +]" +Json.tests.cpp:: passed: stream.str() == R"json( +"custom")json" for: " +"custom"" +== +" +"custom"" +Json.tests.cpp:: passed: stream.str() == "\n\"\\\"\"" for: " +"\""" +== +" +"\""" Compilation.tests.cpp:: passed: []() { return true; }() for: true Approx.tests.cpp:: passed: d <= Approx( 1.24 ) for: 1.23 <= Approx( 1.24 ) Approx.tests.cpp:: passed: d <= Approx( 1.23 ) for: 1.23 <= Approx( 1.23 ) @@ -1343,6 +1501,60 @@ Reporters.tests.cpp:: passed: listingString, ContainsSubstring( "fa " ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: console' Reporters.tests.cpp:: passed: !(factories.empty()) for: !false +Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fakeTag"s) for: "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 1165749983, + "catch2-version": "" + }, + "listings": { + "tags": [ + { + "aliases": [ + "fakeTag" + ], + "count": 1 + } + ]" contains: "fakeTag" with 1 message: 'Tested reporter: JSON' +Reporters.tests.cpp:: passed: !(factories.empty()) for: !false +Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fake reporter"s) for: "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 1746012198, + "catch2-version": "" + }, + "listings": { + "reporters": [ + { + "name": "fake reporter", + "description": "fake description" + } + ]" contains: "fake reporter" with 1 message: 'Tested reporter: JSON' +Reporters.tests.cpp:: passed: !(factories.empty()) for: !false +Reporters.tests.cpp:: passed: listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) for: "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 2024462101, + "catch2-version": "" + }, + "listings": { + "tests": [ + { + "name": "fake test name", + "class-name": "", + "tags": [ + "fakeTestTag" + ], + "source-location": { + "filename": "fake-file.cpp", + "line": 123456789 + } + } + ]" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: JSON' +Reporters.tests.cpp:: passed: !(factories.empty()) for: !false Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fakeTag"s) for: " All available tags: 1 [fakeTag] @@ -2544,7 +2756,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 413 | 308 passed | 85 failed | 6 skipped | 14 failed as expected -assertions: 2230 | 2049 passed | 146 failed | 35 failed as expected +test cases: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected +assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 2484ed1813..58945b1da2 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -977,6 +977,164 @@ Condition.tests.cpp:: passed: data.str_hello != "goodbye" for: "hel Condition.tests.cpp:: passed: data.str_hello != "hell" for: "hello" != "hell" Condition.tests.cpp:: passed: data.str_hello != "hello1" for: "hello" != "hello1" Condition.tests.cpp:: passed: data.str_hello.size() != 6 for: 5 != 6 +Json.tests.cpp:: passed: stream.str() == R"json( +)json" for: " +" +== +" +" +Json.tests.cpp:: passed: stream.str() == R"json( +{ +})json" for: " +{ +}" +== +" +{ +}" +Json.tests.cpp:: passed: stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" for: " +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" +== +" +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" +Json.tests.cpp:: passed: stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" for: " +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" +== +" +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" +Json.tests.cpp:: passed: stream.str() == R"json( +[ +])json" for: " +[ +]" +== +" +[ +]" +Json.tests.cpp:: passed: stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" for: " +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" +== +" +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" +Json.tests.cpp:: passed: stream.str() == R"json( +{ +})json" for: " +{ +}" +== +" +{ +}" +Json.tests.cpp:: passed: stream.str() == R"json( +[ +])json" for: " +[ +]" +== +" +[ +]" +Json.tests.cpp:: passed: stream.str() == R"json( +"custom")json" for: " +"custom"" +== +" +"custom"" +Json.tests.cpp:: passed: stream.str() == "\n\"\\\"\"" for: " +"\""" +== +" +"\""" Compilation.tests.cpp:: passed: []() { return true; }() for: true Approx.tests.cpp:: passed: d <= Approx( 1.24 ) for: 1.23 <= Approx( 1.24 ) Approx.tests.cpp:: passed: d <= Approx( 1.23 ) for: 1.23 <= Approx( 1.23 ) @@ -1341,6 +1499,60 @@ Reporters.tests.cpp:: passed: listingString, ContainsSubstring( "fa " ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: console' Reporters.tests.cpp:: passed: !(factories.empty()) for: !false +Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fakeTag"s) for: "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 3063158779, + "catch2-version": "" + }, + "listings": { + "tags": [ + { + "aliases": [ + "fakeTag" + ], + "count": 1 + } + ]" contains: "fakeTag" with 1 message: 'Tested reporter: JSON' +Reporters.tests.cpp:: passed: !(factories.empty()) for: !false +Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fake reporter"s) for: "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 4167192188, + "catch2-version": "" + }, + "listings": { + "reporters": [ + { + "name": "fake reporter", + "description": "fake description" + } + ]" contains: "fake reporter" with 1 message: 'Tested reporter: JSON' +Reporters.tests.cpp:: passed: !(factories.empty()) for: !false +Reporters.tests.cpp:: passed: listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) for: "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 2012246564, + "catch2-version": "" + }, + "listings": { + "tests": [ + { + "name": "fake test name", + "class-name": "", + "tags": [ + "fakeTestTag" + ], + "source-location": { + "filename": "fake-file.cpp", + "line": 123456789 + } + } + ]" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: JSON' +Reporters.tests.cpp:: passed: !(factories.empty()) for: !false Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fakeTag"s) for: " All available tags: 1 [fakeTag] @@ -2533,7 +2745,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 413 | 308 passed | 85 failed | 6 skipped | 14 failed as expected -assertions: 2230 | 2049 passed | 146 failed | 35 failed as expected +test cases: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected +assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 4ad25ed876..9aa0d0385c 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1588,6 +1588,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 413 | 322 passed | 70 failed | 7 skipped | 14 failed as expected -assertions: 2213 | 2049 passed | 129 failed | 35 failed as expected +test cases: 414 | 323 passed | 70 failed | 7 skipped | 14 failed as expected +assertions: 2229 | 2065 passed | 129 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index bb8d09acf2..5b7376716f 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -7258,6 +7258,274 @@ Condition.tests.cpp:: PASSED: with expansion: 5 != 6 +------------------------------------------------------------------------------- +JsonWriter + Newly constructed JsonWriter does nothing +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +)json" ) +with expansion: + " + " + == + " + " + +------------------------------------------------------------------------------- +JsonWriter + Calling writeObject will create an empty pair of braces +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ +})json" ) +with expansion: + " + { + }" + == + " + { + }" + +------------------------------------------------------------------------------- +JsonWriter + Calling writeObject with key will create an object to write the value +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" ) +with expansion: + " + { + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] + }" + == + " + { + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] + }" + +------------------------------------------------------------------------------- +JsonWriter + nesting objects +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" ) +with expansion: + " + { + "empty_object": { + }, + "fully_object": { + "key": 1 + } + }" + == + " + { + "empty_object": { + }, + "fully_object": { + "key": 1 + } + }" + +------------------------------------------------------------------------------- +JsonWriter + Calling writeArray will create an empty pair of braces +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +[ +])json" ) +with expansion: + " + [ + ]" + == + " + [ + ]" + +------------------------------------------------------------------------------- +JsonWriter + Calling writeArray creates array to write the values to +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" ) +with expansion: + " + [ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] + ]" + == + " + [ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] + ]" + +------------------------------------------------------------------------------- +JsonWriter + Moved from JsonObjectWriter shall not insert superfluous brace +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ +})json" ) +with expansion: + " + { + }" + == + " + { + }" + +------------------------------------------------------------------------------- +JsonWriter + Moved from JsonArrayWriter shall not insert superfluous bracket +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +[ +])json" ) +with expansion: + " + [ + ]" + == + " + [ + ]" + +------------------------------------------------------------------------------- +JsonWriter + Custom class shall be quoted +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +"custom")json" ) +with expansion: + " + "custom"" + == + " + "custom"" + +------------------------------------------------------------------------------- +JsonWriter + String with a quote shall be espaced +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == "\n\"\\\"\"" ) +with expansion: + " + "\""" + == + " + "\""" + ------------------------------------------------------------------------------- Lambdas in assertions ------------------------------------------------------------------------------- @@ -9756,6 +10024,129 @@ Reporter's write listings to provided stream Reporters.tests.cpp: ............................................................................... +Reporters.tests.cpp:: PASSED: + REQUIRE_FALSE( factories.empty() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream + JSON reporter lists tags +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THAT( listingString, ContainsSubstring("fakeTag"s) ) +with expansion: + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 433972047, + "catch2-version": "" + }, + "listings": { + "tags": [ + { + "aliases": [ + "fakeTag" + ], + "count": 1 + } + ]" contains: "fakeTag" +with message: + Tested reporter: JSON + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_FALSE( factories.empty() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream + JSON reporter lists reporters +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THAT( listingString, ContainsSubstring("fake reporter"s) ) +with expansion: + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 3022685148, + "catch2-version": "" + }, + "listings": { + "reporters": [ + { + "name": "fake reporter", + "description": "fake description" + } + ]" contains: "fake reporter" +with message: + Tested reporter: JSON + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_FALSE( factories.empty() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream + JSON reporter lists tests +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THAT( listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) ) +with expansion: + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 1115827888, + "catch2-version": "" + }, + "listings": { + "tests": [ + { + "name": "fake test name", + "class-name": "", + "tags": [ + "fakeTestTag" + ], + "source-location": { + "filename": "fake-file.cpp", + "line": 123456789 + } + } + ]" ( contains: "fake test name" and contains: "fakeTestTag" ) +with message: + Tested reporter: JSON + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + Reporters.tests.cpp:: PASSED: REQUIRE_FALSE( factories.empty() ) with expansion: @@ -18283,6 +18674,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 413 | 308 passed | 85 failed | 6 skipped | 14 failed as expected -assertions: 2230 | 2049 passed | 146 failed | 35 failed as expected +test cases: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected +assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index ce06a690c3..476b49f547 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -7256,6 +7256,274 @@ Condition.tests.cpp:: PASSED: with expansion: 5 != 6 +------------------------------------------------------------------------------- +JsonWriter + Newly constructed JsonWriter does nothing +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +)json" ) +with expansion: + " + " + == + " + " + +------------------------------------------------------------------------------- +JsonWriter + Calling writeObject will create an empty pair of braces +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ +})json" ) +with expansion: + " + { + }" + == + " + { + }" + +------------------------------------------------------------------------------- +JsonWriter + Calling writeObject with key will create an object to write the value +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" ) +with expansion: + " + { + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] + }" + == + " + { + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] + }" + +------------------------------------------------------------------------------- +JsonWriter + nesting objects +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" ) +with expansion: + " + { + "empty_object": { + }, + "fully_object": { + "key": 1 + } + }" + == + " + { + "empty_object": { + }, + "fully_object": { + "key": 1 + } + }" + +------------------------------------------------------------------------------- +JsonWriter + Calling writeArray will create an empty pair of braces +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +[ +])json" ) +with expansion: + " + [ + ]" + == + " + [ + ]" + +------------------------------------------------------------------------------- +JsonWriter + Calling writeArray creates array to write the values to +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" ) +with expansion: + " + [ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] + ]" + == + " + [ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] + ]" + +------------------------------------------------------------------------------- +JsonWriter + Moved from JsonObjectWriter shall not insert superfluous brace +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +{ +})json" ) +with expansion: + " + { + }" + == + " + { + }" + +------------------------------------------------------------------------------- +JsonWriter + Moved from JsonArrayWriter shall not insert superfluous bracket +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +[ +])json" ) +with expansion: + " + [ + ]" + == + " + [ + ]" + +------------------------------------------------------------------------------- +JsonWriter + Custom class shall be quoted +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == R"json( +"custom")json" ) +with expansion: + " + "custom"" + == + " + "custom"" + +------------------------------------------------------------------------------- +JsonWriter + String with a quote shall be espaced +------------------------------------------------------------------------------- +Json.tests.cpp: +............................................................................... + +Json.tests.cpp:: PASSED: + REQUIRE( stream.str() == "\n\"\\\"\"" ) +with expansion: + " + "\""" + == + " + "\""" + ------------------------------------------------------------------------------- Lambdas in assertions ------------------------------------------------------------------------------- @@ -9754,6 +10022,129 @@ Reporter's write listings to provided stream Reporters.tests.cpp: ............................................................................... +Reporters.tests.cpp:: PASSED: + REQUIRE_FALSE( factories.empty() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream + JSON reporter lists tags +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THAT( listingString, ContainsSubstring("fakeTag"s) ) +with expansion: + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 3063158779, + "catch2-version": "" + }, + "listings": { + "tags": [ + { + "aliases": [ + "fakeTag" + ], + "count": 1 + } + ]" contains: "fakeTag" +with message: + Tested reporter: JSON + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_FALSE( factories.empty() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream + JSON reporter lists reporters +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THAT( listingString, ContainsSubstring("fake reporter"s) ) +with expansion: + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 4167192188, + "catch2-version": "" + }, + "listings": { + "reporters": [ + { + "name": "fake reporter", + "description": "fake description" + } + ]" contains: "fake reporter" +with message: + Tested reporter: JSON + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_FALSE( factories.empty() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream + JSON reporter lists tests +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THAT( listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) ) +with expansion: + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 2012246564, + "catch2-version": "" + }, + "listings": { + "tests": [ + { + "name": "fake test name", + "class-name": "", + "tags": [ + "fakeTestTag" + ], + "source-location": { + "filename": "fake-file.cpp", + "line": 123456789 + } + } + ]" ( contains: "fake test name" and contains: "fakeTestTag" ) +with message: + Tested reporter: JSON + +------------------------------------------------------------------------------- +Reporter's write listings to provided stream +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + Reporters.tests.cpp:: PASSED: REQUIRE_FALSE( factories.empty() ) with expansion: @@ -18272,6 +18663,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 413 | 308 passed | 85 failed | 6 skipped | 14 failed as expected -assertions: 2230 | 2049 passed | 146 failed | 35 failed as expected +test cases: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected +assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/default.sw.multi.approved.txt b/tests/SelfTest/Baselines/default.sw.multi.approved.txt index bb17484488..86b8f7c11d 100644 --- a/tests/SelfTest/Baselines/default.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/default.sw.multi.approved.txt @@ -1,11 +1,5 @@ This would not be caught previously Nor would this -A string sent directly to stdout -A string sent directly to stderr -A string sent to stderr via clog -Message from section one -Message from section two -loose text artifact -a! -b1! -! +: src/catch2/reporters/catch_reporter_json.cpp:103: virtual Catch::JsonReporter::~JsonReporter(): Assertion `m_writers.size() == 1 && "Only the top level object should be open"' failed. +terminate called after throwing an instance of 'std::domain_error' + what(): A partial test case has not ended diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 3b6c8fa07b..beb235b578 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -853,6 +853,16 @@ at Condition.tests.cpp: + + + + + + + + + + @@ -1190,6 +1200,9 @@ at Matchers.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index 48b8acc8d6..a5dd30636c 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -852,6 +852,16 @@ at Condition.tests.cpp: + + + + + + + + + + @@ -1189,6 +1199,9 @@ at Matchers.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index b634d27ebb..eaef6357e6 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -130,6 +130,18 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + @@ -178,6 +190,9 @@ at AssertionHandler.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 33c9c208d8..bb23a9955d 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -129,6 +129,18 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + @@ -177,6 +189,9 @@ at AssertionHandler.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 2b2b6eba3d..4adc256134 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -1866,6 +1866,68 @@ ok {test-number} - data.str_hello != "hell" for: "hello" != "hell" ok {test-number} - data.str_hello != "hello1" for: "hello" != "hello1" # Inequality checks that should succeed ok {test-number} - data.str_hello.size() != 6 for: 5 != 6 +# JsonWriter +ok {test-number} - stream.str() == R"json( +)json" for: " " == " " +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ +})json" for: " { }" == " { }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" for: " { "int": 1, "double": 1.5, "true": true, "false": false, "string": "this is a string", "array": [ 1, 2 ] }" == " { "int": 1, "double": 1.5, "true": true, "false": false, "string": "this is a string", "array": [ 1, 2 ] }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" for: " { "empty_object": { }, "fully_object": { "key": 1 } }" == " { "empty_object": { }, "fully_object": { "key": 1 } }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +[ +])json" for: " [ ]" == " [ ]" +# JsonWriter +ok {test-number} - stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" for: " [ 1, 1.5, true, false, "this is a string", { "object": 42 }, [ "array", 42.5 ] ]" == " [ 1, 1.5, true, false, "this is a string", { "object": 42 }, [ "array", 42.5 ] ]" +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ +})json" for: " { }" == " { }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +[ +])json" for: " [ ]" == " [ ]" +# JsonWriter +ok {test-number} - stream.str() == R"json( +"custom")json" for: " "custom"" == " "custom"" +# JsonWriter +ok {test-number} - stream.str() == "\n\"\\\"\"" for: " "\""" == " "\""" # Lambdas in assertions ok {test-number} - []() { return true; }() for: true # Less-than inequalities with different epsilons @@ -2459,6 +2521,18 @@ ok {test-number} - listingString, ContainsSubstring( "fake test name"s ) && Cont # Reporter's write listings to provided stream ok {test-number} - !(factories.empty()) for: !false # Reporter's write listings to provided stream +ok {test-number} - listingString, ContainsSubstring("fakeTag"s) for: "{ "version": 1, "metadata": { "name": "", "rng-seed": 666503459, "catch2-version": "" }, "listings": { "tags": [ { "aliases": [ "fakeTag" ], "count": 1 } ]" contains: "fakeTag" with 1 message: 'Tested reporter: JSON' +# Reporter's write listings to provided stream +ok {test-number} - !(factories.empty()) for: !false +# Reporter's write listings to provided stream +ok {test-number} - listingString, ContainsSubstring("fake reporter"s) for: "{ "version": 1, "metadata": { "name": "", "rng-seed": 4229138389, "catch2-version": "" }, "listings": { "reporters": [ { "name": "fake reporter", "description": "fake description" } ]" contains: "fake reporter" with 1 message: 'Tested reporter: JSON' +# Reporter's write listings to provided stream +ok {test-number} - !(factories.empty()) for: !false +# Reporter's write listings to provided stream +ok {test-number} - listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) for: "{ "version": 1, "metadata": { "name": "", "rng-seed": 1573494800, "catch2-version": "" }, "listings": { "tests": [ { "name": "fake test name", "class-name": "", "tags": [ "fakeTestTag" ], "source-location": { "filename": "fake-file.cpp", "line": 123456789 } } ]" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: JSON' +# Reporter's write listings to provided stream +ok {test-number} - !(factories.empty()) for: !false +# Reporter's write listings to provided stream ok {test-number} - listingString, ContainsSubstring("fakeTag"s) for: " All available tags: 1 [fakeTag] 1 tag " contains: "fakeTag" with 1 message: 'Tested reporter: JUnit' # Reporter's write listings to provided stream ok {test-number} - !(factories.empty()) for: !false @@ -4489,5 +4563,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2242 +1..2258 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 13240e5299..51d985cfa3 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -1864,6 +1864,68 @@ ok {test-number} - data.str_hello != "hell" for: "hello" != "hell" ok {test-number} - data.str_hello != "hello1" for: "hello" != "hello1" # Inequality checks that should succeed ok {test-number} - data.str_hello.size() != 6 for: 5 != 6 +# JsonWriter +ok {test-number} - stream.str() == R"json( +)json" for: " " == " " +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ +})json" for: " { }" == " { }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" for: " { "int": 1, "double": 1.5, "true": true, "false": false, "string": "this is a string", "array": [ 1, 2 ] }" == " { "int": 1, "double": 1.5, "true": true, "false": false, "string": "this is a string", "array": [ 1, 2 ] }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" for: " { "empty_object": { }, "fully_object": { "key": 1 } }" == " { "empty_object": { }, "fully_object": { "key": 1 } }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +[ +])json" for: " [ ]" == " [ ]" +# JsonWriter +ok {test-number} - stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" for: " [ 1, 1.5, true, false, "this is a string", { "object": 42 }, [ "array", 42.5 ] ]" == " [ 1, 1.5, true, false, "this is a string", { "object": 42 }, [ "array", 42.5 ] ]" +# JsonWriter +ok {test-number} - stream.str() == R"json( +{ +})json" for: " { }" == " { }" +# JsonWriter +ok {test-number} - stream.str() == R"json( +[ +])json" for: " [ ]" == " [ ]" +# JsonWriter +ok {test-number} - stream.str() == R"json( +"custom")json" for: " "custom"" == " "custom"" +# JsonWriter +ok {test-number} - stream.str() == "\n\"\\\"\"" for: " "\""" == " "\""" # Lambdas in assertions ok {test-number} - []() { return true; }() for: true # Less-than inequalities with different epsilons @@ -2457,6 +2519,18 @@ ok {test-number} - listingString, ContainsSubstring( "fake test name"s ) && Cont # Reporter's write listings to provided stream ok {test-number} - !(factories.empty()) for: !false # Reporter's write listings to provided stream +ok {test-number} - listingString, ContainsSubstring("fakeTag"s) for: "{ "version": 1, "metadata": { "name": "", "rng-seed": 3063158779, "catch2-version": "" }, "listings": { "tags": [ { "aliases": [ "fakeTag" ], "count": 1 } ]" contains: "fakeTag" with 1 message: 'Tested reporter: JSON' +# Reporter's write listings to provided stream +ok {test-number} - !(factories.empty()) for: !false +# Reporter's write listings to provided stream +ok {test-number} - listingString, ContainsSubstring("fake reporter"s) for: "{ "version": 1, "metadata": { "name": "", "rng-seed": 4167192188, "catch2-version": "" }, "listings": { "reporters": [ { "name": "fake reporter", "description": "fake description" } ]" contains: "fake reporter" with 1 message: 'Tested reporter: JSON' +# Reporter's write listings to provided stream +ok {test-number} - !(factories.empty()) for: !false +# Reporter's write listings to provided stream +ok {test-number} - listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) for: "{ "version": 1, "metadata": { "name": "", "rng-seed": 2012246564, "catch2-version": "" }, "listings": { "tests": [ { "name": "fake test name", "class-name": "", "tags": [ "fakeTestTag" ], "source-location": { "filename": "fake-file.cpp", "line": 123456789 } } ]" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: JSON' +# Reporter's write listings to provided stream +ok {test-number} - !(factories.empty()) for: !false +# Reporter's write listings to provided stream ok {test-number} - listingString, ContainsSubstring("fakeTag"s) for: " All available tags: 1 [fakeTag] 1 tag " contains: "fakeTag" with 1 message: 'Tested reporter: JUnit' # Reporter's write listings to provided stream ok {test-number} - !(factories.empty()) for: !false @@ -4478,5 +4552,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2242 +1..2258 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 4293464dfb..35ff74ac48 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -420,6 +420,8 @@ ##teamcity[testFinished name='Inequality checks that should fail' duration="{duration}"] ##teamcity[testStarted name='Inequality checks that should succeed'] ##teamcity[testFinished name='Inequality checks that should succeed' duration="{duration}"] +##teamcity[testStarted name='JsonWriter'] +##teamcity[testFinished name='JsonWriter' duration="{duration}"] ##teamcity[testStarted name='Lambdas in assertions'] ##teamcity[testFinished name='Lambdas in assertions' duration="{duration}"] ##teamcity[testStarted name='Less-than inequalities with different epsilons'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index b68d8bdb7b..d559c1fe7f 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -420,6 +420,8 @@ ##teamcity[testFinished name='Inequality checks that should fail' duration="{duration}"] ##teamcity[testStarted name='Inequality checks that should succeed'] ##teamcity[testFinished name='Inequality checks that should succeed' duration="{duration}"] +##teamcity[testStarted name='JsonWriter'] +##teamcity[testFinished name='JsonWriter' duration="{duration}"] ##teamcity[testStarted name='Lambdas in assertions'] ##teamcity[testFinished name='Lambdas in assertions' duration="{duration}"] ##teamcity[testStarted name='Less-than inequalities with different epsilons'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 89ce930e75..4d80589c4f 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -8779,6 +8779,267 @@ C + +
+ + + stream.str() == R"json( +)json" + + + " +" +== +" +" + + + +
+
+ + + stream.str() == R"json( +{ +})json" + + + " +{ +}" +== +" +{ +}" + + + +
+
+ + + stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" + + + " +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" +== +" +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" + + + +
+
+ + + stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" + + + " +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" +== +" +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" + + + +
+
+ + + stream.str() == R"json( +[ +])json" + + + " +[ +]" +== +" +[ +]" + + + +
+
+ + + stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" + + + " +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" +== +" +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" + + + +
+
+ + + stream.str() == R"json( +{ +})json" + + + " +{ +}" +== +" +{ +}" + + + +
+
+ + + stream.str() == R"json( +[ +])json" + + + " +[ +]" +== +" +[ +]" + + + +
+
+ + + stream.str() == R"json( +"custom")json" + + + " +"custom"" +== +" +"custom"" + + + +
+
+ + + stream.str() == "\n\"\\\"\"" + + + " +"\""" +== +" +"\""" + + + +
+ +
@@ -11695,6 +11956,120 @@ C !false +
+ + Tested reporter: JSON + + + + listingString, ContainsSubstring("fakeTag"s) + + + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 1034695662, + "catch2-version": "" + }, + "listings": { + "tags": [ + { + "aliases": [ + "fakeTag" + ], + "count": 1 + } + ]" contains: "fakeTag" + + + +
+ + + !(factories.empty()) + + + !false + + +
+ + Tested reporter: JSON + + + + listingString, ContainsSubstring("fake reporter"s) + + + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 1858798674, + "catch2-version": "" + }, + "listings": { + "reporters": [ + { + "name": "fake reporter", + "description": "fake description" + } + ]" contains: "fake reporter" + + + +
+ + + !(factories.empty()) + + + !false + + +
+ + Tested reporter: JSON + + + + listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) + + + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 3265885656, + "catch2-version": "" + }, + "listings": { + "tests": [ + { + "name": "fake test name", + "class-name": "", + "tags": [ + "fakeTestTag" + ], + "source-location": { + "filename": "fake-file.cpp", + "line": 123456789 + } + } + ]" ( contains: "fake test name" and contains: "fakeTestTag" ) + + + +
+ + + !(factories.empty()) + + + !false + +
Tested reporter: JUnit @@ -21268,6 +21643,6 @@ b1!
- - + + diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index 070db9f9f4..5c961edbb4 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -8779,6 +8779,267 @@ C
+ +
+ + + stream.str() == R"json( +)json" + + + " +" +== +" +" + + + +
+
+ + + stream.str() == R"json( +{ +})json" + + + " +{ +}" +== +" +{ +}" + + + +
+
+ + + stream.str() == R"json( +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +})json" + + + " +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" +== +" +{ + "int": 1, + "double": 1.5, + "true": true, + "false": false, + "string": "this is a string", + "array": [ + 1, + 2 + ] +}" + + + +
+
+ + + stream.str() == R"json( +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +})json" + + + " +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" +== +" +{ + "empty_object": { + }, + "fully_object": { + "key": 1 + } +}" + + + +
+
+ + + stream.str() == R"json( +[ +])json" + + + " +[ +]" +== +" +[ +]" + + + +
+
+ + + stream.str() == R"json( +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +])json" + + + " +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" +== +" +[ + 1, + 1.5, + true, + false, + "this is a string", + { + "object": 42 + }, + [ + "array", + 42.5 + ] +]" + + + +
+
+ + + stream.str() == R"json( +{ +})json" + + + " +{ +}" +== +" +{ +}" + + + +
+
+ + + stream.str() == R"json( +[ +])json" + + + " +[ +]" +== +" +[ +]" + + + +
+
+ + + stream.str() == R"json( +"custom")json" + + + " +"custom"" +== +" +"custom"" + + + +
+
+ + + stream.str() == "\n\"\\\"\"" + + + " +"\""" +== +" +"\""" + + + +
+ +
@@ -11695,6 +11956,120 @@ C !false +
+ + Tested reporter: JSON + + + + listingString, ContainsSubstring("fakeTag"s) + + + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 3063158779, + "catch2-version": "" + }, + "listings": { + "tags": [ + { + "aliases": [ + "fakeTag" + ], + "count": 1 + } + ]" contains: "fakeTag" + + + +
+ + + !(factories.empty()) + + + !false + + +
+ + Tested reporter: JSON + + + + listingString, ContainsSubstring("fake reporter"s) + + + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 4167192188, + "catch2-version": "" + }, + "listings": { + "reporters": [ + { + "name": "fake reporter", + "description": "fake description" + } + ]" contains: "fake reporter" + + + +
+ + + !(factories.empty()) + + + !false + + +
+ + Tested reporter: JSON + + + + listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) + + + "{ + "version": 1, + "metadata": { + "name": "", + "rng-seed": 2012246564, + "catch2-version": "" + }, + "listings": { + "tests": [ + { + "name": "fake test name", + "class-name": "", + "tags": [ + "fakeTestTag" + ], + "source-location": { + "filename": "fake-file.cpp", + "line": 123456789 + } + } + ]" ( contains: "fake test name" and contains: "fakeTestTag" ) + + + +
+ + + !(factories.empty()) + + + !false + +
Tested reporter: JUnit @@ -21267,6 +21642,6 @@ b1!
- - + +