Merge branch 'master' into contrib

This commit is contained in:
coombez
2017-11-21 08:15:03 -06:00
committed by GitHub
16 changed files with 91 additions and 54 deletions

View File

@@ -63,7 +63,7 @@
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
} while( Catch::isTrue( false && static_cast<bool>( !!(__VA_ARGS__) ) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
} while( Catch::isTrue(false) && static_cast<bool>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
///////////////////////////////////////////////////////////////////////////////

View File

@@ -62,7 +62,8 @@ namespace Catch {
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
// This is just here to avoid compiler warnings with macro constants and boolean literals
inline bool isTrue( bool value ) { return value; }
inline bool isTrue( bool value ){ return value; }
bool alwaysTrue();
bool alwaysFalse();

View File

@@ -8,8 +8,6 @@
#include <algorithm>
#include <sstream>
static auto const& defaultExpression = "{Unknown expression after the reported line}";
namespace Catch {
StreamRedirect::StreamRedirect(std::ostream& stream, std::string& targetString)
@@ -129,9 +127,13 @@ namespace Catch {
static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
// Reset working state
m_lastAssertionInfo = { "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}", m_lastAssertionInfo.resultDisposition };
resetAssertionInfo();
m_lastResult = result;
}
void RunContext::resetAssertionInfo() {
m_lastAssertionInfo.macroName = StringRef();
m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr;
}
bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) {
ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo));
@@ -255,8 +257,7 @@ namespace Catch {
void RunContext::assertionPassed() {
++m_totals.assertions.passed;
m_lastAssertionInfo.capturedExpression = StringRef(defaultExpression, sizeof(defaultExpression) - 1);
m_lastAssertionInfo.macroName = StringRef("", 0);
resetAssertionInfo();
}
void RunContext::assertionRun() {
@@ -274,18 +275,19 @@ namespace Catch {
Counts prevAssertions = m_totals.assertions;
double duration = 0;
m_shouldReportUnexpected = true;
m_lastAssertionInfo = { "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal };
seedRng(*m_config);
Timer timer;
try {
m_lastAssertionInfo = { "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal };
seedRng(*m_config);
Timer timer;
timer.start();
if (m_reporter->getPreferences().shouldRedirectStdOut) {
StreamRedirect coutRedir(cout(), redirectedCout);
StdErrRedirect errRedir(redirectedCerr);
timer.start();
invokeActiveTestCase();
} else {
timer.start();
invokeActiveTestCase();
}
duration = timer.getElapsedSeconds();

View File

@@ -116,6 +116,8 @@ namespace Catch {
void runCurrentTest(std::string& redirectedCout, std::string& redirectedCerr);
void invokeActiveTestCase();
void resetAssertionInfo();
private:
void handleUnfinishedSections();

View File

@@ -14,8 +14,12 @@
#include "catch_stringref.h"
#include <ostream>
#include <cstring>
namespace Catch {
StringRef::StringRef( char const* rawChars ) noexcept
: StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
{}
StringRef::operator std::string() const {
return std::string( m_start, m_size );

View File

@@ -10,8 +10,6 @@
#include <cstddef>
#include <string>
#include <iosfwd>
#include <cassert>
#include <cstring>
namespace Catch {
@@ -25,10 +23,12 @@ namespace Catch {
/// visible - but it does mean (substring) StringRefs should not be shared between
/// threads.
class StringRef {
public:
using size_type = std::size_t;
private:
friend struct StringRefTestAccess;
using size_type = std::size_t;
char const* m_start;
size_type m_size;
@@ -56,12 +56,7 @@ namespace Catch {
other.m_data = nullptr;
}
StringRef( char const* rawChars ) noexcept
: m_start( rawChars ),
m_size( static_cast<size_type>(std::strlen(rawChars)))
{
assert( rawChars );
}
StringRef( char const* rawChars ) noexcept;
StringRef( char const* rawChars, size_type size ) noexcept
: m_start( rawChars ),
@@ -121,6 +116,10 @@ namespace Catch {
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
return StringRef( rawChars, size );
}
} // namespace Catch
#endif // CATCH_STRINGREF_H_INCLUDED

View File

@@ -35,7 +35,7 @@ auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
}
struct NameAndTags {
NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) noexcept;
NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept;
StringRef name;
StringRef tags;
};

View File

@@ -12,6 +12,10 @@
# pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
// Enable specific decls locally
#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
#endif
#include "catch_tostring.h"
#include "catch_interfaces_config.h"
@@ -221,6 +225,13 @@ std::string StringMaker<double>::convert(double value) {
return fpToString(value, 10);
}
std::string ratio_string<std::atto>::symbol() { return "a"; }
std::string ratio_string<std::femto>::symbol() { return "f"; }
std::string ratio_string<std::pico>::symbol() { return "p"; }
std::string ratio_string<std::nano>::symbol() { return "n"; }
std::string ratio_string<std::micro>::symbol() { return "u"; }
std::string ratio_string<std::milli>::symbol() { return "m"; }
} // end namespace Catch

View File

@@ -26,7 +26,7 @@
// We need a dummy global operator<< so we can bring it into Catch namespace later
struct Catch_global_namespace_dummy;
struct Catch_global_namespace_dummy {};
std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
namespace Catch {
@@ -351,6 +351,9 @@ namespace Catch {
#include <ratio>
#include <chrono>
namespace Catch {
template <class Ratio>
struct ratio_string {
static std::string symbol();
@@ -365,30 +368,29 @@ std::string ratio_string<Ratio>::symbol() {
}
template <>
struct ratio_string<std::atto> {
static std::string symbol() { return "a"; }
static std::string symbol();
};
template <>
struct ratio_string<std::femto> {
static std::string symbol() { return "f"; }
static std::string symbol();
};
template <>
struct ratio_string<std::pico> {
static std::string symbol() { return "p"; }
static std::string symbol();
};
template <>
struct ratio_string<std::nano> {
static std::string symbol() { return "n"; }
static std::string symbol();
};
template <>
struct ratio_string<std::micro> {
static std::string symbol() { return "u"; }
static std::string symbol();
};
template <>
struct ratio_string<std::milli> {
static std::string symbol() { return "m"; }
static std::string symbol();
};
namespace Catch {
////////////
// std::chrono::duration specializations
template<typename Value, typename Ratio>

View File

@@ -0,0 +1,18 @@
/*
* Created by Martin on 21/11/2017.
*
* This file collects declaration that we want to expose to test files.
* These declarations are expected to be duplicated elsewhere,
* together with their implementation.
*
* 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)
*/
#ifndef TWOBLUECUBES_CATCH_USER_INTERFACES_H_INCLUDED
#define TWOBLUECUBES_CATCH_USER_INTERFACES_H_INCLUDED
namespace Catch {
unsigned int rngSeed();
}
#endif // TWOBLUECUBES_CATCH_USER_INTERFACES_H_INCLUDED