mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Moved inline functions in cpp files into anon namespaces
This commit is contained in:
parent
504607701b
commit
b8553d62a3
@ -18,9 +18,11 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
inline auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
|
namespace {
|
||||||
expr.streamReconstructedExpression( os );
|
auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
|
||||||
return os;
|
expr.streamReconstructedExpression( os );
|
||||||
|
return os;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyExpression::LazyExpression( bool isNegated )
|
LazyExpression::LazyExpression( bool isNegated )
|
||||||
|
@ -14,6 +14,12 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
char toLowerCh(char c) {
|
||||||
|
return static_cast<char>( std::tolower( c ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool startsWith( std::string const& s, std::string const& prefix ) {
|
bool startsWith( std::string const& s, std::string const& prefix ) {
|
||||||
return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
|
return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
|
||||||
}
|
}
|
||||||
@ -29,9 +35,6 @@ 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;
|
||||||
}
|
}
|
||||||
inline char toLowerCh(char c) {
|
|
||||||
return static_cast<char>( std::tolower( c ) );
|
|
||||||
}
|
|
||||||
void toLowerInPlace( std::string& s ) {
|
void toLowerInPlace( std::string& s ) {
|
||||||
std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
|
std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
|
||||||
}
|
}
|
||||||
|
@ -19,31 +19,33 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
|
namespace {
|
||||||
if( startsWith( tag, '.' ) ||
|
TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
|
||||||
tag == "!hide" )
|
if( startsWith( tag, '.' ) ||
|
||||||
return TestCaseInfo::IsHidden;
|
tag == "!hide" )
|
||||||
else if( tag == "!throws" )
|
return TestCaseInfo::IsHidden;
|
||||||
return TestCaseInfo::Throws;
|
else if( tag == "!throws" )
|
||||||
else if( tag == "!shouldfail" )
|
return TestCaseInfo::Throws;
|
||||||
return TestCaseInfo::ShouldFail;
|
else if( tag == "!shouldfail" )
|
||||||
else if( tag == "!mayfail" )
|
return TestCaseInfo::ShouldFail;
|
||||||
return TestCaseInfo::MayFail;
|
else if( tag == "!mayfail" )
|
||||||
else if( tag == "!nonportable" )
|
return TestCaseInfo::MayFail;
|
||||||
return TestCaseInfo::NonPortable;
|
else if( tag == "!nonportable" )
|
||||||
else if( tag == "!benchmark" )
|
return TestCaseInfo::NonPortable;
|
||||||
return static_cast<TestCaseInfo::SpecialProperties>( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden );
|
else if( tag == "!benchmark" )
|
||||||
else
|
return static_cast<TestCaseInfo::SpecialProperties>( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden );
|
||||||
return TestCaseInfo::None;
|
else
|
||||||
}
|
return TestCaseInfo::None;
|
||||||
inline bool isReservedTag( std::string const& tag ) {
|
}
|
||||||
return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( static_cast<unsigned char>(tag[0]) );
|
bool isReservedTag( std::string const& tag ) {
|
||||||
}
|
return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( static_cast<unsigned char>(tag[0]) );
|
||||||
inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
|
}
|
||||||
CATCH_ENFORCE( !isReservedTag(tag),
|
void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
|
||||||
"Tag name: [" << tag << "] is not allowed.\n"
|
CATCH_ENFORCE( !isReservedTag(tag),
|
||||||
<< "Tag names starting with non alpha-numeric characters are reserved\n"
|
"Tag name: [" << tag << "] is not allowed.\n"
|
||||||
<< _lineInfo );
|
<< "Tag names starting with non alpha-numeric characters are reserved\n"
|
||||||
|
<< _lineInfo );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase makeTestCase( ITestInvoker* _testCase,
|
TestCase makeTestCase( ITestInvoker* _testCase,
|
||||||
|
@ -18,34 +18,36 @@ namespace Catch {
|
|||||||
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto estimateClockResolution() -> uint64_t {
|
namespace {
|
||||||
uint64_t sum = 0;
|
auto estimateClockResolution() -> uint64_t {
|
||||||
static const uint64_t iterations = 1000000;
|
uint64_t sum = 0;
|
||||||
|
static const uint64_t iterations = 1000000;
|
||||||
|
|
||||||
auto startTime = getCurrentNanosecondsSinceEpoch();
|
auto startTime = getCurrentNanosecondsSinceEpoch();
|
||||||
|
|
||||||
for( std::size_t i = 0; i < iterations; ++i ) {
|
for( std::size_t i = 0; i < iterations; ++i ) {
|
||||||
|
|
||||||
uint64_t ticks;
|
uint64_t ticks;
|
||||||
uint64_t baseTicks = getCurrentNanosecondsSinceEpoch();
|
uint64_t baseTicks = getCurrentNanosecondsSinceEpoch();
|
||||||
do {
|
do {
|
||||||
ticks = getCurrentNanosecondsSinceEpoch();
|
ticks = getCurrentNanosecondsSinceEpoch();
|
||||||
} while( ticks == baseTicks );
|
} while( ticks == baseTicks );
|
||||||
|
|
||||||
auto delta = ticks - baseTicks;
|
auto delta = ticks - baseTicks;
|
||||||
sum += delta;
|
sum += delta;
|
||||||
|
|
||||||
// If we have been calibrating for over 3 seconds -- the clock
|
// If we have been calibrating for over 3 seconds -- the clock
|
||||||
// is terrible and we should move on.
|
// is terrible and we should move on.
|
||||||
// TBD: How to signal that the measured resolution is probably wrong?
|
// TBD: How to signal that the measured resolution is probably wrong?
|
||||||
if (ticks > startTime + 3 * nanosecondsInSecond) {
|
if (ticks > startTime + 3 * nanosecondsInSecond) {
|
||||||
return sum / i;
|
return sum / i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// We're just taking the mean, here. To do better we could take the std. dev and exclude outliers
|
// We're just taking the mean, here. To do better we could take the std. dev and exclude outliers
|
||||||
// - and potentially do more iterations if there's a high variance.
|
// - and potentially do more iterations if there's a high variance.
|
||||||
return sum/iterations;
|
return sum/iterations;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto getEstimatedClockResolution() -> uint64_t {
|
auto getEstimatedClockResolution() -> uint64_t {
|
||||||
static auto s_resolution = estimateClockResolution();
|
static auto s_resolution = estimateClockResolution();
|
||||||
|
Loading…
Reference in New Issue
Block a user