mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-29 16:09:30 +00:00
All tests files have .tests.cpp suffix. Also moved tests out of TestMain.cpp and moved up a level
This commit is contained in:
parent
e34754e433
commit
74d3dfd4cc
32 changed files with 3323 additions and 3322 deletions
73
projects/SelfTest/UsageTests/ToStringWhich.tests.cpp
Normal file
73
projects/SelfTest/UsageTests/ToStringWhich.tests.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "catch.hpp"
|
||||
/*
|
||||
Demonstrate which version of toString/StringMaker is being used
|
||||
for various types
|
||||
*/
|
||||
|
||||
|
||||
struct has_operator { };
|
||||
struct has_maker {};
|
||||
struct has_maker_and_operator {};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const has_operator&) {
|
||||
os << "operator<<( has_operator )";
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const has_maker_and_operator&) {
|
||||
os << "operator<<( has_maker_and_operator )";
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace Catch {
|
||||
template<>
|
||||
struct StringMaker<has_maker> {
|
||||
static std::string convert( const has_maker& ) {
|
||||
return "StringMaker<has_maker>";
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<has_maker_and_operator> {
|
||||
static std::string convert( const has_maker_and_operator& ) {
|
||||
return "StringMaker<has_maker_and_operator>";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Call the operator
|
||||
TEST_CASE( "stringify( has_operator )", "[toString]" ) {
|
||||
has_operator item;
|
||||
REQUIRE( ::Catch::Detail::stringify( item ) == "operator<<( has_operator )" );
|
||||
}
|
||||
|
||||
// Call the stringmaker
|
||||
TEST_CASE( "stringify( has_maker )", "[toString]" ) {
|
||||
has_maker item;
|
||||
REQUIRE( ::Catch::Detail::stringify( item ) == "StringMaker<has_maker>" );
|
||||
}
|
||||
|
||||
// Call the stringmaker
|
||||
TEST_CASE( "stringify( has_maker_and_toString )", "[.][toString]" ) {
|
||||
has_maker_and_operator item;
|
||||
REQUIRE( ::Catch::Detail::stringify( item ) == "StringMaker<has_maker_and_operator>" );
|
||||
}
|
||||
|
||||
// Vectors...
|
||||
|
||||
// Don't run this in approval tests as it is sensitive to two phase lookup differences
|
||||
TEST_CASE( "toString( vectors<has_toString )", "[.][toString][!nonportable]" ) {
|
||||
std::vector<has_operator> v(1);
|
||||
REQUIRE( ::Catch::Detail::stringify( v ) == "{ operator<<( has_operator ) }" );
|
||||
}
|
||||
|
||||
TEST_CASE( "toString( vectors<has_maker )", "[toString]" ) {
|
||||
std::vector<has_maker> v(1);
|
||||
REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" );
|
||||
}
|
||||
|
||||
|
||||
// Don't run this in approval tests as it is sensitive to two phase lookup differences
|
||||
TEST_CASE( "toString( vectors<has_maker_and_toString )", "[.][toString][!nonportable]" ) {
|
||||
std::vector<has_maker_and_operator> v(1);
|
||||
REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker_and_toString> }" );
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue