mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 21:05:39 +02:00
merge from tags
This commit is contained in:
@@ -15,21 +15,24 @@ namespace Counter {
|
||||
int g_haveCountedMessages = 0;
|
||||
}
|
||||
|
||||
// This test works with the equivalent in MessageInstantiationTests2.cpp
|
||||
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||
// just check the value. The purpose of this test is to verify that the compiler's
|
||||
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||
// references to the globalCount
|
||||
|
||||
TEST_CASE("message counting1","")
|
||||
namespace MI1
|
||||
{
|
||||
if( Counter::g_haveCountedMessages > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
// This test works with the equivalent in MessageInstantiationTests2.cpp
|
||||
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||
// just check the value. The purpose of this test is to verify that the compiler's
|
||||
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||
// references to the globalCount
|
||||
|
||||
TEST_CASE("message counting1","")
|
||||
{
|
||||
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||
Counter::g_haveCountedMessages = 1;
|
||||
if( Counter::g_haveCountedMessages > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||
Counter::g_haveCountedMessages = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,14 +40,17 @@ namespace LongCounter {
|
||||
int g_haveCountedMessagesLong = 0;
|
||||
}
|
||||
|
||||
TEST_CASE("long message counting1","")
|
||||
namespace MI1
|
||||
{
|
||||
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
TEST_CASE("long message counting1","")
|
||||
{
|
||||
++Catch::MessageInfoCounter<long>::globalCount;
|
||||
LongCounter::g_haveCountedMessagesLong = 1;
|
||||
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<long>::globalCount;
|
||||
LongCounter::g_haveCountedMessagesLong = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,21 +14,24 @@ namespace Counter {
|
||||
extern int g_haveCountedMessages;
|
||||
}
|
||||
|
||||
// This test works with the equivalent in MessageInstantiationTests1.cpp
|
||||
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||
// just check the value. The purpose of this test is to verify that the compiler's
|
||||
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||
// references to the globalCount
|
||||
|
||||
TEST_CASE("message counting2","")
|
||||
namespace MI2
|
||||
{
|
||||
if( Counter::g_haveCountedMessages > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
// This test works with the equivalent in MessageInstantiationTests1.cpp
|
||||
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||
// just check the value. The purpose of this test is to verify that the compiler's
|
||||
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||
// references to the globalCount
|
||||
|
||||
TEST_CASE("message counting2","")
|
||||
{
|
||||
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||
Counter::g_haveCountedMessages = 1;
|
||||
if( Counter::g_haveCountedMessages > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||
Counter::g_haveCountedMessages = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +39,17 @@ namespace LongCounter {
|
||||
extern int g_haveCountedMessagesLong;
|
||||
}
|
||||
|
||||
TEST_CASE("long message counting2","")
|
||||
namespace MI2
|
||||
{
|
||||
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
TEST_CASE("long message counting2","")
|
||||
{
|
||||
++Catch::MessageInfoCounter<long>::globalCount;
|
||||
LongCounter::g_haveCountedMessagesLong = 1;
|
||||
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<long>::globalCount;
|
||||
LongCounter::g_haveCountedMessagesLong = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
187
projects/SelfTest/RunAllTests.cpp
Normal file
187
projects/SelfTest/RunAllTests.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Created by Phil on 22/10/2010.
|
||||
* Copyright 2010 Two Blue Cubes Ltd
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "internal/catch_text.h"
|
||||
#include "internal/catch_console_colour.hpp"
|
||||
|
||||
namespace AllTestsRunner {
|
||||
|
||||
class NullStreamingReporter : public Catch::SharedImpl<Catch::IStreamingReporter> {
|
||||
public:
|
||||
|
||||
virtual ~NullStreamingReporter();
|
||||
|
||||
static std::string getDescription() {
|
||||
return "null reporter";
|
||||
}
|
||||
|
||||
private: // IStreamingReporter
|
||||
|
||||
virtual Catch::ReporterPreferences getPreferences() const {
|
||||
return Catch::ReporterPreferences();
|
||||
}
|
||||
|
||||
virtual void noMatchingTestCases( std::string const& ) {}
|
||||
virtual void testRunStarting( Catch::TestRunInfo const& ) {}
|
||||
virtual void testGroupStarting( Catch::GroupInfo const& ) {}
|
||||
virtual void testCaseStarting( Catch::TestCaseInfo const& ) {}
|
||||
virtual void sectionStarting( Catch::SectionInfo const& ) {}
|
||||
virtual void assertionStarting( Catch::AssertionInfo const& ) {}
|
||||
virtual bool assertionEnded( Catch::AssertionStats const& ) { return false; }
|
||||
virtual void sectionEnded( Catch::SectionStats const& ) {}
|
||||
virtual void testCaseEnded( Catch::TestCaseStats const& ) {}
|
||||
virtual void testGroupEnded( Catch::TestGroupStats const& ) {}
|
||||
virtual void testRunEnded( Catch::TestRunStats const& ) {}
|
||||
};
|
||||
|
||||
class EmbeddedRunner {
|
||||
|
||||
public:
|
||||
EmbeddedRunner() : m_reporter( new NullStreamingReporter() ) {}
|
||||
|
||||
Catch::Totals runMatching( const std::string& rawTestSpec,
|
||||
std::size_t groupIndex,
|
||||
std::size_t groupsCount,
|
||||
const std::string& reporter = "console" );
|
||||
|
||||
private:
|
||||
Catch::Ptr<Catch::IStreamingReporter> m_reporter;
|
||||
};
|
||||
|
||||
class MetaTestRunner {
|
||||
|
||||
public:
|
||||
struct Expected { enum Result {
|
||||
ToSucceed,
|
||||
ToFail
|
||||
}; };
|
||||
|
||||
MetaTestRunner( Expected::Result expectedResult, std::size_t groupIndex, std::size_t groupsCount )
|
||||
: m_expectedResult( expectedResult ),
|
||||
m_groupIndex( groupIndex ),
|
||||
m_groupsCount( groupsCount )
|
||||
{}
|
||||
|
||||
static void runMatching( const std::string& testSpec,
|
||||
Expected::Result expectedResult,
|
||||
std::size_t groupIndex,
|
||||
std::size_t groupsCount ) {
|
||||
forEach( Catch::getRegistryHub().getTestCaseRegistry().getMatchingTestCases( testSpec ),
|
||||
MetaTestRunner( expectedResult, groupIndex, groupsCount ) );
|
||||
}
|
||||
|
||||
void operator()( const Catch::TestCase& testCase ) {
|
||||
std::string name;
|
||||
Catch::Totals totals;
|
||||
{
|
||||
EmbeddedRunner runner;
|
||||
name = testCase.getTestCaseInfo().name;
|
||||
totals = runner.runMatching( name, m_groupIndex, m_groupsCount );
|
||||
}
|
||||
switch( m_expectedResult ) {
|
||||
case Expected::ToSucceed:
|
||||
if( totals.assertions.failed > 0 ) {
|
||||
FAIL( "Expected test case '"
|
||||
<< name
|
||||
<< "' to succeed but there was/ were "
|
||||
<< totals.assertions.failed << " failure(s)" );
|
||||
}
|
||||
else {
|
||||
SUCCEED( "Tests passed, as expected" );
|
||||
}
|
||||
break;
|
||||
case Expected::ToFail:
|
||||
if( totals.assertions.failed == 0 ) {
|
||||
FAIL( "Expected test case '"
|
||||
<< name
|
||||
<< "' to fail but there was/ were "
|
||||
<< totals.assertions.passed << " success(es)" );
|
||||
}
|
||||
else {
|
||||
SUCCEED( "Tests failed, as expected" );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Expected::Result m_expectedResult;
|
||||
std::size_t m_groupIndex;
|
||||
std::size_t m_groupsCount;
|
||||
};
|
||||
|
||||
NullStreamingReporter::~NullStreamingReporter() {}
|
||||
|
||||
Catch::Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, std::size_t groupIndex, std::size_t groupsCount, const std::string& ) {
|
||||
std::ostringstream oss;
|
||||
Catch::Ptr<Catch::Config> config = new Catch::Config();
|
||||
config->setStreamBuf( oss.rdbuf() );
|
||||
|
||||
Catch::Totals totals;
|
||||
|
||||
// Scoped because RunContext doesn't report EndTesting until its destructor
|
||||
{
|
||||
Catch::RunContext runner( config.get(), m_reporter.get() );
|
||||
totals = runner.runMatching( rawTestSpec, groupIndex, groupsCount );
|
||||
}
|
||||
return totals;
|
||||
}
|
||||
|
||||
TEST_CASE( "Run all failing and succeeding tests", "[vsall]" ) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
SECTION( "selftest/expected result",
|
||||
"Tests do what they claim" ) {
|
||||
|
||||
#ifdef _UNICODE
|
||||
std::cout << "using Unicode..." << std::endl;
|
||||
#else
|
||||
std::cout << "using Mbcs..." << std::endl;
|
||||
#endif
|
||||
|
||||
SECTION( "selftest/expected result/failing tests",
|
||||
"Tests in the 'failing' branch fail" ) {
|
||||
std::cout << "Tests in the 'failing' branch fail" << std::endl;
|
||||
MetaTestRunner::runMatching( "./failing/*", MetaTestRunner::Expected::ToFail, 0, 2 );
|
||||
}
|
||||
|
||||
SECTION( "selftest/expected result/succeeding tests",
|
||||
"Tests in the 'succeeding' branch succeed" ) {
|
||||
std::cout << "Tests in the 'succeeding' branch succeed" << std::endl;
|
||||
MetaTestRunner::runMatching( "./succeeding/*", MetaTestRunner::Expected::ToSucceed, 1, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
SECTION( "selftest/test counts",
|
||||
"Number of test cases that run is fixed" ) {
|
||||
EmbeddedRunner runner;
|
||||
|
||||
SECTION( "selftest/test counts/succeeding tests",
|
||||
"Number of 'succeeding' tests is fixed" ) {
|
||||
std::cout << "Number of 'succeeding' tests is fixed" << std::endl;
|
||||
Catch::Totals totals = runner.runMatching( "./succeeding/*", 0, 2 );
|
||||
CHECK( totals.assertions.passed == 298 );
|
||||
CHECK( totals.assertions.failed == 0 );
|
||||
}
|
||||
|
||||
SECTION( "selftest/test counts/failing tests",
|
||||
"Number of 'failing' tests is fixed" ) {
|
||||
std::cout << "Number of 'failing' tests is fixed" << std::endl;
|
||||
Catch::Totals totals = runner.runMatching( "./failing/*", 1, 2 );
|
||||
CHECK( totals.assertions.passed == 2 );
|
||||
CHECK( totals.assertions.failed == 77 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(INTERNAL_CATCH_VS_MANAGED) || defined(INTERNAL_CATCH_VS_NATIVE)
|
||||
CATCH_MAP_CATEGORY_TO_TAG(all, "[vsall]");
|
||||
#endif
|
||||
}
|
@@ -346,35 +346,35 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
|
||||
std::string testString = "one two three four";
|
||||
|
||||
SECTION( "No wrapping", "" ) {
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString );
|
||||
}
|
||||
SECTION( "Wrapped once", "" ) {
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 17 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 16 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 14 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 13 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 12 ) ).toString() == "one two\nthree four" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 17 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 16 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 14 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 13 ) ).toString() == "one two three\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 12 ) ).toString() == "one two\nthree four" );
|
||||
}
|
||||
SECTION( "Wrapped twice", "" ) {
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" );
|
||||
}
|
||||
SECTION( "Wrapped three times", "" ) {
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 5 ) ).toString() == "one\ntwo\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 5 ) ).toString() == "one\ntwo\nthree\nfour" );
|
||||
}
|
||||
SECTION( "Short wrap", "" ) {
|
||||
CHECK( Text( "abcdef", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef" );
|
||||
CHECK( Text( "abcdefg", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndefg" );
|
||||
CHECK( Text( "abcdefgh", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef-\ngh" );
|
||||
CHECK( Catch::Text( "abcdef", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef" );
|
||||
CHECK( Catch::Text( "abcdefg", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndefg" );
|
||||
CHECK( Catch::Text( "abcdefgh", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef-\ngh" );
|
||||
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 4 ) ).toString() == "one\ntwo\nthr-\nee\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 3 ) ).toString() == "one\ntwo\nth-\nree\nfo-\nur" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 4 ) ).toString() == "one\ntwo\nthr-\nee\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 3 ) ).toString() == "one\ntwo\nth-\nree\nfo-\nur" );
|
||||
}
|
||||
SECTION( "As container", "" ) {
|
||||
Text text( testString, TextAttributes().setWidth( 6 ) );
|
||||
Catch::Text text( testString, TextAttributes().setWidth( 6 ) );
|
||||
REQUIRE( text.size() == 4 );
|
||||
CHECK( text[0] == "one" );
|
||||
CHECK( text[1] == "two" );
|
||||
@@ -382,7 +382,7 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
|
||||
CHECK( text[3] == "four" );
|
||||
}
|
||||
SECTION( "Indent first line differently", "" ) {
|
||||
Text text( testString, TextAttributes()
|
||||
Catch::Text text( testString, TextAttributes()
|
||||
.setWidth( 10 )
|
||||
.setIndent( 4 )
|
||||
.setInitialIndent( 1 ) );
|
||||
@@ -397,22 +397,22 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
|
||||
std::string testString = "one two\nthree four";
|
||||
|
||||
SECTION( "No wrapping" , "" ) {
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 10 ) ).toString() == testString );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 10 ) ).toString() == testString );
|
||||
}
|
||||
SECTION( "Trailing newline" , "" ) {
|
||||
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef\n" );
|
||||
CHECK( Text( "abcdef", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" );
|
||||
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef\n" );
|
||||
CHECK( Catch::Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef\n" );
|
||||
CHECK( Catch::Text( "abcdef", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" );
|
||||
CHECK( Catch::Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef\n" );
|
||||
}
|
||||
SECTION( "Wrapped once", "" ) {
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" );
|
||||
}
|
||||
SECTION( "Wrapped twice", "" ) {
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" );
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
|
||||
// guide: 1234567890123456789
|
||||
std::string testString = "one two \tthree four five six";
|
||||
|
||||
CHECK( Text( testString, TextAttributes().setWidth( 15 ) ).toString()
|
||||
CHECK( Catch::Text( testString, TextAttributes().setWidth( 15 ) ).toString()
|
||||
== "one two three\n four\n five\n six" );
|
||||
}
|
||||
|
||||
@@ -522,12 +522,12 @@ TEST_CASE( "Strings can be rendered with colour", "[colour]" ) {
|
||||
|
||||
TEST_CASE( "Text can be formatted using the Text class", "" ) {
|
||||
|
||||
CHECK( Text( "hi there" ).toString() == "hi there" );
|
||||
CHECK( Catch::Text( "hi there" ).toString() == "hi there" );
|
||||
|
||||
TextAttributes narrow;
|
||||
narrow.setWidth( 6 );
|
||||
|
||||
CHECK( Text( "hi there", narrow ).toString() == "hi\nthere" );
|
||||
CHECK( Catch::Text( "hi there", narrow ).toString() == "hi\nthere" );
|
||||
}
|
||||
|
||||
TEST_CASE( "Long text is truncted", "[Text][Truncated]" ) {
|
||||
@@ -537,7 +537,7 @@ TEST_CASE( "Long text is truncted", "[Text][Truncated]" ) {
|
||||
std::ostringstream oss;
|
||||
for(int i = 0; i < 600; ++i )
|
||||
oss << longLine << longLine << "\n";
|
||||
Text t( oss.str() );
|
||||
Catch::Text t( oss.str() );
|
||||
CHECK_THAT( t.toString(), EndsWith( "... message truncated due to excessive size" ) );
|
||||
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ namespace Catch
|
||||
}
|
||||
}
|
||||
|
||||
namespace TrickTests
|
||||
namespace TrickyTests
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TEST_CASE
|
||||
@@ -209,177 +209,180 @@ namespace ObjectWithNonConstEqualityOperator
|
||||
}
|
||||
}
|
||||
|
||||
namespace EnumBitFieldTests
|
||||
namespace TrickyTests
|
||||
{
|
||||
enum Bits {bit0 = 0x0001, bit1 = 0x0002, bit2 = 0x0004, bit3 = 0x0008, bit1and2 = 0x0006,
|
||||
bit30 = 0x40000000, bit31 = 0x80000000,
|
||||
bit30and31 = 0xc0000000};
|
||||
|
||||
TEST_CASE( "Test enum bit values", "[Tricky]" )
|
||||
namespace EnumBitFieldTests
|
||||
{
|
||||
REQUIRE( 0xc0000000 == bit30and31 );
|
||||
}
|
||||
}
|
||||
enum Bits {bit0 = 0x0001, bit1 = 0x0002, bit2 = 0x0004, bit3 = 0x0008, bit1and2 = 0x0006,
|
||||
bit30 = 0x40000000, bit31 = 0x80000000,
|
||||
bit30and31 = 0xc0000000};
|
||||
|
||||
struct Obj
|
||||
{
|
||||
Obj():prop(&p){}
|
||||
TEST_CASE( "Test enum bit values", "[Tricky]" )
|
||||
{
|
||||
REQUIRE( 0xc0000000 == bit30and31 );
|
||||
}
|
||||
}
|
||||
|
||||
struct Obj
|
||||
{
|
||||
Obj():prop(&p){}
|
||||
|
||||
int p;
|
||||
int* prop;
|
||||
};
|
||||
int p;
|
||||
int* prop;
|
||||
};
|
||||
|
||||
TEST_CASE("boolean member", "[Tricky]")
|
||||
{
|
||||
Obj obj;
|
||||
REQUIRE( obj.prop != NULL );
|
||||
}
|
||||
|
||||
// Tests for a problem submitted by Ralph McArdell
|
||||
//
|
||||
// The static bool value should not need to be defined outside the
|
||||
// struct it is declared in - but when evaluating it in a deduced
|
||||
// context it appears to require the extra definition.
|
||||
// The issue was fixed by adding bool overloads to bypass the
|
||||
// templates that were there to deduce it.
|
||||
template <bool B>
|
||||
struct is_true
|
||||
{
|
||||
static const bool value = B;
|
||||
};
|
||||
|
||||
TEST_CASE( "(unimplemented) static bools can be evaluated", "[Tricky]" )
|
||||
{
|
||||
SECTION("compare to true","")
|
||||
TEST_CASE("boolean member", "[Tricky]")
|
||||
{
|
||||
REQUIRE( is_true<true>::value == true );
|
||||
REQUIRE( true == is_true<true>::value );
|
||||
}
|
||||
SECTION("compare to false","")
|
||||
{
|
||||
REQUIRE( is_true<false>::value == false );
|
||||
REQUIRE( false == is_true<false>::value );
|
||||
Obj obj;
|
||||
REQUIRE( obj.prop != NULL );
|
||||
}
|
||||
|
||||
SECTION("negation", "")
|
||||
// Tests for a problem submitted by Ralph McArdell
|
||||
//
|
||||
// The static bool value should not need to be defined outside the
|
||||
// struct it is declared in - but when evaluating it in a deduced
|
||||
// context it appears to require the extra definition.
|
||||
// The issue was fixed by adding bool overloads to bypass the
|
||||
// templates that were there to deduce it.
|
||||
template <bool B>
|
||||
struct is_true
|
||||
{
|
||||
REQUIRE( !is_true<false>::value );
|
||||
static const bool value = B;
|
||||
};
|
||||
|
||||
TEST_CASE( "(unimplemented) static bools can be evaluated", "[Tricky]" )
|
||||
{
|
||||
SECTION("compare to true","")
|
||||
{
|
||||
REQUIRE( is_true<true>::value == true );
|
||||
REQUIRE( true == is_true<true>::value );
|
||||
}
|
||||
SECTION("compare to false","")
|
||||
{
|
||||
REQUIRE( is_true<false>::value == false );
|
||||
REQUIRE( false == is_true<false>::value );
|
||||
}
|
||||
|
||||
SECTION("negation", "")
|
||||
{
|
||||
REQUIRE( !is_true<false>::value );
|
||||
}
|
||||
|
||||
SECTION("double negation","")
|
||||
{
|
||||
REQUIRE( !!is_true<true>::value );
|
||||
}
|
||||
|
||||
SECTION("direct","")
|
||||
{
|
||||
REQUIRE( is_true<true>::value );
|
||||
REQUIRE_FALSE( is_true<false>::value );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("double negation","")
|
||||
// Uncomment these tests to produce an error at test registration time
|
||||
/*
|
||||
TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" )
|
||||
{
|
||||
REQUIRE( !!is_true<true>::value );
|
||||
}
|
||||
|
||||
SECTION("direct","")
|
||||
{
|
||||
REQUIRE( is_true<true>::value );
|
||||
REQUIRE_FALSE( is_true<false>::value );
|
||||
}
|
||||
}
|
||||
|
||||
// Uncomment these tests to produce an error at test registration time
|
||||
/*
|
||||
TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" )
|
||||
{
|
||||
|
||||
}
|
||||
TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" )
|
||||
{
|
||||
}
|
||||
TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" )
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
*/
|
||||
|
||||
struct Boolable
|
||||
{
|
||||
explicit Boolable( bool value ) : m_value( value ) {}
|
||||
struct Boolable
|
||||
{
|
||||
explicit Boolable( bool value ) : m_value( value ) {}
|
||||
|
||||
operator Catch::SafeBool::type() const {
|
||||
return Catch::SafeBool::makeSafe( m_value );
|
||||
operator Catch::SafeBool::type() const {
|
||||
return Catch::SafeBool::makeSafe( m_value );
|
||||
}
|
||||
|
||||
bool m_value;
|
||||
};
|
||||
|
||||
TEST_CASE( "Objects that evaluated in boolean contexts can be checked", "[Tricky][SafeBool]" )
|
||||
{
|
||||
Boolable True( true );
|
||||
Boolable False( false );
|
||||
|
||||
CHECK( True );
|
||||
CHECK( !False );
|
||||
CHECK_FALSE( False );
|
||||
}
|
||||
|
||||
bool m_value;
|
||||
};
|
||||
|
||||
TEST_CASE( "Objects that evaluated in boolean contexts can be checked", "[Tricky][SafeBool]" )
|
||||
{
|
||||
Boolable True( true );
|
||||
Boolable False( false );
|
||||
|
||||
CHECK( True );
|
||||
CHECK( !False );
|
||||
CHECK_FALSE( False );
|
||||
}
|
||||
|
||||
TEST_CASE( "Assertions then sections", "[Tricky]" )
|
||||
{
|
||||
// This was causing a failure due to the way the console reporter was handling
|
||||
// the current section
|
||||
|
||||
REQUIRE( Catch::isTrue( true ) );
|
||||
|
||||
SECTION( "A section", "" )
|
||||
TEST_CASE( "Assertions then sections", "[Tricky]" )
|
||||
{
|
||||
// This was causing a failure due to the way the console reporter was handling
|
||||
// the current section
|
||||
|
||||
REQUIRE( Catch::isTrue( true ) );
|
||||
|
||||
SECTION( "A section", "" )
|
||||
{
|
||||
REQUIRE( Catch::isTrue( true ) );
|
||||
|
||||
SECTION( "Another section", "" )
|
||||
{
|
||||
REQUIRE( Catch::isTrue( true ) );
|
||||
}
|
||||
SECTION( "Another other section", "" )
|
||||
{
|
||||
REQUIRE( Catch::isTrue( true ) );
|
||||
SECTION( "Another section", "" )
|
||||
{
|
||||
REQUIRE( Catch::isTrue( true ) );
|
||||
}
|
||||
SECTION( "Another other section", "" )
|
||||
{
|
||||
REQUIRE( Catch::isTrue( true ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Awkward
|
||||
{
|
||||
operator int() const { return 7; }
|
||||
};
|
||||
|
||||
TEST_CASE( "non streamable - with conv. op", "[Tricky]" )
|
||||
{
|
||||
Awkward awkward;
|
||||
std::string s = Catch::toString( awkward );
|
||||
REQUIRE( s == "7" );
|
||||
}
|
||||
|
||||
inline void foo() {}
|
||||
|
||||
typedef void (*fooptr_t)();
|
||||
|
||||
TEST_CASE( "Comparing function pointers", "[Tricky][function pointer]" )
|
||||
{
|
||||
// This was giving a warning in VS2010
|
||||
// #179
|
||||
fooptr_t a = foo;
|
||||
|
||||
REQUIRE( a );
|
||||
REQUIRE( a == &foo );
|
||||
}
|
||||
|
||||
class ClassName {};
|
||||
|
||||
TEST_CASE( "pointer to class", "[Tricky]" )
|
||||
{
|
||||
ClassName *p = 0;
|
||||
REQUIRE( p == 0 );
|
||||
}
|
||||
|
||||
#ifdef CATCH_CONFIG_CPP11_NULLPTR
|
||||
|
||||
#include <memory>
|
||||
|
||||
TEST_CASE( "null_ptr", "[Tricky]" )
|
||||
{
|
||||
std::unique_ptr<int> ptr;
|
||||
REQUIRE(ptr.get() == nullptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_CASE( "X/level/0/a", "[Tricky]" ) { SUCCEED(""); }
|
||||
TEST_CASE( "X/level/0/b", "[Tricky][fizz]" ){ SUCCEED(""); }
|
||||
TEST_CASE( "X/level/1/a", "[Tricky]" ) { SUCCEED(""); }
|
||||
TEST_CASE( "X/level/1/b", "[Tricky]" ) { SUCCEED(""); }
|
||||
}
|
||||
|
||||
struct Awkward
|
||||
{
|
||||
operator int() const { return 7; }
|
||||
};
|
||||
|
||||
TEST_CASE( "non streamable - with conv. op", "[Tricky]" )
|
||||
{
|
||||
Awkward awkward;
|
||||
std::string s = Catch::toString( awkward );
|
||||
REQUIRE( s == "7" );
|
||||
}
|
||||
|
||||
inline void foo() {}
|
||||
|
||||
typedef void (*fooptr_t)();
|
||||
|
||||
TEST_CASE( "Comparing function pointers", "[Tricky][function pointer]" )
|
||||
{
|
||||
// This was giving a warning in VS2010
|
||||
// #179
|
||||
fooptr_t a = foo;
|
||||
|
||||
REQUIRE( a );
|
||||
REQUIRE( a == &foo );
|
||||
}
|
||||
|
||||
class ClassName {};
|
||||
|
||||
TEST_CASE( "pointer to class", "[Tricky]" )
|
||||
{
|
||||
ClassName *p = 0;
|
||||
REQUIRE( p == 0 );
|
||||
}
|
||||
|
||||
#ifdef CATCH_CONFIG_CPP11_NULLPTR
|
||||
|
||||
#include <memory>
|
||||
|
||||
TEST_CASE( "null_ptr", "[Tricky]" )
|
||||
{
|
||||
std::unique_ptr<int> ptr;
|
||||
REQUIRE(ptr.get() == nullptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_CASE( "X/level/0/a", "[Tricky]" ) { SUCCEED(""); }
|
||||
TEST_CASE( "X/level/0/b", "[Tricky][fizz]" ){ SUCCEED(""); }
|
||||
TEST_CASE( "X/level/1/a", "[Tricky]" ) { SUCCEED(""); }
|
||||
TEST_CASE( "X/level/1/b", "[Tricky]" ) { SUCCEED(""); }
|
||||
|
110
projects/SelfTest/VisualStudioTests.cpp
Normal file
110
projects/SelfTest/VisualStudioTests.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Created by Phil on 22/10/2010.
|
||||
* Copyright 2010 Two Blue Cubes Ltd
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#if defined(INTERNAL_CATCH_VS_MANAGED) || defined(INTERNAL_CATCH_VS_NATIVE)
|
||||
|
||||
namespace VisualStudioTests
|
||||
{
|
||||
class UniqueTestsFixture {
|
||||
private:
|
||||
static int uniqueID;
|
||||
public:
|
||||
UniqueTestsFixture() { }
|
||||
protected:
|
||||
int getID() {
|
||||
return ++uniqueID;
|
||||
}
|
||||
};
|
||||
|
||||
int UniqueTestsFixture::uniqueID = 0;
|
||||
TEST_CASE("M00", "[m_off]")
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(!show);
|
||||
}
|
||||
|
||||
CATCH_CONFIG_SHOW_SUCCESS(true)
|
||||
TEST_CASE("M01", "[m_on]")
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(show);
|
||||
}
|
||||
|
||||
TEST_CASE("M02", "[m_off]")
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(!show);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(UniqueTestsFixture, "M10", "[m_off]")
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(!show);
|
||||
getID();
|
||||
}
|
||||
|
||||
CATCH_CONFIG_WARN_MISSING_ASSERTIONS(true)
|
||||
CATCH_CONFIG_SHOW_SUCCESS(true)
|
||||
TEST_CASE_METHOD(UniqueTestsFixture, "M11", "[m_on]")
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(show);
|
||||
getID();
|
||||
}
|
||||
|
||||
CATCH_CONFIG_WARN_MISSING_ASSERTIONS(true)
|
||||
CATCH_CONFIG_SHOW_SUCCESS(true)
|
||||
TEST_CASE_METHOD(UniqueTestsFixture, "M99", "[m_on]")
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(show);
|
||||
WARN("Warning message");
|
||||
getID();
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(UniqueTestsFixture, "M12", "[m_off]")
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(!show);
|
||||
getID();
|
||||
}
|
||||
|
||||
class ConfigTest
|
||||
{
|
||||
public:
|
||||
void run1()
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(!show);
|
||||
}
|
||||
void run2()
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(show);
|
||||
}
|
||||
void run3()
|
||||
{
|
||||
bool show = Catch::getCurrentContext().getConfig()->includeSuccessfulResults();
|
||||
REQUIRE(!show);
|
||||
}
|
||||
};
|
||||
METHOD_AS_TEST_CASE(ConfigTest::run1,"M20", "[m_off]");
|
||||
|
||||
CATCH_CONFIG_SHOW_SUCCESS(true)
|
||||
METHOD_AS_TEST_CASE(ConfigTest::run2,"M21", "[m_on]");
|
||||
|
||||
METHOD_AS_TEST_CASE(ConfigTest::run3,"M22", "[m_off]");
|
||||
|
||||
CATCH_MAP_CATEGORY_TO_TAG(vstestsCheckOutputOff, "[m_off]");
|
||||
CATCH_CONFIG_SHOW_SUCCESS(true)
|
||||
CATCH_MAP_CATEGORY_TO_TAG(vstestsCheckOutputOn, "[m_on]");
|
||||
CATCH_MAP_CATEGORY_TO_TAG(vstestsCheckOutputOff2, "[m_off]");
|
||||
}
|
||||
#endif
|
@@ -4,8 +4,6 @@ SOURCES = ApproxTests.cpp \
|
||||
ExceptionTests.cpp \
|
||||
GeneratorTests.cpp \
|
||||
MessageTests.cpp \
|
||||
MessageInstantiationTests1.cpp \
|
||||
MessageInstantiationTests2.cpp \
|
||||
MiscTests.cpp \
|
||||
TestMain.cpp \
|
||||
TrickyTests.cpp \
|
||||
|
Reference in New Issue
Block a user