Compare commits

...

24 Commits

Author SHA1 Message Date
Phil Nash
e27c4ee042 Build 1.5.8 2016-10-26 12:08:26 +01:00
Phil Nash
072114293b Merge branch 'BillyONeal-master' 2016-10-26 12:06:35 +01:00
Phil Nash
f90ee9fb37 Merge branch 'master' of https://github.com/BillyONeal/Catch into BillyONeal-master 2016-10-26 12:04:38 +01:00
Billy Robert O'Neal III
c17ba0870a Fix transform without a lambda
Catch apparently supports targeting C++03, so use an inline function
instead.
2016-10-14 14:28:15 -07:00
Billy Robert O'Neal III
79f01100e3 Fix transform narrowing warnings
Catch passes ::tolower into std::transform with string iterators.
::tolower has the signature int(int), which triggers a stealth narrowing
warning inside std::transform, because transform calls
*_Dest = _Fn(*_First), which implicitly narrows an int to a char.

For this particular application the narrowing is fine, so explicitly
narrow in a lambda.
2016-10-14 14:16:21 -07:00
Billy Robert O'Neal III
ccf7f2842a Fix random_shuffle narrowing warnings
Catch passes an RNG which accepts int to random_shuffle. Inside
random_shuffle, the STL tries to call that RNG with the difference_type
of the user provided iterators. For std::vector, this is ptrdiff_t,
which on amd64 builds is wider than int. This triggers a narrowing
warning because the 64 bit difference is being truncated to 32 bits.

Note that this RNG implementation still does not produce a correctly
uniformly shuffled result -- it's currently asserting that std::rand
can produce 1000000 which is false -- but I don't know enough about
how much repeatable shuffles are necessary here, so I'm leaving that
alone for now.
2016-10-14 14:06:45 -07:00
Phil Nash
e0302db4a6 Rename element for Fatal Error Condition so it doesn't have spaces
Fixes: #685
2016-10-14 18:45:08 +01:00
Phil Nash
88732e85b2 Merge pull request #716 from jbcoe/master
Quick fix for failing travis builds on OS X
2016-10-04 15:57:10 +01:00
Phil Nash
1c9a6cab88 Removed XCode6 builds (which were erroring anyway) and added XCode8 builds 2016-09-27 11:20:33 +01:00
Phil Nash
40f6068d52 Build 1.5.7 2016-09-27 10:46:22 +01:00
Phil Nash
21cbfc107e --list-test-names quotes test names that start with #
- completes #717
2016-09-27 10:43:03 +01:00
Phil Nash
31861bbd46 rebased following recent changes 2016-09-27 10:28:11 +01:00
Phil Nash
b1eeec7c69 -f supports quoted test names (test name surrounded with " characters).
This is the first part to resolving #717
2016-09-27 10:27:28 +01:00
Phil Nash
c23b374f3d Added braces to emphasise the return logic 2016-09-27 09:58:12 +01:00
Phil Nash
916317bd81 Merge pull request #680 from nabijaczleweli/master
Fix misindent in internal/catch_test_spec.hpp:70
2016-09-27 09:49:37 +01:00
nabijaczleweli
8c459dd207 Fix misindent
Closes #679
2016-09-27 00:35:26 +02:00
Jonathan B. Coe
fd7d35464b quick fix for failing travis builds on os x 2016-09-24 19:38:43 +01:00
Phil Nash
c47c1797d2 Merge pull request #701 from razeh/master
Fixes for XML encoding.
2016-09-22 17:44:14 +01:00
Phil Nash
f5d2b2dce8 Merge pull request #705 from hmich/xml-reporter-trim
Do not trim test case names in the XML reporter.
2016-09-22 17:28:46 +01:00
Igor Akhmetov
02c7e41c7c Do not trim test case names in the XML reporter.
SCENARIO does not add leading spaces to the test name (only BDD-style section
names are modified), so the trimming is not necessary. But if the name is
trimmed, it makes it harder to correlate the output of XML reporter with tests
that have leading spaces in their name: e.g. these tests will have the same name
attribute:

TEST_CASE("Test") {}
TEST_CASE(" Test") {}
2016-08-30 11:15:19 +01:00
Robert A Zeh
5095619955 Fixes for XML encoding.
This commit fixes the following scenario:
  * You have a test that compares strings with embedded control
  characters.
  * The test fails.
  * You are using JUnit tests within TeamCity.

Before this commit, the JUnit report watcher fails on parsing the XML
for two reasons: the control characters are missing a semicolon at the
end, and the XML document doesn't specify that it is XML 1.1.

XML 1.0 --- what we get if we don't specify an XML version --- doesn't support embedding control characters --- see
http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml
for all of the gory details.

This is based on PR #588 by @mrpi
2016-08-24 09:38:24 -05:00
Phil Nash
35f510545d v1.5.6 2016-06-09 19:21:09 +01:00
Phil Nash
742457cbcf Use Clara v0.0.2.4 (updated) - fix for string lengths 2016-06-09 19:19:55 +01:00
Phil Nash
1aa6c91e64 Fixed RNG issue with pre C++14 compilers 2016-06-09 19:07:05 +01:00
17 changed files with 134 additions and 75 deletions

View File

@@ -119,23 +119,22 @@ matrix:
# 3/ OSX Clang Builds # 3/ OSX Clang Builds
- os: osx - os: osx
osx_image: xcode6.4 osx_image: xcode7
compiler: clang compiler: clang
env: COMPILER='ccache clang++' BUILD_TYPE='Debug' env: COMPILER='ccache clang++' BUILD_TYPE='Debug'
- os: osx - os: osx
osx_image: xcode6.4 osx_image: xcode7
compiler: clang compiler: clang
env: COMPILER='ccache clang++' BUILD_TYPE='Release' env: COMPILER='ccache clang++' BUILD_TYPE='Release'
- os: osx - os: osx
osx_image: xcode7 osx_image: xcode8
compiler: clang compiler: clang
env: COMPILER='ccache clang++' BUILD_TYPE='Debug' env: COMPILER='ccache clang++' BUILD_TYPE='Debug'
- os: osx - os: osx
osx_image: xcode7 osx_image: xcode8
compiler: clang compiler: clang
env: COMPILER='ccache clang++' BUILD_TYPE='Release' env: COMPILER='ccache clang++' BUILD_TYPE='Release'
@@ -149,7 +148,8 @@ install:
mkdir cmake && travis_retry wget --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake mkdir cmake && travis_retry wget --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake
export PATH=${DEPS_DIR}/cmake/bin:${PATH} export PATH=${DEPS_DIR}/cmake/bin:${PATH}
elif [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then elif [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
brew install cmake ccache which cmake || brew install cmake
which ccache || brew install ccache
fi fi
before_script: before_script:

View File

@@ -1,6 +1,6 @@
![catch logo](catch-logo-small.png) ![catch logo](catch-logo-small.png)
*v1.5.5* *v1.5.8*
Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch)

View File

@@ -589,7 +589,7 @@ namespace Clara {
} }
} }
Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
if( std::string( ":=\0", 5 ).find( c ) == std::string::npos ) if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
return mode; return mode;
std::string optName = arg.substr( from, i-from ); std::string optName = arg.substr( from, i-from );
@@ -603,7 +603,7 @@ namespace Clara {
return None; return None;
} }
Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
if( inQuotes || std::string( "\0", 3 ).find( c ) == std::string::npos ) if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
return mode; return mode;
std::string data = arg.substr( from, i-from ); std::string data = arg.substr( from, i-from );

View File

@@ -85,8 +85,11 @@ namespace Catch {
std::string line; std::string line;
while( std::getline( f, line ) ) { while( std::getline( f, line ) ) {
line = trim(line); line = trim(line);
if( !line.empty() && !startsWith( line, "#" ) ) if( !line.empty() && !startsWith( line, "#" ) ) {
addTestOrTags( config, "\"" + line + "\"," ); if( !startsWith( line, "\"" ) )
line = "\"" + line + "\"";
addTestOrTags( config, line + "," );
}
} }
} }

View File

@@ -21,8 +21,11 @@ namespace Catch {
bool contains( std::string const& s, std::string const& infix ) { bool contains( std::string const& s, std::string const& infix ) {
return s.find( infix ) != std::string::npos; return s.find( infix ) != std::string::npos;
} }
char toLowerCh(char c) {
return static_cast<char>( ::tolower( c ) );
}
void toLowerInPlace( std::string& s ) { void toLowerInPlace( std::string& s ) {
std::transform( s.begin(), s.end(), s.begin(), ::tolower ); std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
} }
std::string toLower( std::string const& s ) { std::string toLower( std::string const& s ) {
std::string lc = s; std::string lc = s;

View File

@@ -68,7 +68,10 @@ namespace Catch {
++it ) { ++it ) {
matchedTests++; matchedTests++;
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
Catch::cout() << testCaseInfo.name << std::endl; if( startsWith( testCaseInfo.name, "#" ) )
Catch::cout() << "\"" << testCaseInfo.name << "\"" << std::endl;
else
Catch::cout() << testCaseInfo.name << std::endl;
} }
return matchedTests; return matchedTests;
} }

View File

@@ -24,9 +24,9 @@
#endif #endif
namespace Catch { namespace Catch {
struct RandomNumberGenerator { struct RandomNumberGenerator {
typedef int result_type; typedef std::ptrdiff_t result_type;
result_type operator()( result_type n ) const { return std::rand() % n; } result_type operator()( result_type n ) const { return std::rand() % n; }
@@ -37,10 +37,11 @@ namespace Catch {
#endif #endif
template<typename V> template<typename V>
static void shuffle( V& vector ) { static void shuffle( V& vector ) {
RandomNumberGenerator rng;
#ifdef CATCH_CPP14_OR_GREATER #ifdef CATCH_CPP14_OR_GREATER
std::shuffle( vector.begin(), vector.end(), RandomNumberGenerator() ); std::shuffle( vector.begin(), vector.end(), rng );
#else #else
std::random_shuffle( vector.begin(), vector.end(), RandomNumberGenerator() ); std::random_shuffle( vector.begin(), vector.end(), rng );
#endif #endif
} }
}; };

View File

@@ -64,10 +64,11 @@ namespace Catch {
bool matches( TestCaseInfo const& testCase ) const { bool matches( TestCaseInfo const& testCase ) const {
// All patterns in a filter must match for the filter to be a match // All patterns in a filter must match for the filter to be a match
for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
if( !(*it)->matches( testCase ) ) if( !(*it)->matches( testCase ) )
return false; return false;
return true; }
return true;
} }
}; };

View File

@@ -37,7 +37,7 @@ namespace Catch {
return os; return os;
} }
Version libraryVersion( 1, 5, 5, "", 0 ); Version libraryVersion( 1, 5, 8, "", 0 );
} }

View File

@@ -55,9 +55,10 @@ namespace Catch {
break; break;
default: default:
// Escape control chars - based on contribution by @espenalb in PR #465 // Escape control chars - based on contribution by @espenalb in PR #465 and
// by @mrpi PR #588
if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' )
os << "&#x" << std::uppercase << std::hex << static_cast<int>( c ); os << "&#x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>( c ) << ';';
else else
os << c; os << c;
} }
@@ -112,13 +113,20 @@ namespace Catch {
: m_tagIsOpen( false ), : m_tagIsOpen( false ),
m_needsNewline( false ), m_needsNewline( false ),
m_os( &Catch::cout() ) m_os( &Catch::cout() )
{} {
// We encode control characters, which requires
// XML 1.1
// see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
*m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
}
XmlWriter( std::ostream& os ) XmlWriter( std::ostream& os )
: m_tagIsOpen( false ), : m_tagIsOpen( false ),
m_needsNewline( false ), m_needsNewline( false ),
m_os( &os ) m_os( &os )
{} {
*m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
}
~XmlWriter() { ~XmlWriter() {
while( !m_tags.empty() ) while( !m_tags.empty() )

View File

@@ -53,7 +53,7 @@ namespace Catch {
virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
StreamingReporterBase::testCaseStarting(testInfo); StreamingReporterBase::testCaseStarting(testInfo);
m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.name );
if ( m_config->showDurations() == ShowDurations::Always ) if ( m_config->showDurations() == ShowDurations::Always )
m_testCaseTimer.start(); m_testCaseTimer.start();
@@ -115,7 +115,7 @@ namespace Catch {
.writeText( assertionResult.getMessage() ); .writeText( assertionResult.getMessage() );
break; break;
case ResultWas::FatalErrorCondition: case ResultWas::FatalErrorCondition:
m_xml.scopedElement( "Fatal Error Condition" ) m_xml.scopedElement( "FatalErrorCondition" )
.writeAttribute( "filename", assertionResult.getSourceInfo().file ) .writeAttribute( "filename", assertionResult.getSourceInfo().file )
.writeAttribute( "line", assertionResult.getSourceInfo().line ) .writeAttribute( "line", assertionResult.getSourceInfo().line )
.writeText( assertionResult.getMessage() ); .writeText( assertionResult.getMessage() );

View File

@@ -830,6 +830,6 @@ with expansion:
"first" == "second" "first" == "second"
=============================================================================== ===============================================================================
test cases: 168 | 124 passed | 42 failed | 2 failed as expected test cases: 169 | 125 passed | 42 failed | 2 failed as expected
assertions: 920 | 824 passed | 78 failed | 18 failed as expected assertions: 921 | 825 passed | 78 failed | 18 failed as expected

View File

@@ -3920,9 +3920,9 @@ MiscTests.cpp:<line number>
MiscTests.cpp:<line number>: MiscTests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( encode( "[\x01]" ) == "[&#x1]" ) REQUIRE( encode( "[\x01]" ) == "[&#x01;]" )
with expansion: with expansion:
"[&#x1]" == "[&#x1]" "[&#x01;]" == "[&#x01;]"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
XmlEncode XmlEncode
@@ -3933,9 +3933,9 @@ MiscTests.cpp:<line number>
MiscTests.cpp:<line number>: MiscTests.cpp:<line number>:
PASSED: PASSED:
REQUIRE( encode( "[\x7F]" ) == "[&#x7F]" ) REQUIRE( encode( "[\x7F]" ) == "[&#x7F;]" )
with expansion: with expansion:
"[&#x7F]" == "[&#x7F]" "[&#x7F;]" == "[&#x7F;]"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
long long long long
@@ -3962,6 +3962,17 @@ PASSED:
with message: with message:
oops! oops!
-------------------------------------------------------------------------------
# A test name that starts with a #
-------------------------------------------------------------------------------
MiscTests.cpp:<line number>
...............................................................................
MiscTests.cpp:<line number>:
PASSED:
with message:
yay
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Process can be configured on command line Process can be configured on command line
default - no arguments default - no arguments
@@ -9104,6 +9115,6 @@ with expansion:
1 > 0 1 > 0
=============================================================================== ===============================================================================
test cases: 168 | 123 passed | 43 failed | 2 failed as expected test cases: 169 | 124 passed | 43 failed | 2 failed as expected
assertions: 922 | 824 passed | 80 failed | 18 failed as expected assertions: 923 | 825 passed | 80 failed | 18 failed as expected

View File

@@ -1,5 +1,6 @@
<?xml version="1.1" encoding="UTF-8"?>
<testsuites> <testsuites>
<testsuite name="CatchSelfTest" errors="13" failures="68" tests="923" hostname="tbd" time="{duration}" timestamp="tbd"> <testsuite name="CatchSelfTest" errors="13" failures="68" tests="924" hostname="tbd" time="{duration}" timestamp="tbd">
<testcase classname="global" name="toString(enum)" time="{duration}"/> <testcase classname="global" name="toString(enum)" time="{duration}"/>
<testcase classname="global" name="toString(enum w/operator&lt;&lt;)" time="{duration}"/> <testcase classname="global" name="toString(enum w/operator&lt;&lt;)" time="{duration}"/>
<testcase classname="global" name="toString(enum class)" time="{duration}"/> <testcase classname="global" name="toString(enum class)" time="{duration}"/>
@@ -500,6 +501,7 @@ MiscTests.cpp:<line number>
<testcase classname="XmlEncode" name="string with control char (x7F)" time="{duration}"/> <testcase classname="XmlEncode" name="string with control char (x7F)" time="{duration}"/>
<testcase classname="global" name="long long" time="{duration}"/> <testcase classname="global" name="long long" time="{duration}"/>
<testcase classname="global" name="This test 'should' fail but doesn't" time="{duration}"/> <testcase classname="global" name="This test 'should' fail but doesn't" time="{duration}"/>
<testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="Process can be configured on command line" name="default - no arguments" time="{duration}"/> <testcase classname="Process can be configured on command line" name="default - no arguments" time="{duration}"/>
<testcase classname="Process can be configured on command line" name="test lists/1 test" time="{duration}"/> <testcase classname="Process can be configured on command line" name="test lists/1 test" time="{duration}"/>
<testcase classname="Process can be configured on command line" name="test lists/Specify one test case exclusion using exclude:" time="{duration}"/> <testcase classname="Process can be configured on command line" name="test lists/Specify one test case exclusion using exclude:" time="{duration}"/>

View File

@@ -1,3 +1,4 @@
<?xml version="1.1" encoding="UTF-8"?>
<Catch name="CatchSelfTest"> <Catch name="CatchSelfTest">
<Group name="CatchSelfTest"> <Group name="CatchSelfTest">
<TestCase name="toString(enum)"> <TestCase name="toString(enum)">
@@ -4051,10 +4052,10 @@
<Section name="string with control char (1)"> <Section name="string with control char (1)">
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/MiscTests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/SelfTest/MiscTests.cpp" >
<Original> <Original>
encode( "[\x01]" ) == "[&amp;#x1]" encode( "[\x01]" ) == "[&amp;#x01;]"
</Original> </Original>
<Expanded> <Expanded>
"[&amp;#x1]" == "[&amp;#x1]" "[&amp;#x01;]" == "[&amp;#x01;]"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
@@ -4062,10 +4063,10 @@
<Section name="string with control char (x7F)"> <Section name="string with control char (x7F)">
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/MiscTests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/SelfTest/MiscTests.cpp" >
<Original> <Original>
encode( "[\x7F]" ) == "[&amp;#x7F]" encode( "[\x7F]" ) == "[&amp;#x7F;]"
</Original> </Original>
<Expanded> <Expanded>
"[&amp;#x7F]" == "[&amp;#x7F]" "[&amp;#x7F;]" == "[&amp;#x7F;]"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
@@ -4088,6 +4089,9 @@
<TestCase name="This test 'should' fail but doesn't"> <TestCase name="This test 'should' fail but doesn't">
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="# A test name that starts with a #">
<OverallResult success="true"/>
</TestCase>
<TestCase name="Process can be configured on command line"> <TestCase name="Process can be configured on command line">
<Section name="default - no arguments"> <Section name="default - no arguments">
<Expression success="true" type="CHECK_NOTHROW" filename="projects/SelfTest/TestMain.cpp" > <Expression success="true" type="CHECK_NOTHROW" filename="projects/SelfTest/TestMain.cpp" >
@@ -9566,7 +9570,7 @@ there"
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="824" failures="81" expectedFailures="18"/> <OverallResults successes="825" failures="81" expectedFailures="18"/>
</Group> </Group>
<OverallResults successes="824" failures="80" expectedFailures="18"/> <OverallResults successes="825" failures="80" expectedFailures="18"/>
</Catch> </Catch>

View File

@@ -406,27 +406,27 @@ TEST_CASE( "Tabs and newlines show in output", "[.][whitespace][failing]" ) {
TEST_CASE( "toString on const wchar_t const pointer returns the string contents", "[toString]" ) { TEST_CASE( "toString on const wchar_t const pointer returns the string contents", "[toString]" ) {
const wchar_t * const s = L"wide load"; const wchar_t * const s = L"wide load";
std::string result = Catch::toString( s ); std::string result = Catch::toString( s );
CHECK( result == "\"wide load\"" ); CHECK( result == "\"wide load\"" );
} }
TEST_CASE( "toString on const wchar_t pointer returns the string contents", "[toString]" ) { TEST_CASE( "toString on const wchar_t pointer returns the string contents", "[toString]" ) {
const wchar_t * s = L"wide load"; const wchar_t * s = L"wide load";
std::string result = Catch::toString( s ); std::string result = Catch::toString( s );
CHECK( result == "\"wide load\"" ); CHECK( result == "\"wide load\"" );
} }
TEST_CASE( "toString on wchar_t const pointer returns the string contents", "[toString]" ) { TEST_CASE( "toString on wchar_t const pointer returns the string contents", "[toString]" ) {
wchar_t * const s = const_cast<wchar_t* const>( L"wide load" ); wchar_t * const s = const_cast<wchar_t* const>( L"wide load" );
std::string result = Catch::toString( s ); std::string result = Catch::toString( s );
CHECK( result == "\"wide load\"" ); CHECK( result == "\"wide load\"" );
} }
TEST_CASE( "toString on wchar_t returns the string contents", "[toString]" ) { TEST_CASE( "toString on wchar_t returns the string contents", "[toString]" ) {
wchar_t * s = const_cast<wchar_t*>( L"wide load" ); wchar_t * s = const_cast<wchar_t*>( L"wide load" );
std::string result = Catch::toString( s ); std::string result = Catch::toString( s );
CHECK( result == "\"wide load\"" ); CHECK( result == "\"wide load\"" );
} }
inline std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) { inline std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) {
@@ -458,10 +458,10 @@ TEST_CASE( "XmlEncode" ) {
REQUIRE( encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) == "don't &quot;quote&quot; me on that" ); REQUIRE( encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) == "don't &quot;quote&quot; me on that" );
} }
SECTION( "string with control char (1)" ) { SECTION( "string with control char (1)" ) {
REQUIRE( encode( "[\x01]" ) == "[&#x1]" ); REQUIRE( encode( "[\x01]" ) == "[&#x01;]" );
} }
SECTION( "string with control char (x7F)" ) { SECTION( "string with control char (x7F)" ) {
REQUIRE( encode( "[\x7F]" ) == "[&#x7F]" ); REQUIRE( encode( "[\x7F]" ) == "[&#x7F;]" );
} }
} }
@@ -483,3 +483,7 @@ TEST_CASE( "This test 'should' fail but doesn't", "[.][failing][!shouldfail]" )
{ {
SUCCEED( "oops!" ); SUCCEED( "oops!" );
} }
TEST_CASE( "# A test name that starts with a #" ) {
SUCCEED( "yay" );
}

View File

@@ -1,6 +1,6 @@
/* /*
* Catch v1.5.5 * Catch v1.5.8
* Generated: 2016-06-09 08:17:50.409622 * Generated: 2016-10-26 12:07:30.938259
* ---------------------------------------------------------- * ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly * This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@@ -3223,10 +3223,11 @@ namespace Catch {
bool matches( TestCaseInfo const& testCase ) const { bool matches( TestCaseInfo const& testCase ) const {
// All patterns in a filter must match for the filter to be a match // All patterns in a filter must match for the filter to be a match
for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
if( !(*it)->matches( testCase ) ) if( !(*it)->matches( testCase ) )
return false; return false;
return true; }
return true;
} }
}; };
@@ -4185,7 +4186,7 @@ namespace Clara {
} }
} }
Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
if( std::string( ":=\0", 5 ).find( c ) == std::string::npos ) if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
return mode; return mode;
std::string optName = arg.substr( from, i-from ); std::string optName = arg.substr( from, i-from );
@@ -4199,7 +4200,7 @@ namespace Clara {
return None; return None;
} }
Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
if( inQuotes || std::string( "\0", 3 ).find( c ) == std::string::npos ) if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
return mode; return mode;
std::string data = arg.substr( from, i-from ); std::string data = arg.substr( from, i-from );
@@ -4719,8 +4720,11 @@ namespace Catch {
std::string line; std::string line;
while( std::getline( f, line ) ) { while( std::getline( f, line ) ) {
line = trim(line); line = trim(line);
if( !line.empty() && !startsWith( line, "#" ) ) if( !line.empty() && !startsWith( line, "#" ) ) {
addTestOrTags( config, "\"" + line + "\"," ); if( !startsWith( line, "\"" ) )
line = "\"" + line + "\"";
addTestOrTags( config, line + "," );
}
} }
} }
@@ -5368,7 +5372,10 @@ namespace Catch {
++it ) { ++it ) {
matchedTests++; matchedTests++;
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
Catch::cout() << testCaseInfo.name << std::endl; if( startsWith( testCaseInfo.name, "#" ) )
Catch::cout() << "\"" << testCaseInfo.name << "\"" << std::endl;
else
Catch::cout() << testCaseInfo.name << std::endl;
} }
return matchedTests; return matchedTests;
} }
@@ -6454,7 +6461,7 @@ namespace Catch {
namespace Catch { namespace Catch {
struct RandomNumberGenerator { struct RandomNumberGenerator {
typedef int result_type; typedef std::ptrdiff_t result_type;
result_type operator()( result_type n ) const { return std::rand() % n; } result_type operator()( result_type n ) const { return std::rand() % n; }
@@ -6465,10 +6472,11 @@ namespace Catch {
#endif #endif
template<typename V> template<typename V>
static void shuffle( V& vector ) { static void shuffle( V& vector ) {
RandomNumberGenerator rng;
#ifdef CATCH_CPP14_OR_GREATER #ifdef CATCH_CPP14_OR_GREATER
std::shuffle( vector.begin(), vector.end(), RandomNumberGenerator() ); std::shuffle( vector.begin(), vector.end(), rng );
#else #else
std::random_shuffle( vector.begin(), vector.end(), RandomNumberGenerator() ); std::random_shuffle( vector.begin(), vector.end(), rng );
#endif #endif
} }
}; };
@@ -7570,7 +7578,7 @@ namespace Catch {
return os; return os;
} }
Version libraryVersion( 1, 5, 5, "", 0 ); Version libraryVersion( 1, 5, 8, "", 0 );
} }
@@ -7801,8 +7809,11 @@ namespace Catch {
bool contains( std::string const& s, std::string const& infix ) { bool contains( std::string const& s, std::string const& infix ) {
return s.find( infix ) != std::string::npos; return s.find( infix ) != std::string::npos;
} }
char toLowerCh(char c) {
return static_cast<char>( ::tolower( c ) );
}
void toLowerInPlace( std::string& s ) { void toLowerInPlace( std::string& s ) {
std::transform( s.begin(), s.end(), s.begin(), ::tolower ); std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
} }
std::string toLower( std::string const& s ) { std::string toLower( std::string const& s ) {
std::string lc = s; std::string lc = s;
@@ -8950,9 +8961,10 @@ namespace Catch {
break; break;
default: default:
// Escape control chars - based on contribution by @espenalb in PR #465 // Escape control chars - based on contribution by @espenalb in PR #465 and
// by @mrpi PR #588
if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' )
os << "&#x" << std::uppercase << std::hex << static_cast<int>( c ); os << "&#x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>( c ) << ';';
else else
os << c; os << c;
} }
@@ -9007,13 +9019,20 @@ namespace Catch {
: m_tagIsOpen( false ), : m_tagIsOpen( false ),
m_needsNewline( false ), m_needsNewline( false ),
m_os( &Catch::cout() ) m_os( &Catch::cout() )
{} {
// We encode control characters, which requires
// XML 1.1
// see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
*m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
}
XmlWriter( std::ostream& os ) XmlWriter( std::ostream& os )
: m_tagIsOpen( false ), : m_tagIsOpen( false ),
m_needsNewline( false ), m_needsNewline( false ),
m_os( &os ) m_os( &os )
{} {
*m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
}
~XmlWriter() { ~XmlWriter() {
while( !m_tags.empty() ) while( !m_tags.empty() )
@@ -9180,7 +9199,7 @@ namespace Catch {
virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
StreamingReporterBase::testCaseStarting(testInfo); StreamingReporterBase::testCaseStarting(testInfo);
m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.name );
if ( m_config->showDurations() == ShowDurations::Always ) if ( m_config->showDurations() == ShowDurations::Always )
m_testCaseTimer.start(); m_testCaseTimer.start();
@@ -9242,7 +9261,7 @@ namespace Catch {
.writeText( assertionResult.getMessage() ); .writeText( assertionResult.getMessage() );
break; break;
case ResultWas::FatalErrorCondition: case ResultWas::FatalErrorCondition:
m_xml.scopedElement( "Fatal Error Condition" ) m_xml.scopedElement( "FatalErrorCondition" )
.writeAttribute( "filename", assertionResult.getSourceInfo().file ) .writeAttribute( "filename", assertionResult.getSourceInfo().file )
.writeAttribute( "line", assertionResult.getSourceInfo().line ) .writeAttribute( "line", assertionResult.getSourceInfo().line )
.writeText( assertionResult.getMessage() ); .writeText( assertionResult.getMessage() );