Lines Matching defs:std

187 // Android somehow still does not support std::to_string
212 // some versions of cygwin (most) do not support std::to_string. Use the libstd check.
459 std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
482 SourceLineInfo( char const* _file, std::size_t _line ) noexcept
497 std::size_t line;
500 std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
512 std::string operator+() const;
521 ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
559 virtual std::vector<TestCase> const& getAllTests() const = 0;
560 virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
565 std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
566 std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
580 /// A non-owning string class (similar to the forthcoming std::string_view)
585 using size_type = std::size_t;
604 StringRef( std::string const& stdString ) noexcept
609 explicit operator std::string() const {
610 return std::string(m_start, m_size);
633 // null-terminated, throws std::domain_exception
654 auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
655 auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
657 constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
662 constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
902 struct always_false : std::false_type {};
904 template <typename> struct true_given : std::true_type {};
907 true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
909 std::false_type static test(...);
919 // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
920 // replaced with std::invoke_result here. Also *_t format is preferred over
923 using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>;
926 using FunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U)>::type>::type>::type;
954 return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod );
1081 (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++, 0)... };/* NOLINT */ \
1127 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++, 0)... };/* NOLINT */\
1171 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++, 0)... };/* NOLINT */\
1205 (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++, 0)... };/* NOLINT */ \
1254 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++, 0)... };/* NOLINT */ \
1301 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++, 0)... };/* NOLINT */ \
1404 std::ostream& cout();
1405 std::ostream& cerr();
1406 std::ostream& clog();
1412 virtual std::ostream& stream() const = 0;
1418 std::size_t m_index;
1419 std::ostream* m_oss;
1424 auto str() const -> std::string;
1431 auto get() -> std::ostream& { return *m_oss; }
1445 std::vector<std::pair<int, StringRef>> m_values;
1456 virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
1459 Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
1461 std::vector<int> intValues;
1531 extern const std::string unprintableString;
1533 std::string rawMemoryToString( const void *object, std::size_t size );
1536 std::string rawMemoryToString( const T& object ) {
1544 -> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type());
1547 static auto test(...)->std::false_type;
1550 static const bool value = decltype(test<std::ostream, const T&>(0))::value;
1554 std::string convertUnknownEnumToString( E e );
1557 typename std::enable_if<
1558 !std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value,
1559 std::string>::type convertUnstreamable( T const& ) {
1563 typename std::enable_if<
1564 !std::is_enum<T>::value && std::is_base_of<std::exception, T>::value,
1565 std::string>::type convertUnstreamable(T const& ex) {
1570 typename std::enable_if<
1571 std::is_enum<T>::value
1572 , std::string>::type convertUnstreamable( T const& value ) {
1577 //! Convert a CLR string to a utf8 std::string
1579 std::string clrReferenceToString( T^ ref ) {
1581 return std::string("null");
1584 return std::string(reinterpret_cast<char const *>(p), bytes->Length);
1595 typename std::enable_if<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
1606 typename std::enable_if<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
1621 std::string stringify(const T& e) {
1622 return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
1626 std::string convertUnknownEnumToString( E e ) {
1627 return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<E>::type>(e));
1632 std::string stringify( T^ e ) {
1642 struct StringMaker<std::string> {
1643 static std::string convert(const std::string& str);
1648 struct StringMaker<std::string_view> {
1649 static std::string convert(std::string_view str);
1655 static std::string convert(char const * str);
1659 static std::string convert(char * str);
1664 struct StringMaker<std::wstring> {
1665 static std::string convert(const std::wstring& wstr);
1670 struct StringMaker<std::wstring_view> {
1671 static std::string convert(std::wstring_view str);
1677 static std::string convert(wchar_t const * str);
1681 static std::string convert(wchar_t * str);
1689 static std::string convert(char const* str) {
1690 return ::Catch::Detail::stringify(std::string{ str });
1695 static std::string convert(signed char const* str) {
1696 return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
1701 static std::string convert(unsigned char const* str) {
1702 return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
1708 struct StringMaker<std::byte> {
1709 static std::string convert(std::byte value);
1714 static std::string convert(int value);
1718 static std::string convert(long value);
1722 static std::string convert(long long value);
1726 static std::string convert(unsigned int value);
1730 static std::string convert(unsigned long value);
1734 static std::string convert(unsigned long long value);
1739 static std::string convert(bool b);
1744 static std::string convert(char c);
1748 static std::string convert(signed char c);
1752 static std::string convert(unsigned char c);
1756 struct StringMaker<std::nullptr_t> {
1757 static std::string convert(std::nullptr_t);
1762 static std::string convert(float value);
1768 static std::string convert(double value);
1775 static std::string convert(U* p) {
1786 static std::string convert(R C::* p) {
1798 static std::string convert( T^ ref ) {
1806 std::string rangeToString(InputIterator first, InputIterator last) {
1822 static std::string convert(NSString * nsstring) {
1825 return std::string("@") + [nsstring UTF8String];
1830 static std::string convert(NSObject* nsObject) {
1836 inline std::string stringify( NSString* nsstring ) {
1846 // Separate std-lib types stringification, so it can be selectively enabled
1857 // Separate std::pair specialization
1862 struct StringMaker<std::pair<T1, T2> > {
1863 static std::string convert(const std::pair<T1, T2>& pair) {
1880 struct StringMaker<std::optional<T> > {
1881 static std::string convert(const std::optional<T>& optional) {
1894 // Separate std::tuple specialization
1901 std::size_t N = 0,
1902 bool = (N < std::tuple_size<Tuple>::value)
1905 static void print(const Tuple& tuple, std::ostream& os) {
1907 << ::Catch::Detail::stringify(std::get<N>(tuple));
1914 std::size_t N
1917 static void print(const Tuple&, std::ostream&) {}
1923 struct StringMaker<std::tuple<Types...>> {
1924 static std::string convert(const std::tuple<Types...>& tuple) {
1927 Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
1939 struct StringMaker<std::monostate> {
1940 static std::string convert(const std::monostate&) {
1946 struct StringMaker<std::variant<Elements...>> {
1947 static std::string convert(const std::variant<Elements...>& variant) {
1951 return std::visit(
1966 // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace
1967 using std::begin;
1968 using std::end;
1976 !std::is_same<decltype(begin(std::declval<T>())), not_this_one>::value &&
1977 !std::is_same<decltype(end(std::declval<T>())), not_this_one>::value;
1988 std::string rangeToString( Range const& range ) {
1994 std::string rangeToString( std::vector<bool, Allocator> const& v ) {
2010 struct StringMaker<R, typename std::enable_if<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>::type> {
2011 static std::string convert( R const& range ) {
2018 static std::string convert(T const(&arr)[SZ]) {
2025 // Separate std::chrono::duration specialization
2035 static std::string symbol();
2039 std::string ratio_string<Ratio>::symbol() {
2046 struct ratio_string<std::atto> {
2047 static std::string symbol();
2050 struct ratio_string<std::femto> {
2051 static std::string symbol();
2054 struct ratio_string<std::pico> {
2055 static std::string symbol();
2058 struct ratio_string<std::nano> {
2059 static std::string symbol();
2062 struct ratio_string<std::micro> {
2063 static std::string symbol();
2066 struct ratio_string<std::milli> {
2067 static std::string symbol();
2071 // std::chrono::duration specializations
2073 struct StringMaker<std::chrono::duration<Value, Ratio>> {
2074 static std::string convert(std::chrono::duration<Value, Ratio> const& duration) {
2081 struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> {
2082 static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) {
2089 struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> {
2090 static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) {
2097 struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> {
2098 static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) {
2106 // std::chrono::time_point specialization
2107 // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock>
2109 struct StringMaker<std::chrono::time_point<Clock, Duration>> {
2110 static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) {
2114 // std::chrono::time_point<system_clock> specialization
2116 struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
2117 static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
2118 auto converted = std::chrono::system_clock::to_time_t(time_point);
2121 std::tm timeInfo = {};
2124 std::tm* timeInfo = std::gmtime(&converted);
2132 std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
2134 std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
2136 return std::string(timeStamp);
2145 static std::string convert( enumName value ) { \
2147 return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \
2175 virtual void streamReconstructedExpression( std::ostream &os ) const = 0;
2191 void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
2199 void streamReconstructedExpression( std::ostream &os ) const override {
2273 void streamReconstructedExpression( std::ostream &os ) const override {
2412 template <typename Duration = std::chrono::duration<double, std::nano>>
2428 virtual void benchmarkPreparing( std::string const& name ) = 0;
2431 virtual void benchmarkFailed( std::string const& error ) = 0;
2455 std::string const& message,
2468 virtual std::string getCurrentTestName() const = 0;
2498 friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
2545 void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString );
2563 std::string message;
2611 std::vector<MessageInfo> m_messages;
2618 void captureValue( size_t index, std::string const& value );
2791 std::size_t total() const;
2795 std::size_t passed = 0;
2796 std::size_t failed = 0;
2797 std::size_t failedButOk = 0;
2821 std::string const& _name );
2826 std::string const& _name,
2827 std::string const& ) : SectionInfo( _lineInfo, _name ) {}
2829 std::string name;
2830 std::string description; // !Deprecated: this will always be empty
2880 std::string m_name;
2921 using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
2936 virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0;
2940 virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
2948 std::string translateActiveException();
2955 static std::string translatorName( signature )
2963 using exceptionTranslateFunction = std::string(*)();
2966 using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
2970 virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
2976 virtual std::string translateActiveException() const = 0;
2984 ExceptionTranslator( std::string(*translateFunction)( T& ) )
2988 std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
2991 std::rethrow_exception(std::current_exception());
3001 std::string(*m_translateFunction)( T& );
3006 ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
3015 static std::string translatorName( signature ); \
3020 static std::string translatorName( signature )
3049 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3058 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3062 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3068 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3073 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3078 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3083 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3088 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3093 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3098 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3103 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3110 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3117 template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3123 std::string toString() const;
3140 static std::string convert(Catch::Detail::Approx const& value);
3154 bool startsWith( std::string const& s, std::string const& prefix );
3155 bool startsWith( std::string const& s, char prefix );
3156 bool endsWith( std::string const& s, std::string const& suffix );
3157 bool endsWith( std::string const& s, char suffix );
3158 bool contains( std::string const& s, std::string const& infix );
3159 void toLowerInPlace( std::string& s );
3160 std::string toLower( std::string const& s );
3162 std::string trim( std::string const& str );
3167 std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
3168 bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
3171 pluralise( std::size_t count, std::string const& label );
3173 friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
3175 std::size_t m_count;
3176 std::string m_label;
3202 std::string toString() const;
3206 virtual std::string describe() const = 0;
3207 mutable std::string m_cachedToString;
3250 std::string describe() const override {
3251 std::string description;
3271 std::vector<MatcherBase<ArgT> const*> m_matchers;
3283 std::string describe() const override {
3284 std::string description;
3304 std::vector<MatcherBase<ArgT> const*> m_matchers;
3316 std::string describe() const override {
3351 class ExceptionMessageMatcher : public MatcherBase<std::exception> {
3352 std::string m_message;
3355 ExceptionMessageMatcher(std::string const& message):
3359 bool match(std::exception const& ex) const override;
3361 std::string describe() const override;
3366 Exception::ExceptionMessageMatcher Message(std::string const& message);
3384 std::string describe() const override;
3393 std::string describe() const override;
3409 std::string describe() const override;
3443 std::string finalizeDescription(const std::string& desc);
3448 std::function<bool(T const&)> m_predicate;
3449 std::string m_description;
3452 PredicateMatcher(std::function<bool(T const&)> const& elem, std::string const& descr)
3453 :m_predicate(std::move(elem)),
3461 std::string describe() const override {
3470 // inferring std::function<bool(T const&)> is hard (but possible) and
3473 Generic::PredicateMatcher<T> Predicate(std::function<bool(T const&)> const& predicate, std::string const& description = "") {
3492 CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
3493 std::string adjustString( std::string const& str ) const;
3494 std::string caseSensitivitySuffix() const;
3497 std::string m_str;
3500 struct StringMatcherBase : MatcherBase<std::string> {
3501 StringMatcherBase( std::string const& operation, CasedString const& comparator );
3502 std::string describe() const override;
3505 std::string m_operation;
3510 bool match( std::string const& source ) const override;
3514 bool match( std::string const& source ) const override;
3518 bool match( std::string const& source ) const override;
3522 bool match( std::string const& source ) const override;
3525 struct RegexMatcher : MatcherBase<std::string> {
3526 RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
3527 bool match( std::string const& matchee ) const override;
3528 std::string describe() const override;
3531 std::string m_regex;
3540 StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
3541 StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
3542 StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
3543 StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
3544 StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
3559 struct ContainsElementMatcher : MatcherBase<std::vector<T>> {
3563 bool match(std::vector<T> const &v) const override {
3572 std::string describe() const override {
3580 struct ContainsMatcher : MatcherBase<std::vector<T>> {
3582 ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
3584 bool match(std::vector<T> const &v) const override {
3602 std::string describe() const override {
3606 std::vector<T> const& m_comparator;
3610 struct EqualsMatcher : MatcherBase<std::vector<T>> {
3612 EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
3614 bool match(std::vector<T> const &v) const override {
3617 // to using !=. but could be specialised for, e.g. std::vector<T> etc
3621 for (std::size_t i = 0; i < v.size(); ++i)
3626 std::string describe() const override {
3629 std::vector<T> const& m_comparator;
3633 struct ApproxMatcher : MatcherBase<std::vector<T>> {
3635 ApproxMatcher(std::vector<T> const& comparator) : m_comparator( comparator ) {}
3637 bool match(std::vector<T> const &v) const override {
3640 for (std::size_t i = 0; i < v.size(); ++i)
3645 std::string describe() const override {
3648 template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3653 template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3658 template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
3664 std::vector<T> const& m_comparator;
3669 struct UnorderedEqualsMatcher : MatcherBase<std::vector<T>> {
3670 UnorderedEqualsMatcher(std::vector<T> const& target) : m_target(target) {}
3671 bool match(std::vector<T> const& vec) const override {
3672 // Note: This is a reimplementation of std::is_permutation,
3677 return std::is_permutation(m_target.begin(), m_target.end(), vec.begin());
3680 std::string describe() const override {
3684 std::vector<T> const& m_target;
3693 Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) {
3703 Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) {
3708 Vector::ApproxMatcher<T> Approx( std::vector<T> const& comparator ) {
3713 Vector::UnorderedEqualsMatcher<T> UnorderedEquals(std::vector<T> const& target) {
3736 void streamReconstructedExpression( std::ostream &os ) const override {
3746 using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
3809 using GeneratorBasePtr = std::unique_ptr<GeneratorUntypedBase>;
3836 void throw_exception(std::exception const& e);
3840 void throw_logic_error(std::string const& msg);
3842 void throw_domain_error(std::string const& msg);
3844 void throw_runtime_error(std::string const& msg);
3873 class GeneratorException : public std::exception {
3889 std::unique_ptr<T> make_unique( Args&&... args ) {
3890 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
3911 SingleValueGenerator(T&& value) : m_value(std::move(value)) {}
3923 static_assert(!std::is_same<T, bool>::value,
3924 "FixedValuesGenerator does not support bools because of std::vector<bool>"
3926 std::vector<T> m_values;
3929 FixedValuesGenerator( std::initializer_list<T> values ) : m_values( values ) {}
3942 std::unique_ptr<IGenerator<T>> m_generator;
3944 GeneratorWrapper(std::unique_ptr<IGenerator<T>> generator):
3945 m_generator(std::move(generator))
3957 return GeneratorWrapper<T>(pf::make_unique<SingleValueGenerator<T>>(std::forward<T>(value)));
3960 GeneratorWrapper<T> values(std::initializer_list<T> values) {
3966 std::vector<GeneratorWrapper<T>> m_generators;
3970 m_generators.emplace_back(std::move(generator));
3973 m_generators.emplace_back(value(std::move(val)));
3977 populate(T(std::move(val)));
3981 populate(std::forward<U>(valueOrGenerator));
3982 populate(std::forward<Gs>(moreGenerators)...);
3989 populate(std::forward<Gs>(moreGenerators)...);
4009 GeneratorWrapper<std::tuple<Ts...>> table( std::initializer_list<std::tuple<typename std::decay<Ts>::type...>> tuples ) {
4010 return values<std::tuple<Ts...>>( tuples );
4019 return Generators<T>(std::move(generator), std::forward<Gs>(moreGenerators)...);
4023 return Generators<T>(std::move(generator));
4027 return makeGenerators( value( std::forward<T>( val ) ), std::forward<Gs>( moreGenerators )... );
4031 return makeGenerators( value( T( std::forward<U>( val ) ) ), std::forward<Gs>( moreGenerators )... );
4040 auto generate( SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval<decltype(generatorExpression())>().get()) {
4075 m_generator(std::move(generator)),
4101 return GeneratorWrapper<T>(pf::make_unique<TakeGenerator<T>>(target, std::move(generator)));
4111 m_generator(std::move(generator)),
4112 m_predicate(std::forward<P>(pred))
4140 return GeneratorWrapper<T>(std::unique_ptr<IGenerator<T>>(pf::make_unique<FilterGenerator<T, Predicate>>(std::forward<Predicate>(pred), std::move(generator))));
4145 static_assert(!std::is_same<T, bool>::value,
4147 "because of std::vector<bool> specialization");
4149 mutable std::vector<T> m_returned;
4155 m_generator(std::move(generator)),
4196 return GeneratorWrapper<T>(pf::make_unique<RepeatGenerator<T>>(repeats, std::move(generator)));
4209 m_generator(std::move(generator)),
4210 m_function(std::forward<F2>(function)),
4229 pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
4236 pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
4241 class ChunkGenerator final : public IGenerator<std::vector<T>> {
4242 std::vector<T> m_chunk;
4248 m_chunk_size(size), m_generator(std::move(generator))
4261 std::vector<T> const& get() const override {
4277 GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) {
4278 return GeneratorWrapper<std::vector<T>>(
4279 pf::make_unique<ChunkGenerator<T>>(size, std::move(generator))
4300 using IConfigPtr = std::shared_ptr<IConfig const>;
4460 virtual std::ostream& stream() const = 0;
4461 virtual std::string name() const = 0;
4471 virtual std::vector<std::string> const& getTestsOrTags() const = 0;
4475 virtual std::vector<std::string> const& getSectionsToRun() const = 0;
4484 using IConfigPtr = std::shared_ptr<IConfig const>;
4500 using state_type = std::uint64_t;
4502 using result_type = std::uint32_t;
4527 std::uint64_t m_state;
4532 static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL;
4546 std::uniform_real_distribution<Float> m_dist;
4568 std::uniform_int_distribution<Integer> m_dist;
4590 typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value,
4599 typename std::enable_if<std::is_floating_point<T>::value,
4642 static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric");
4648 static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer");
4654 static_assert(!std::is_same<T, bool>::value,
4656 "because of std::vector<bool> specialization");
4658 std::vector<T> m_elems;
4680 typename ResultType = typename std::iterator_traits<InputIterator>::value_type>
4724 TestCaseInfo( std::string const& _name,
4725 std::string const& _className,
4726 std::string const& _description,
4727 std::vector<std::string> const& _tags,
4730 friend void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags );
4737 std::string tagsAsString() const;
4739 std::string name;
4740 std::string className;
4741 std::string description;
4742 std::vector<std::string> tags;
4743 std::vector<std::string> lcaseTags;
4753 TestCase withName( std::string const& _newName ) const;
4763 std::shared_ptr<ITestInvoker> test;
4767 std::string const& className,
4837 inline std::string getAnnotation( Class cls,
4838 std::string const& annotationName,
4839 std::string const& testCaseName ) {
4850 inline std::size_t registerTestMethods() {
4851 std::size_t noTestMethods = 0;
4864 std::string methodName = sel_getName(selector);
4866 std::string testCaseName = methodName.substr( 15 );
4867 std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
4868 std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
4909 std::string describe() const override {
4922 std::string describe() const override {
4935 std::string describe() const override {
4947 std::string describe() const override {
5031 WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity );
5033 virtual bool matches( std::string const& str ) const;
5036 std::string normaliseString( std::string const& str ) const;
5039 std::string m_pattern;
5055 explicit Pattern( std::string const& name );
5058 std::string const& name() const;
5060 std::string const m_name;
5062 using PatternPtr = std::shared_ptr<Pattern>;
5066 explicit NamePattern( std::string const& name, std::string const& filterString );
5074 explicit TagPattern( std::string const& tag, std::string const& filterString );
5077 std::string m_tag;
5089 std::vector<PatternPtr> m_patterns;
5092 std::string name() const;
5097 std::string name;
5098 std::vector<TestCase const*> tests;
5100 using Matches = std::vector<FilterMatch>;
5101 using vectorStrings = std::vector<std::string>;
5105 Matches matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const;
5109 std::vector<Filter> m_filters;
5110 std::vector<std::string> m_invalidArgs;
5131 virtual TagAlias const* find( std::string const& alias ) const = 0;
5132 virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
5147 std::size_t m_pos = 0;
5148 std::size_t m_realPatternPos = 0;
5149 std::string m_arg;
5150 std::string m_substring;
5151 std::string m_patternName;
5152 std::vector<std::size_t> m_escapeChars;
5160 TestSpecParser& parse( std::string const& arg );
5178 std::string preprocessPattern();
5191 TestSpec parseTestSpec( std::string const& arg );
5243 std::string outputFilename;
5244 std::string name;
5245 std::string processName;
5249 std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER;
5252 std::vector<std::string> testsOrTags;
5253 std::vector<std::string> sectionsToRun;
5263 std::string const& getFilename() const;
5270 std::string getProcessName() const;
5271 std::string const& getReporterName() const;
5273 std::vector<std::string> const& getTestsOrTags() const override;
5274 std::vector<std::string> const& getSectionsToRun() const override;
5283 std::ostream& stream() const override;
5284 std::string name() const override;
5306 std::unique_ptr<IStream const> m_stream;
5326 std::string message;
5327 mutable std::string reconstructedExpression;
5331 std::string reconstructExpression() const;
5344 std::string getExpression() const;
5345 std::string getExpressionInMacro() const;
5347 std::string getExpandedExpression() const;
5348 std::string getMessage() const;
5419 ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
5421 std::ostream& stream() const;
5425 std::ostream* m_stream;
5449 TestRunInfo( std::string const& _name );
5450 std::string name;
5453 GroupInfo( std::string const& _name,
5454 std::size_t _groupIndex,
5455 std::size_t _groupsCount );
5457 std::string name;
5458 std::size_t groupIndex;
5459 std::size_t groupsCounts;
5464 std::vector<MessageInfo> const& _infoMessages,
5474 std::vector<MessageInfo> infoMessages;
5498 std::string const& _stdOut,
5499 std::string const& _stdErr,
5510 std::string stdOut;
5511 std::string stdErr;
5550 std::string name;
5563 std::vector<Duration> samples;
5571 std::vector<Duration2> samples2;
5573 std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
5576 std::move(samples2),
5590 // static std::string getDescription();
5591 // static std::set<Verbosity> getSupportedVerbosities()
5595 virtual void noMatchingTestCases( std::string const& spec ) = 0;
5597 virtual void reportInvalidArguments(std::string const&) {}
5606 virtual void benchmarkPreparing( std::string const& ) {}
5609 virtual void benchmarkFailed( std::string const& ) {}
5629 using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
5634 virtual std::string getDescription() const = 0;
5636 using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
5639 using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
5640 using Listeners = std::vector<IReporterFactoryPtr>;
5643 virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
5663 std::string getFormattedDuration( double duration );
5665 std::string serializeFilters( std::vector<std::string> const& container );
5683 static std::set<Verbosity> getSupportedVerbosities() {
5689 void noMatchingTestCases(std::string const&) override {}
5691 void reportInvalidArguments(std::string const&) override {}
5729 std::ostream& stream;
5735 std::vector<SectionInfo> m_sectionStack;
5746 using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>;
5757 bool operator == (std::shared_ptr<SectionNode> const& other) const {
5762 using ChildSections = std::vector<std::shared_ptr<SectionNode>>;
5763 using Assertions = std::vector<AssertionStats>;
5766 std::string stdOut;
5767 std::string stdErr;
5773 bool operator() (std::shared_ptr<SectionNode> const& node) const {
5801 static std::set<Verbosity> getSupportedVerbosities() {
5812 std::shared_ptr<SectionNode> node;
5815 m_rootSection = std::make_shared<SectionNode>( incompleteStats );
5821 std::find_if( parentNode.childSections.begin(),
5825 node = std::make_shared<SectionNode>( incompleteStats );
5832 m_deepestSection = std::move(node);
5856 auto node = std::make_shared<TestCaseNode>(testCaseStats);
5867 auto node = std::make_shared<TestGroupNode>(testGroupStats);
5872 auto node = std::make_shared<TestRunNode>(testRunStats);
5882 std::ostream& stream;
5883 std::vector<AssertionStats> m_assertions;
5884 std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;
5885 std::vector<std::shared_ptr<TestCaseNode>> m_testCases;
5886 std::vector<std::shared_ptr<TestGroupNode>> m_testGroups;
5888 std::vector<std::shared_ptr<TestRunNode>> m_testRuns;
5890 std::shared_ptr<SectionNode> m_rootSection;
5891 std::shared_ptr<SectionNode> m_deepestSection;
5892 std::vector<std::shared_ptr<SectionNode>> m_sectionStack;
5900 std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
5909 static std::set<Verbosity> getSupportedVerbosities();
5972 std::ostream& operator << ( std::ostream& os, Colour const& );
5988 return std::unique_ptr<T>( new T( config ) );
5991 std::string getDescription() const override {
5998 explicit ReporterRegistrar( std::string const& name ) {
5999 getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() );
6009 return std::unique_ptr<T>( new T( config ) );
6011 std::string getDescription() const override {
6012 return std::string();
6019 getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() );
6056 static std::string getDescription();
6060 void noMatchingTestCases(std::string const& spec) override;
6090 std::unique_ptr<TablePrinter> m_tablePrinter;
6094 static std::string getDescription();
6096 void noMatchingTestCases(std::string const& spec) override;
6098 void reportInvalidArguments(std::string const&arg) override;
6108 void benchmarkPreparing(std::string const& name) override;
6111 void benchmarkFailed(std::string const& error) override;
6127 void printClosedHeader(std::string const& _name);
6128 void printOpenHeader(std::string const& _name);
6132 void printHeaderString(std::string const& _string, std::size_t indent = 0);
6135 void printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row);
6172 XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes );
6174 void encodeTo( std::ostream& os ) const;
6176 friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
6179 std::string m_str;
6195 ScopedElement& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent );
6198 ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
6208 XmlWriter( std::ostream& os = Catch::cout() );
6214 XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6216 ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6220 XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
6222 XmlWriter& writeAttribute( std::string const& name, bool attribute );
6225 XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
6231 XmlWriter& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6233 XmlWriter& writeComment(std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6235 void writeStylesheetRef( std::string const& url );
6251 std::vector<std::string> m_tags;
6252 std::string m_indent;
6253 std::ostream& m_os;
6267 static std::string getDescription();
6269 void noMatchingTestCases(std::string const& /*spec*/) override;
6288 void writeSection(std::string const& className,
6289 std::string const& rootName,
6297 std::string stdOutForSuite;
6298 std::string stdErrForSuite;
6315 static std::string getDescription();
6317 virtual std::string getStylesheetRef() const;
6323 void noMatchingTestCases(std::string const& s) override;
6346 void benchmarkPreparing(std::string const& name) override;
6349 void benchmarkFailed(std::string const&) override;
6394 using FloatDuration = std::chrono::duration<double, typename Clock::period>;
6399 using default_clock = std::chrono::steady_clock;
6408 using fp_seconds = std::chrono::duration<double, std::ratio<1>>;
6449 std::atomic_thread_fence(std::memory_order_seq_cst);
6461 inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<!std::is_same<void, decltype(fn(args...))>::value>::type {
6462 deoptimize_value(std::forward<Fn>(fn) (std::forward<Args...>(args...)));
6466 inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<std::is_same<void, decltype(fn(args...))>::value>::type {
6467 std::forward<Fn>(fn) (std::forward<Args...>(args...));
6496 return std::forward<Fun>(fun)(std::forward<Args>(args)...);
6503 std::forward<Fun>(fun)(std::forward<Args>(args)...);
6508 using ResultOf_t = typename std::result_of<Sig>::type;
6513 return CompleteInvoker<ResultOf_t<Fun(Args...)>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
6516 const std::string benchmarkErrorMsg = "a benchmark failed to run successfully";
6522 return Detail::complete_invoke(std::forward<Fun>(fun));
6555 void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(int)>()); }
6565 void measure(Fun&& fun, std::false_type) {
6566 measure([&fun](int) { return fun(); }, std::true_type());
6570 void measure(Fun&& fun, std::true_type) {
6619 // Dumb std::function implementation for consistent call overhead
6631 using Decay = typename std::decay<T>::type;
6634 : std::is_same<Decay<T>, Decay<U>> {};
6636 /// We need to reinvent std::function because every piece of code that might add overhead
6639 /// Implementations of std::function with optimizations that aren't always applicable, like
6641 /// This is effectively an implementation of std::function without any such optimizations;
6652 model(Fun&& fun) : fun(std::move(fun)) {}
6660 void call(Chronometer meter, std::true_type) const {
6663 void call(Chronometer meter, std::false_type) const {
6680 typename std::enable_if<!is_related<Fun, BenchmarkFunction>::value, int>::type = 0>
6682 : f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
6685 : f(std::move(that.f)) {}
6691 f = std::move(that.f);
6703 std::unique_ptr<callable> f;
6731 repeater<typename std::decay<Fun>::type> repeat(Fun&& fun) {
6732 return { std::forward<Fun>(fun) };
6779 auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...);
6782 return { delta, std::forward<decltype(r)>(r), 1 };
6796 TimingOf<Clock, Fun(int)> measure_one(Fun&& fun, int iters, std::false_type) {
6800 TimingOf<Clock, Fun(Chronometer)> measure_one(Fun&& fun, int iters, std::true_type) {
6804 return { meter.elapsed(), std::move(result), iters };
6808 using run_for_at_least_argument_t = typename std::conditional<is_callable<Fun(Chronometer)>::value, Chronometer, int>::type;
6810 struct optimized_away_error : std::exception {
6823 return { Timing.elapsed, std::move(Timing.result), iters };
6852 std::vector<FloatDuration<Clock>> run(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
6854 Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_iterations, Detail::repeat(now<Clock>{}));
6856 std::vector<FloatDuration<Clock>> times;
6858 std::generate_n(std::back_inserter(times), cfg.benchmarkSamples(), [this, env] {
6894 using sample = std::vector<double>;
6896 double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last);
6900 std::vector<double> copy(first, last);
6925 double sum = std::accumulate(first, last, 0.);
6932 std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
6936 std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] {
6937 std::vector<double> resampled;
6939 std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; });
6942 std::sort(out.begin(), out.end());
6949 auto second = std::next(first);
6954 std::iter_swap(it, first);
6962 return std::erfc(-x / std::sqrt(2.0)) / 2.0;
6980 std::tie(sum_squares, sum_cubes) = std::accumulate(jack.begin(), jack.end(), std::make_pair(0., 0.), [jack_mean](std::pair<double, double> sqcb, double x) -> std::pair<double, double> {
6987 double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
6989 double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / (double)n;
6997 return std::lround(normal_cdf(x) * n); };
7003 auto lo = std::max(cumn(a1), 0);
7004 auto hi = std::min(cumn(a2), n - 1);
7017 bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
7033 std::vector<double> resolution(int k) {
7034 std::vector<TimePoint<Clock>> times;
7036 std::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
7038 std::vector<double> deltas;
7040 std::transform(std::next(times.begin()), times.end(), times.begin(),
7041 std::back_inserter(deltas),
7048 const auto warmup_time = std::chrono::milliseconds(100);
7051 const auto clock_resolution_estimation_time = std::chrono::milliseconds(500);
7052 const auto clock_cost_estimation_time_limit = std::chrono::seconds(1);
7054 const auto clock_cost_estimation_time = std::chrono::milliseconds(10);
7059 return run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_seed, &resolution<Clock>)
7064 auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>)
7073 auto time_limit = std::min(resolution * clock_cost_estimation_tick_limit, FloatDuration<Clock>(clock_cost_estimation_time_limit));
7084 auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
7085 std::vector<double> times;
7086 int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
7088 std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
7135 std::vector<Duration> samples;
7143 std::vector<Duration2> samples2;
7145 std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
7147 std::move(samples2),
7169 std::vector<double> samples;
7171 std::transform(first, last, std::back_inserter(samples), [](Duration d) { return d.count(); });
7184 std::vector<Duration> samples2;
7186 std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](double d) { return Duration(d); });
7188 std::move(samples2),
7195 std::vector<Duration> samples;
7207 std::move(samples),
7229 Benchmark(std::string &&name)
7230 : name(std::move(name)) {}
7233 Benchmark(std::string &&name, FUN &&func)
7234 : fun(std::move(func)), name(std::move(name)) {}
7239 auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(Detail::warmup_time));
7240 auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun);
7241 int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed));
7242 return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(Detail::warmup_time), Detail::warmup_iterations };
7279 std::rethrow_exception(std::current_exception());
7285 typename std::enable_if<!Detail::is_related<Fun, Benchmark>::value, int>::type = 0>
7298 std::string name;
7327 using TStorage = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type;
7338 new(&data) T(std::move(other.stored_object()));
7346 new (&data) T(std::forward<Args>(args)...);
7350 typename std::enable_if<AllowManualDestruction>::type destruct()
7358 void destruct_on_exit(typename std::enable_if<Destruct, U>::type* = 0) { destruct<true>(); }
7361 void destruct_on_exit(typename std::enable_if<!Destruct, U>::type* = 0) { }
7404 std::string name;
7407 NameAndLocation( std::string const& _name, SourceLineInfo const& _location );
7412 using ITrackerPtr = std::shared_ptr<ITracker>;
7478 using Children = std::vector<ITrackerPtr>;
7516 std::vector<std::string> m_filters;
7517 std::string m_trimmed_name;
7529 void addInitialFilters( std::vector<std::string> const& filters );
7530 void addNextFilters( std::vector<std::string> const& filters );
7644 double standard_deviation(std::vector<double>::iterator first, std::vector<double>::iterator last) {
7646 double variance = std::accumulate(first, last, 0., [m](double a, double b) {
7650 return std::sqrt(variance);
7659 double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last) {
7664 std::nth_element(first, first + j, last);
7668 auto xj1 = *std::min_element(first + (j + 1), last);
7677 static const double ROOT_TWO = std::sqrt(2.0);
7696 double sg = std::min(mg_min / 4., sb / std::sqrt(n));
7707 return (int)(-2. * k0 / (k1 + std::sqrt(det)));
7715 return std::min(var_out(1), var_out(std::min(c_max(0.), c_max(mg_min)))) / sb2;
7718 bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
7721 static std::random_device entropy;
7726 auto mean = &Detail::mean<std::vector<double>::iterator>;
7730 auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) {
7732 return std::async(std::launch::async, [=] {
7733 std::mt19937 rng(seed);
7745 auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) {
7747 std::mt19937 rng(seed);
7773 // Performs equivalent check of std::fabs(lhs - rhs) <= margin
7785 : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
7801 std::string Approx::toString() const {
7811 || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(std::isinf(m_value)? 0 : m_value)));
7839 std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
7986 void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount );
7987 void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount );
8011 std::string const& message,
8028 void benchmarkPreparing( std::string const& name ) override;
8031 void benchmarkFailed( std::string const& error ) override;
8039 std::string getCurrentTestName() const override;
8057 void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
8085 std::vector<MessageInfo> m_messages;
8086 std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */
8088 std::vector<SectionEndInfo> m_unfinishedSections;
8089 std::vector<ITracker*> m_activeSections;
8104 auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
8120 auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
8199 void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ) {
8212 std::string AssertionResultData::reconstructExpression() const {
8251 std::string AssertionResult::getExpression() const {
8253 std::string expr; expr.reserve(m_info.capturedExpression.size() + 3);
8264 std::string AssertionResult::getExpressionInMacro() const {
8265 std::string expr;
8267 expr = static_cast<std::string>(m_info.capturedExpression);
8282 std::string AssertionResult::getExpandedExpression() const {
8283 std::string expr = m_resultData.reconstructExpression();
8289 std::string AssertionResult::getMessage() const {
8306 using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
8312 std::string exceptionMessage = Catch::translateActiveException();
8313 MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
8362 #define CLARA_CONFIG_OPTIONAL_TYPE std::optional
8393 static std::string chars = " \t\n\r";
8394 return chars.find(c) != std::string::npos;
8397 static std::string chars = "[({<|";
8398 return chars.find(c) != std::string::npos;
8401 static std::string chars = "])}>.,:;*+-=&/\\";
8402 return chars.find(c) != std::string::npos;
8408 std::vector<std::string> m_strings;
8411 size_t m_initialIndent = std::string::npos;
8429 auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; }
8472 auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos;
8473 return initial == std::string::npos ? m_column.m_indent : initial;
8476 auto addIndentAndSuffix(std::string const &plain) const -> std::string {
8477 return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain);
8481 using difference_type = std::ptrdiff_t;
8482 using value_type = std::string;
8485 using iterator_category = std::forward_iterator_tag;
8489 assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent);
8495 auto operator *() const -> std::string {
8535 explicit Column(std::string const& text) { m_strings.push_back(text); }
8555 inline friend std::ostream& operator << (std::ostream& os, Column const& col) {
8569 auto toString() const -> std::string {
8570 std::ostringstream oss;
8585 std::vector<Column> m_columns;
8593 std::vector<Column> const& m_columns;
8594 std::vector<Column::iterator> m_iterators;
8607 using difference_type = std::ptrdiff_t;
8608 using value_type = std::string;
8611 using iterator_category = std::forward_iterator_tag;
8628 auto operator *() const -> std::string {
8629 std::string row, padding;
8634 std::string col = *m_iterators[i];
8637 padding = std::string(width - col.size(), ' ');
8641 padding += std::string(width, ' ');
8674 inline friend std::ostream& operator << (std::ostream& os, Columns const& cols) {
8687 auto toString() const -> std::string {
8688 std::ostringstream oss;
8733 using ArgType = typename std::remove_const<typename std::remove_reference<ArgT>::type>::type;
8742 std::string m_exeName;
8743 std::vector<std::string> m_args;
8750 Args( std::initializer_list<std::string> args )
8755 auto exeName() const -> std::string {
8767 std::string token;
8780 using Iterator = std::vector<std::string>::const_iterator;
8783 std::vector<Token> m_tokenBuffer;
8796 if( delimiterPos != std::string::npos ) {
8801 std::string opt = "- ";
8925 static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; }
8926 static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; }
8930 auto errorMessage() const -> std::string { return m_errorMessage; }
8940 std::abort();
8943 std::string m_errorMessage; // Only populated if resultType is an error
8945 BasicResult( ResultBase::Type type, std::string const &message )
8981 std::string left;
8982 std::string right;
8986 inline auto convertInto( std::string const &source, T& target ) -> ParserResult {
8987 std::stringstream ss;
8995 inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult {
8999 inline auto convertInto( std::string const &source, bool &target ) -> ParserResult {
9000 std::string srcLC = source;
9001 std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( char c ) { return static_cast<char>( std::tolower(c) ); } );
9012 inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE<T>& target ) -> ParserResult {
9016 target = std::move(temp);
9035 virtual auto setValue( std::string const &arg ) -> ParserResult = 0;
9048 auto setValue( std::string const &arg ) -> ParserResult override {
9054 struct BoundValueRef<std::vector<T>> : BoundValueRefBase {
9055 std::vector<T> &m_ref;
9057 explicit BoundValueRef( std::vector<T> &ref ) : m_ref( ref ) {}
9061 auto setValue( std::string const &arg ) -> ParserResult override {
9083 static_assert( std::is_same<ReturnType, ParserResult>::value, "Lambda must return void or clara::ParserResult" );
9101 inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult {
9116 auto setValue( std::string const &arg ) -> ParserResult override {
9126 static_assert( std::is_same<typename UnaryLambdaTraits<L>::ArgType, bool>::value, "flags must be boolean" );
9143 virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0;
9166 std::shared_ptr<BoundRef> m_ref;
9167 std::string m_hint;
9168 std::string m_description;
9170 explicit ParserRefImpl( std::shared_ptr<BoundRef> const &ref ) : m_ref( ref ) {}
9174 ParserRefImpl( T &ref, std::string const &hint )
9175 : m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
9180 ParserRefImpl( LambdaT const &ref, std::string const &hint )
9181 : m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
9185 auto operator()( std::string const &description ) -> DerivedT & {
9211 auto hint() const -> std::string { return m_hint; }
9215 std::shared_ptr<std::string> m_name;
9216 std::shared_ptr<BoundValueRefBase> m_ref;
9219 static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundValueRefBase> {
9220 return std::make_shared<BoundLambda<LambdaT>>( lambda) ;
9224 ExeName() : m_name( std::make_shared<std::string>( "<executable>" ) ) {}
9226 explicit ExeName( std::string &ref ) : ExeName() {
9227 m_ref = std::make_shared<BoundValueRef<std::string>>( ref );
9232 m_ref = std::make_shared<BoundLambda<LambdaT>>( lambda );
9236 auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
9240 auto name() const -> std::string { return *m_name; }
9241 auto set( std::string const& newName ) -> ParserResult {
9244 auto filename = ( lastSlash == std::string::npos )
9260 auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override {
9281 inline auto normaliseOpt( std::string const &optName ) -> std::string {
9292 std::vector<std::string> m_optNames;
9296 explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {}
9298 explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {}
9301 Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {}
9304 Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {}
9306 auto operator[]( std::string const &optName ) -> Opt & {
9311 auto getHelpColumns() const -> std::vector<HelpColumns> {
9312 std::ostringstream oss;
9326 auto isMatch( std::string const &optToken ) const -> bool {
9337 auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
9408 std::vector<Opt> m_options;
9409 std::vector<Arg> m_args;
9443 auto getHelpColumns() const -> std::vector<HelpColumns> {
9444 std::vector<HelpColumns> cols;
9452 void writeToStream( std::ostream &os ) const {
9473 os << "\n\nwhere options are:" << std::endl;
9480 optWidth = (std::max)(optWidth, cols.left.size() + 2);
9482 optWidth = (std::min)(optWidth, consoleWidth/2);
9489 os << row << std::endl;
9493 friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& {
9514 auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override {
9622 auto const setWarning = [&]( std::string const& warning ) {
9638 auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
9639 std::ifstream f( filename.c_str() );
9643 std::string line;
9644 while( std::getline( f, line ) ) {
9660 auto const setTestOrder = [&]( std::string const& order ) {
9671 auto const setRngSeed = [&]( std::string const& seed ) {
9674 config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
9677 auto const setColourUsage = [&]( std::string const& useColour ) {
9690 auto const setWaitForKeypress = [&]( std::string const& keypress ) {
9702 auto const setVerbosity = [&]( std::string const& verbosity ) {
9714 auto const setReporter = [&]( std::string const& reporter ) {
9830 return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
9835 return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0));
9838 std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
9847 std::string StreamEndStop::operator+() const {
9848 return std::string();
9885 std::string const& Config::getFilename() const {
9894 std::string Config::getProcessName() const { return m_data.processName; }
9895 std::string const& Config::getReporterName() const { return m_data.reporterName; }
9897 std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; }
9898 std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
9907 std::ostream& Config::stream() const { return m_stream->stream(); }
9908 std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
10161 std::ostream& operator << ( std::ostream& os, Colour const& ) {
10240 void writeToDebugConsole( std::string const& text );
10248 void writeToDebugConsole( std::string const& text ) {
10256 void writeToDebugConsole( std::string const& text ) {
10264 void writeToDebugConsole( std::string const& text ) {
10299 std::size_t size;
10318 Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
10347 // Libstdc++ has a bug, where std::ifstream sets errno to 0
10350 std::ifstream in("/proc/self/status");
10351 for( std::string line; std::getline(in, line); ) {
10390 void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) {
10392 lhs.find('\n') == std::string::npos &&
10393 rhs.find('\n') == std::string::npos )
10407 void throw_exception(std::exception const& e) {
10410 std::terminate();
10415 void throw_logic_error(std::string const& msg) {
10416 throw_exception(std::logic_error(msg));
10420 void throw_domain_error(std::string const& msg) {
10421 throw_exception(std::domain_error(msg));
10425 void throw_runtime_error(std::string const& msg) {
10426 throw_exception(std::runtime_error(msg));
10441 std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
10445 std::vector<std::unique_ptr<EnumInfo>> m_enumInfos;
10447 EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
10450 std::vector<StringRef> parseEnums( StringRef enums );
10480 std::vector<StringRef> parseEnums( StringRef enums ) {
10482 std::vector<StringRef> parsed;
10500 std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
10501 std::unique_ptr<EnumInfo> enumInfo( new EnumInfo );
10507 std::size_t i = 0;
10514 EnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
10546 std::string translateActiveException() const override;
10547 std::string tryTranslators() const;
10550 std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators;
10565 m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) );
10569 std::string ExceptionTranslatorRegistry::translateActiveException() const {
10582 // do not fill-in std::current_exception and thus lead to crash
10588 if (std::current_exception() == nullptr) {
10595 std::rethrow_exception(std::current_exception());
10597 catch( std::exception& ex ) {
10600 catch( std::string& msg ) {
10611 std::string ExceptionTranslatorRegistry::tryTranslators() const {
10613 std::rethrow_exception(std::current_exception());
10620 std::string ExceptionTranslatorRegistry::translateActiveException() const {
10624 std::string ExceptionTranslatorRegistry::tryTranslators() const {
10717 static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;
10752 for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
10764 for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
10849 using Reporters = std::vector<IStreamingReporterPtr>;
10864 void noMatchingTestCases( std::string const& spec ) override;
10866 void reportInvalidArguments(std::string const&arg) override;
10868 static std::set<Verbosity> getSupportedVerbosities();
10871 void benchmarkPreparing(std::string const& name) override;
10874 void benchmarkFailed(std::string const&) override;
10903 ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream )
10906 std::ostream& ReporterConfig::stream() const { return *m_stream; }
10909 TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {}
10911 GroupInfo::GroupInfo( std::string const& _name,
10912 std::size_t _groupIndex,
10913 std::size_t _groupsCount )
10920 std::vector<MessageInfo> const& _infoMessages,
10955 std::string const& _stdOut,
10956 std::string const& _stdErr,
11050 std::size_t listTests( Config const& config );
11052 std::size_t listTestsNamesOnly( Config const& config );
11055 void add( std::string const& spelling );
11056 std::string all() const;
11058 std::set<std::string> spellings;
11059 std::size_t count = 0;
11062 std::size_t listTags( Config const& config );
11064 std::size_t listReporters();
11066 Option<std::size_t> list( std::shared_ptr<Config> const& config );
11084 std::size_t listTests( Config const& config ) {
11101 Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl;
11102 std::string description = testCaseInfo.description;
11105 Catch::cout() << Column( description ).indent(4) << std::endl;
11112 Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl;
11114 Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl;
11118 std::size_t listTestsNamesOnly( Config const& config ) {
11120 std::size_t matchedTests = 0;
11121 std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
11130 Catch::cout() << std::endl;
11135 void TagInfo::add( std::string const& spelling ) {
11140 std::string TagInfo::all() const {
11147 std::string out; out.reserve(size);
11156 std::size_t listTags( Config const& config ) {
11164 std::map<std::string, TagInfo> tagCounts;
11166 std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
11169 std::string lcaseTagName = toLower( tagName );
11172 countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
11179 rss << " " << std::setw(2) << tagCount.second.count << " ";
11187 Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
11191 std::size_t listReporters() {
11194 std::size_t maxNameLen = 0;
11196 maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
11209 Catch::cout() << std::endl;
11213 Option<std::size_t> list( std::shared_ptr<Config> const& config ) {
11214 Option<std::size_t> listedCount;
11235 std::string MatcherUntypedBase::toString() const {
11257 bool ExceptionMessageMatcher::match(std::exception const& ex) const {
11261 std::string ExceptionMessageMatcher::describe() const {
11266 Exception::ExceptionMessageMatcher Message(std::string const& message) {
11290 std::string to_string(T const& t) {
11292 return std::to_string(t);
11318 std::memcpy(&i, &f, sizeof(f));
11325 std::memcpy(&i, &d, sizeof(d));
11345 auto ulpDiff = std::abs(lc - rc);
11385 start = std::nextafter(start, direction);
11391 // Performs equivalent check of std::fabs(lhs - rhs) <= margin
11398 void write(std::ostream& out, FloatingPoint num) {
11399 out << std::scientific
11400 << std::setprecision(std::numeric_limits<FloatingPoint>::max_digits10 - 1)
11420 // Performs equivalent check of std::fabs(lhs - rhs) <= margin
11426 std::string WithinAbsMatcher::describe() const {
11433 || m_ulps < (std::numeric_limits<uint32_t>::max)(),
11458 std::string WithinUlpsMatcher::describe() const {
11459 std::stringstream ret;
11494 const auto relMargin = m_epsilon * (std::max)(std::fabs(matchee), std::fabs(m_target));
11496 std::isinf(relMargin)? 0 : relMargin);
11499 std::string WithinRelMatcher::describe() const {
11524 return Floating::WithinRelMatcher(target, std::numeric_limits<double>::epsilon() * 100);
11532 return Floating::WithinRelMatcher(target, std::numeric_limits<float>::epsilon() * 100);
11541 std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) {
11558 CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
11562 std::string CasedString::adjustString( std::string const& str ) const {
11567 std::string CasedString::caseSensitivitySuffix() const {
11570 : std::string();
11573 StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator )
11578 std::string StringMatcherBase::describe() const {
11579 std::string description;
11592 bool EqualsMatcher::match( std::string const& source ) const {
11598 bool ContainsMatcher::match( std::string const& source ) const {
11604 bool StartsWithMatcher::match( std::string const& source ) const {
11610 bool EndsWithMatcher::match( std::string const& source ) const {
11614 RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {}
11616 bool RegexMatcher::match(std::string const& matchee) const {
11617 auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway
11619 flags |= std::regex::icase;
11621 auto reg = std::regex(m_regex, flags);
11622 return std::regex_match(matchee, reg);
11625 std::string RegexMatcher::describe() const {
11631 StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
11634 StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
11637 StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
11640 StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
11644 StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) {
11734 std::stack<char> openings;
11759 m_messages.back().message = static_cast<std::string>(trimmed(start, pos));
11767 m_messages.back().message = static_cast<std::string>(trimmed(start, names.size() - 1));
11778 void Capturer::captureValue( size_t index, std::string const& value ) {
11800 std::ostream& m_originalStream;
11801 std::ostream& m_redirectionStream;
11802 std::streambuf* m_prevBuf;
11805 RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream );
11814 auto str() const -> std::string;
11817 // StdErr has two constituent streams in C++, std::cerr and std::clog
11826 auto str() const -> std::string;
11836 RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr);
11839 std::string& m_redirectedCout;
11840 std::string& m_redirectedCerr;
11847 // Windows's implementation of std::tmpfile is terrible (it tries
11861 std::FILE* getFile();
11862 std::string getContents();
11865 std::FILE* m_file = nullptr;
11878 OutputRedirect(std::string& stdout_dest, std::string& stderr_dest);
11886 std::string& m_stdoutDest;
11887 std::string& m_stderrDest;
11915 RedirectedStream::RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream )
11928 auto RedirectedStdOut::str() const -> std::string { return m_rss.str(); }
11934 auto RedirectedStdErr::str() const -> std::string { return m_rss.str(); }
11936 RedirectedStreams::RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr)
11963 m_file = std::tmpfile();
11973 std::fclose(m_file);
11977 std::remove(m_buffer);
11985 std::string TempFile::getContents() {
11986 std::stringstream sstr;
11988 std::rewind(m_file);
11989 while (std::fgets(buffer, sizeof(buffer), m_file)) {
11995 OutputRedirect::OutputRedirect(std::string& stdout_dest, std::string& stderr_dest) :
12005 Catch::cout() << std::flush;
12008 // even though std::cerr is unbuffered
12009 Catch::cerr() << std::flush;
12010 Catch::clog() << std::flush;
12040 return std::isnan(f);
12043 return std::isnan(d);
12048 return std::_isnan(f);
12051 return std::_isnan(d);
12133 std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
12138 void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions );
12140 std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
12141 std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
12149 std::vector<TestCase> const& getAllTests() const override;
12150 std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const override;
12153 std::vector<TestCase> m_functions;
12155 mutable std::vector<TestCase> m_sortedFunctions;
12156 std::size_t m_unnamedCount = 0;
12157 std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
12170 std::string extractClassName( StringRef const& classOrQualifiedMethodName );
12189 IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override;
12191 void registerReporter( std::string const& name, IReporterFactoryPtr const& factory );
12213 TagAlias(std::string const& _tag, SourceLineInfo _lineInfo);
12215 std::string tag;
12229 TagAlias const* find( std::string const& alias ) const override;
12230 std::string expandAliases( std::string const& unexpandedTestSpec ) const override;
12231 void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
12234 std::map<std::string, TagAlias> m_registry;
12249 void add(std::exception_ptr const& exception) noexcept;
12250 std::vector<std::exception_ptr> const& getExceptions() const noexcept;
12252 std::vector<std::exception_ptr> m_exceptions;
12319 void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override {
12331 void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
12335 m_exceptionRegistry.add(std::current_exception());
12363 std::string translateActiveException() {
12375 IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
12382 void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) {
12436 std::shared_ptr<GeneratorTracker> tracker;
12442 tracker = std::static_pointer_cast<GeneratorTracker>( childTracker );
12445 tracker = std::make_shared<GeneratorTracker>( nameAndLocation, ctx, &currentTracker );
12475 m_generator = std::move( generator );
12485 m_reporter(std::move(reporter)),
12499 void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) {
12503 void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) {
12510 std::string redirectedCout;
12511 std::string redirectedCerr;
12645 void RunContext::benchmarkPreparing(std::string const& name) {
12654 void RunContext::benchmarkFailed(std::string const & error) {
12664 m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end());
12671 std::string RunContext::getCurrentTestName() const {
12674 : std::string();
12692 tempResult.message = static_cast<std::string>(message);
12715 std::string(),
12716 std::string(),
12719 testGroupEnded(std::string(), m_totals, 1, 1);
12735 return m_totals.assertions.failed >= static_cast<std::size_t>(m_config->abortAfter());
12738 void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) {
12855 data.message = static_cast<std::string>(message);
12870 std::string const& message,
12921 std::srand(config.rngSeed());
12966 std::string const& _name )
13018 std::shared_ptr<Config> m_config;
13049 friend std::ostream& operator << ( std::ostream& os, Version const& version );
13066 IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
13073 IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
13078 // On older platforms, returning std::unique_ptr<ListeningReporter>
13079 // when the return type is std::unique_ptr<IStreamingReporter>
13080 // doesn't compile without a std::move call. However, this causes
13083 auto ret = std::unique_ptr<IStreamingReporter>(new ListeningReporter);
13095 explicit TestGroup(std::shared_ptr<Config> const& config)
13141 using Tests = std::set<TestCase const*>;
13143 std::shared_ptr<Config> m_config;
13150 auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
13154 std::string filename = testCase.lineInfo.file;
13156 if (lastSlash != std::string::npos) {
13162 if (lastDot != std::string::npos) {
13166 tags.push_back(std::move(filename));
13193 std::rethrow_exception(ex_ptr);
13194 } catch ( std::exception const& ex ) {
13211 << m_cli << std::endl
13212 << "For more detailed usage please see the project docs\n" << std::endl;
13216 << std::left << std::setw(16) << "description: " << "A Catch2 test executable\n"
13217 << std::left << std::setw(16) << "category: " << "testframework\n"
13218 << std::left << std::setw(16) << "framework: " << "Catch Test\n"
13219 << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
13235 Catch::cerr() << "Run with -? for usage\n" << std::endl;
13278 Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
13279 static_cast<void>(std::getchar());
13283 Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
13284 static_cast<void>(std::getchar());
13300 m_config = std::make_shared<Config>( m_configData );
13321 if( Option<std::size_t> listed = list( m_config ) )
13333 return (std::min) (MaxExitCode, (std::max) (totals.error, static_cast<int>(totals.assertions.failed)));
13336 catch( std::exception& ex ) {
13337 Catch::cerr() << ex.what() << std::endl;
13352 static auto getSingletons() -> std::vector<ISingleton*>*& {
13353 static std::vector<ISingleton*>* g_singletons = nullptr;
13355 g_singletons = new std::vector<ISingleton*>();
13378 void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept {
13383 std::terminate();
13387 std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const noexcept {
13407 template<typename WriterF, std::size_t bufferSize=256>
13408 class StreamBufImpl : public std::streambuf {
13427 m_writer( std::string( 1, static_cast<char>( c ) ) );
13436 m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
13447 void operator()( std::string const&str ) {
13455 mutable std::ofstream m_ofs;
13463 std::ostream& stream() const override {
13471 mutable std::ostream m_os;
13479 std::ostream& stream() const override { return m_os; }
13485 std::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
13486 mutable std::ostream m_os;
13496 std::ostream& stream() const override { return m_os; }
13518 std::vector<std::unique_ptr<std::ostringstream>> m_streams;
13519 std::vector<std::size_t> m_unused;
13520 std::ostringstream m_referenceStream; // Used for copy state/ flags from
13522 auto add() -> std::size_t {
13524 m_streams.push_back( std::unique_ptr<std::ostringstream>( new std::ostringstream ) );
13534 void release( std::size_t index ) {
13546 static_cast<std::ostringstream*>( m_oss )->str("");
13551 auto ReusableStringStream::str() const -> std::string {
13552 return static_cast<std::ostringstream*>( m_oss )->str();
13558 std::ostream& cout() { return std::cout; }
13559 std::ostream& cerr() { return std::cerr; }
13560 std::ostream& clog() { return std::clog; }
13576 return static_cast<char>( std::tolower( c ) );
13580 bool startsWith( std::string const& s, std::string const& prefix ) {
13581 return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
13583 bool startsWith( std::string const& s, char prefix ) {
13586 bool endsWith( std::string const& s, std::string const& suffix ) {
13587 return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
13589 bool endsWith( std::string const& s, char suffix ) {
13592 bool contains( std::string const& s, std::string const& infix ) {
13593 return s.find( infix ) != std::string::npos;
13595 void toLowerInPlace( std::string& s ) {
13596 std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
13598 std::string toLower( std::string const& s ) {
13599 std::string lc = s;
13603 std::string trim( std::string const& str ) {
13605 std::string::size_type start = str.find_first_not_of( whitespaceChars );
13606 std::string::size_type end = str.find_last_not_of( whitespaceChars );
13608 return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
13623 bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
13625 std::size_t i = str.find( replaceThis );
13626 while( i != std::string::npos ) {
13632 i = std::string::npos;
13637 std::vector<StringRef> splitStringRef( StringRef str, char delimiter ) {
13638 std::vector<StringRef> subStrings;
13639 std::size_t start = 0;
13640 for(std::size_t pos = 0; pos < str.size(); ++pos ) {
13652 pluralise::pluralise( std::size_t count, std::string const& label )
13657 std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
13675 : StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
13688 return StringRef(m_start + start, (std::min)(m_size - start, size));
13695 && (std::memcmp( m_start, other.m_start, m_size ) == 0);
13698 auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& {
13702 auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& {
13712 TagAlias::TagAlias(std::string const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {}
13738 TagAlias const* TagAliasRegistry::find( std::string const& alias ) const {
13746 std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
13747 std::string expandedTestSpec = unexpandedTestSpec;
13749 std::size_t pos = expandedTestSpec.find( registryKvp.first );
13750 if( pos != std::string::npos ) {
13759 void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) {
13763 CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second,
13787 TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
13804 bool isReservedTag( std::string const& tag ) {
13805 return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( static_cast<unsigned char>(tag[0]) );
13807 void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
13816 std::string const& _className,
13823 std::vector<std::string> tags;
13824 std::string desc, tag;
13859 TestCaseInfo info( static_cast<std::string>(nameAndTags.name), _className, desc, tags, _lineInfo );
13860 return TestCase( _testCase, std::move(info) );
13863 void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
13864 std::sort(begin(tags), end(tags));
13865 tags.erase(std::unique(begin(tags), end(tags)), end(tags));
13869 std::string lcaseTag = toLower( tag );
13873 testCaseInfo.tags = std::move(tags);
13876 TestCaseInfo::TestCaseInfo( std::string const& _name,
13877 std::string const& _className,
13878 std::string const& _description,
13879 std::vector<std::string> const& _tags,
13903 std::string TestCaseInfo::tagsAsString() const {
13904 std::string ret;
13906 std::size_t full_size = 2 * tags.size();
13920 TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {}
13922 TestCase TestCase::withName( std::string const& _newName ) const {
13955 std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
13957 std::vector<TestCase> sorted = unsortedTestCases;
13961 std::sort( sorted.begin(), sorted.end() );
13965 std::shuffle( sorted.begin(), sorted.end(), rng() );
13982 void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
13983 std::set<TestCase> seenFunctions;
13993 std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
13994 std::vector<TestCase> filtered;
14004 std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
14009 std::string name = testCase.getTestCaseInfo().name;
14018 std::vector<TestCase> const& TestRegistry::getAllTests() const {
14021 std::vector<TestCase> const& TestRegistry::getAllTestsSorted( IConfig const& config ) const {
14039 std::string extractClassName( StringRef const& classOrQualifiedMethodName ) {
14040 std::string className(classOrQualifiedMethodName);
14043 std::size_t lastColons = className.rfind( "::" );
14044 std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
14045 if( penultimateColons == std::string::npos )
14070 NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location )
14078 m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr );
14135 auto it = std::find_if( m_children.begin(), m_children.end(),
14182 if( std::all_of(m_children.begin(), m_children.end(), [](ITrackerPtr const& t){ return t->isComplete(); }) )
14233 || std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) {
14242 std::shared_ptr<SectionTracker> section;
14248 section = std::static_pointer_cast<SectionTracker>( childTracker );
14251 section = std::make_shared<SectionTracker>( nameAndLocation, ctx, &currentTracker );
14264 void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
14272 void SectionTracker::addNextFilters( std::vector<std::string> const& filters ) {
14294 return new(std::nothrow) TestInvokerAsFunction( testAsFunction );
14326 TestSpec::Pattern::Pattern( std::string const& name )
14332 std::string const& TestSpec::Pattern::name() const {
14336 TestSpec::NamePattern::NamePattern( std::string const& name, std::string const& filterString )
14345 TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString )
14351 return std::find(begin(testCase.lcaseTags),
14366 return std::all_of( m_patterns.begin(), m_patterns.end(), [&]( PatternPtr const& p ){ return p->matches( testCase ); } );
14369 std::string TestSpec::Filter::name() const {
14370 std::string name;
14381 return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter const& f ){ return f.matches( testCase ); } );
14384 TestSpec::Matches TestSpec::matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const
14387 std::transform( m_filters.begin(), m_filters.end(), matches.begin(), [&]( Filter const& filter ){
14388 std::vector<TestCase const*> currentMatches;
14409 TestSpecParser& TestSpecParser::parse( std::string const& arg ) {
14572 std::string TestSpecParser::preprocessPattern() {
14573 std::string token = m_patternName;
14574 for (std::size_t i = 0; i < m_escapeChars.size(); ++i)
14591 TestSpec::PatternPtr pattern = std::make_shared<TestSpec::NamePattern>(token, m_substring);
14593 pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
14609 TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(".", m_substring);
14611 pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
14616 TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(token, m_substring);
14619 pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
14628 TestSpec parseTestSpec( std::string const& arg ) {
14643 return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
14653 for( std::size_t i = 0; i < iterations; ++i ) {
14672 // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers
14720 const std::string unprintableString = "{?}";
14738 std::string rawMemoryToString( const void *object, std::size_t size ) {
14748 rss << "0x" << std::setfill('0') << std::hex;
14750 rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
14756 std::string fpToString( T value, int precision ) {
14762 rss << std::setprecision( precision )
14763 << std::fixed
14765 std::string d = rss.str();
14766 std::size_t i = d.find_last_not_of( '0' );
14767 if( i != std::string::npos && i != d.size()-1 ) {
14781 std::string StringMaker<std::string>::convert(const std::string& str) {
14786 std::string s("\"");
14805 std::string StringMaker<std::string_view>::convert(std::string_view str) {
14806 return ::Catch::Detail::stringify(std::string{ str });
14810 std::string StringMaker<char const*>::convert(char const* str) {
14812 return ::Catch::Detail::stringify(std::string{ str });
14817 std::string StringMaker<char*>::convert(char* str) {
14819 return ::Catch::Detail::stringify(std::string{ str });
14826 std::string StringMaker<std::wstring>::convert(const std::wstring& wstr) {
14827 std::string s;
14836 std::string StringMaker<std::wstring_view>::convert(std::wstring_view str) {
14837 return StringMaker<std::wstring>::convert(std::wstring(str));
14841 std::string StringMaker<wchar_t const*>::convert(wchar_t const * str) {
14843 return ::Catch::Detail::stringify(std::wstring{ str });
14848 std::string StringMaker<wchar_t *>::convert(wchar_t * str) {
14850 return ::Catch::Detail::stringify(std::wstring{ str });
14859 std::string StringMaker<std::byte>::convert(std::byte value) {
14860 return ::Catch::Detail::stringify(std::to_integer<unsigned long long>(value));
14864 std::string StringMaker<int>::convert(int value) {
14867 std::string StringMaker<long>::convert(long value) {
14870 std::string StringMaker<long long>::convert(long long value) {
14874 rss << " (0x" << std::hex << value << ')';
14879 std::string StringMaker<unsigned int>::convert(unsigned int value) {
14882 std::string StringMaker<unsigned long>::convert(unsigned long value) {
14885 std::string StringMaker<unsigned long long>::convert(unsigned long long value) {
14889 rss << " (0x" << std::hex << value << ')';
14894 std::string StringMaker<bool>::convert(bool b) {
14898 std::string StringMaker<signed char>::convert(signed char value) {
14915 std::string StringMaker<char>::convert(char c) {
14918 std::string StringMaker<unsigned char>::convert(unsigned char c) {
14922 std::string StringMaker<std::nullptr_t>::convert(std::nullptr_t) {
14928 std::string StringMaker<float>::convert(float value) {
14934 std::string StringMaker<double>::convert(double value) {
14938 std::string ratio_string<std::atto>::symbol() { return "a"; }
14939 std::string ratio_string<std::femto>::symbol() { return "f"; }
14940 std::string ratio_string<std::pico>::symbol() { return "p"; }
14941 std::string ratio_string<std::nano>::symbol() { return "n"; }
14942 std::string ratio_string<std::micro>::symbol() { return "u"; }
14943 std::string ratio_string<std::milli>::symbol() { return "m"; }
14971 std::size_t Counts::total() const {
15014 return std::uncaught_exceptions() > 0;
15016 return std::uncaught_exception();
15040 std::ostream& operator << ( std::ostream& os, Version const& version ) {
15063 WildcardPattern::WildcardPattern( std::string const& pattern,
15078 bool WildcardPattern::matches( std::string const& str ) const {
15093 std::string WildcardPattern::normaliseString( std::string const& str ) const {
15135 void hexEscapeChar(std::ostream& os, unsigned char c) {
15136 std::ios_base::fmtflags f(os.flags());
15138 << std::uppercase << std::hex << std::setfill('0') << std::setw(2)
15144 return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Newline));
15148 return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Indent));
15155 static_cast<std::underlying_type<XmlFormatting>::type>(lhs) |
15156 static_cast<std::underlying_type<XmlFormatting>::type>(rhs)
15162 static_cast<std::underlying_type<XmlFormatting>::type>(lhs) &
15163 static_cast<std::underlying_type<XmlFormatting>::type>(rhs)
15167 XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat )
15172 void XmlEncode::encodeTo( std::ostream& os ) const {
15176 for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) {
15236 for (std::size_t n = 1; n < encBytes; ++n) {
15257 for (std::size_t n = 0; n < encBytes; ++n) {
15266 std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
15300 XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, XmlFormatting fmt ) {
15305 XmlWriter::XmlWriter( std::ostream& os ) : m_os( os )
15317 XmlWriter& XmlWriter::startElement( std::string const& name, XmlFormatting fmt ) {
15331 XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name, XmlFormatting fmt ) {
15350 m_os << std::flush;
15356 XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) {
15362 XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) {
15367 XmlWriter& XmlWriter::writeText( std::string const& text, XmlFormatting fmt) {
15380 XmlWriter& XmlWriter::writeComment( std::string const& text, XmlFormatting fmt) {
15390 void XmlWriter::writeStylesheetRef( std::string const& url ) {
15402 m_os << '>' << std::flush;
15418 m_os << std::endl;
15439 std::string getFormattedDuration( double duration ) {
15444 const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
15452 std::sprintf(buffer, "%.3f", duration);
15454 return std::string(buffer);
15457 std::string serializeFilters( std::vector<std::string> const& container ) {
15475 std::set<Verbosity> TestEventListenerBase::getSupportedVerbosities() {
15502 std::string bothOrAll( std::size_t count ) {
15503 return count == 1 ? std::string() :
15517 void printTotals(std::ostream& out, const Totals& totals) {
15522 const std::string qualify_assertions_failed =
15524 bothOrAll(totals.assertions.failed) : std::string();
15554 AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages)
15578 printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok"));
15635 void printResultType(Colour::Code colour, std::string const& passOrFail) const {
15645 void printIssue(std::string const& issue) const {
15688 const auto N = static_cast<std::size_t>(std::distance(itMessage, itEnd));
15710 std::ostream& stream;
15712 std::vector<MessageInfo> messages;
15713 std::vector<MessageInfo>::const_iterator itMessage;
15719 std::string CompactReporter::getDescription() {
15727 void CompactReporter::noMatchingTestCases( std::string const& spec ) {
15728 stream << "No test cases matched '" << spec << '\'' << std::endl;
15748 stream << std::endl;
15754 stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
15760 stream << '\n' << std::endl;
15796 ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages)
15918 std::ostream& stream;
15922 std::string passOrFail;
15923 std::string messageLabel;
15924 std::string message;
15925 std::vector<MessageInfo> messages;
15929 std::size_t makeRatio(std::size_t number, std::size_t total) {
15930 std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
15934 std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) {
15945 std::string name;
16006 auto unitsAsString() const -> std::string {
16023 friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& {
16030 std::ostream& m_os;
16031 std::vector<ColumnInfo> m_columnInfos;
16032 std::ostringstream m_oss;
16037 TablePrinter( std::ostream& os, std::vector<ColumnInfo> columnInfos )
16039 m_columnInfos( std::move( columnInfos ) ) {}
16041 auto columnInfos() const -> std::vector<ColumnInfo> const& {
16053 headerCols += Column(info.name).width(static_cast<std::size_t>(info.width - 2));
16064 m_os << std::endl;
16087 auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width))
16088 ? std::string(colInfo.width - (strSize + 1), ' ')
16089 : std::string();
16109 [&config]() -> std::vector<ColumnInfo> {
16123 { "samples mean std dev", 14, ColumnInfo::Right },
16124 { "iterations low mean low std dev", 14, ColumnInfo::Right },
16125 { "estimated high mean high std dev", 14, ColumnInfo::Right }
16131 std::string ConsoleReporter::getDescription() {
16135 void ConsoleReporter::noMatchingTestCases(std::string const& spec) {
16136 stream << "No test cases matched '" << spec << '\'' << std::endl;
16139 void ConsoleReporter::reportInvalidArguments(std::string const&arg){
16140 stream << "Invalid Filter: " << arg << std::endl;
16158 stream << std::endl;
16176 stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
16179 stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
16188 void ConsoleReporter::benchmarkPreparing(std::string const& name) {
16191 auto nameCol = Column(name).width(static_cast<std::size_t>(m_tablePrinter->columnInfos()[0].width - 2));
16227 void ConsoleReporter::benchmarkFailed(std::string const& error) {
16245 stream << '\n' << std::endl;
16252 stream << std::endl;
16315 stream << getLineOfChars<'.'>() << '\n' << std::endl;
16318 void ConsoleReporter::printClosedHeader(std::string const& _name) {
16322 void ConsoleReporter::printOpenHeader(std::string const& _name) {
16332 void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) {
16333 std::size_t i = _string.find(": ");
16334 if (i != std::string::npos)
16343 SummaryColumn( std::string _label, Colour::Code _colour )
16344 : label( std::move( _label ) ),
16346 SummaryColumn addRow( std::size_t count ) {
16349 std::string row = rss.str();
16360 std::string label;
16362 std::vector<std::string> rows;
16377 std::vector<SummaryColumn> columns;
16395 void ConsoleReporter::printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row) {
16397 std::string value = col.rows[row];
16415 std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total());
16416 std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total());
16417 std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total());
16423 stream << Colour(Colour::Error) << std::string(failedRatio, '=');
16424 stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio, '=');
16426 stream << Colour(Colour::ResultSuccess) << std::string(passedRatio, '=');
16428 stream << Colour(Colour::Success) << std::string(passedRatio, '=');
16430 stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '=');
16465 std::string getCurrentTimestamp() {
16469 std::time(&rawtime);
16473 std::tm timeInfo = {};
16476 std::tm* timeInfo;
16477 timeInfo = std::gmtime(&rawtime);
16484 std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
16486 std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
16488 return std::string(timeStamp);
16491 std::string fileNameTag(const std::vector<std::string> &tags) {
16492 auto it = std::find_if(begin(tags),
16494 [] (std::string const& tag) {return tag.front() == '#'; });
16497 return std::string();
16511 std::string JunitReporter::getDescription() {
16515 void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {}
16602 std::string className = stats.testInfo.className;
16616 void JunitReporter::writeSection( std::string const& className,
16617 std::string const& rootName,
16619 std::string name = trim( sectionNode.stats.sectionInfo.name );
16659 std::string elementName;
16734 m_listeners.push_back( std::move( listener ) );
16739 m_reporter = std::move( reporter );
16747 std::set<Verbosity> ListeningReporter::getSupportedVerbosities() {
16748 return std::set<Verbosity>{ };
16751 void ListeningReporter::noMatchingTestCases( std::string const& spec ) {
16758 void ListeningReporter::reportInvalidArguments(std::string const&arg){
16766 void ListeningReporter::benchmarkPreparing( std::string const& name ) {
16785 void ListeningReporter::benchmarkFailed( std::string const& error ) {
16897 std::string XmlReporter::getDescription() {
16901 std::string XmlReporter::getStylesheetRef() const {
16902 return std::string();
16911 void XmlReporter::noMatchingTestCases( std::string const& s ) {
16917 std::string stylesheetRef = getStylesheetRef();
17087 void XmlReporter::benchmarkPreparing(std::string const& name) {
17124 void XmlReporter::benchmarkFailed(std::string const &error) {