diff options
author | amatanhead <amatanhead@yandex-team.ru> | 2022-02-10 16:50:04 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:04 +0300 |
commit | b6f3a80f7c2c8b7dbb0c01b056fdc1fd8cd820e9 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/testing/gtest_extensions/assertions.cpp | |
parent | 8879605a63ac17539be5b3bd41b529791f4d4b02 (diff) | |
download | ydb-b6f3a80f7c2c8b7dbb0c01b056fdc1fd8cd820e9.tar.gz |
Restoring authorship annotation for <amatanhead@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/testing/gtest_extensions/assertions.cpp')
-rw-r--r-- | library/cpp/testing/gtest_extensions/assertions.cpp | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/library/cpp/testing/gtest_extensions/assertions.cpp b/library/cpp/testing/gtest_extensions/assertions.cpp index 14416daed3..f390409d1b 100644 --- a/library/cpp/testing/gtest_extensions/assertions.cpp +++ b/library/cpp/testing/gtest_extensions/assertions.cpp @@ -1,90 +1,90 @@ -#include "assertions.h" - -#include <util/string/builder.h> -#include <util/string/split.h> +#include "assertions.h" + +#include <util/string/builder.h> +#include <util/string/split.h> #include <util/system/type_name.h> - -namespace NGTest::NInternal { - namespace { - void FormatActual(const std::exception& err, const TBackTrace* bt, TStringBuilder& out) { + +namespace NGTest::NInternal { + namespace { + void FormatActual(const std::exception& err, const TBackTrace* bt, TStringBuilder& out) { out << "an exception of type " << TypeName(err) << " " - << "with message " << TString(err.what()).Quote() << "."; - if (bt) { - out << "\n Trace: "; - for (auto& line: StringSplitter(bt->PrintToString()).Split('\n')) { - out << " " << line.Token() << "\n"; - } - } - } - - void FormatActual(TStringBuilder& out) { - out << " Actual: it throws "; - auto exceptionPtr = std::current_exception(); - if (exceptionPtr) { - try { - std::rethrow_exception(exceptionPtr); - } catch (const yexception& err) { - FormatActual(err, err.BackTrace(), out); - return; - } catch (const std::exception& err) { - FormatActual(err, nullptr, out); - return; - } catch (...) { - out << "an unknown exception."; - return; - } - } - out << "nothing."; - } - - void FormatExpected(const char* statement, const char* type, const TString& contains, TStringBuilder& out) { - out << "Expected: "; - if (TStringBuf(statement).size() > 80) { - out << "statement"; - } else { - out << statement; - } - out << " throws an exception of type " << type; - - if (!contains.empty()) { - out << " with message containing " << contains.Quote(); - } - - out << "."; - } - } - - TString FormatErrorWrongException(const char* statement, const char* type) { - return FormatErrorWrongException(statement, type, ""); - } - - TString FormatErrorWrongException(const char* statement, const char* type, TString contains) { - TStringBuilder out; - - FormatExpected(statement, type, contains, out); - out << "\n"; - FormatActual(out); - - return out; - } - - TString FormatErrorUnexpectedException(const char* statement) { - TStringBuilder out; - - out << "Expected: "; - if (TStringBuf(statement).size() > 80) { - out << "statement"; - } else { - out << statement; - } - out << " doesn't throw an exception.\n "; - - FormatActual(out); - - return out; - } - - bool ExceptionMessageContains(const std::exception& err, TString contains) { - return TStringBuf(err.what()).Contains(contains); - } -} + << "with message " << TString(err.what()).Quote() << "."; + if (bt) { + out << "\n Trace: "; + for (auto& line: StringSplitter(bt->PrintToString()).Split('\n')) { + out << " " << line.Token() << "\n"; + } + } + } + + void FormatActual(TStringBuilder& out) { + out << " Actual: it throws "; + auto exceptionPtr = std::current_exception(); + if (exceptionPtr) { + try { + std::rethrow_exception(exceptionPtr); + } catch (const yexception& err) { + FormatActual(err, err.BackTrace(), out); + return; + } catch (const std::exception& err) { + FormatActual(err, nullptr, out); + return; + } catch (...) { + out << "an unknown exception."; + return; + } + } + out << "nothing."; + } + + void FormatExpected(const char* statement, const char* type, const TString& contains, TStringBuilder& out) { + out << "Expected: "; + if (TStringBuf(statement).size() > 80) { + out << "statement"; + } else { + out << statement; + } + out << " throws an exception of type " << type; + + if (!contains.empty()) { + out << " with message containing " << contains.Quote(); + } + + out << "."; + } + } + + TString FormatErrorWrongException(const char* statement, const char* type) { + return FormatErrorWrongException(statement, type, ""); + } + + TString FormatErrorWrongException(const char* statement, const char* type, TString contains) { + TStringBuilder out; + + FormatExpected(statement, type, contains, out); + out << "\n"; + FormatActual(out); + + return out; + } + + TString FormatErrorUnexpectedException(const char* statement) { + TStringBuilder out; + + out << "Expected: "; + if (TStringBuf(statement).size() > 80) { + out << "statement"; + } else { + out << statement; + } + out << " doesn't throw an exception.\n "; + + FormatActual(out); + + return out; + } + + bool ExceptionMessageContains(const std::exception& err, TString contains) { + return TStringBuf(err.what()).Contains(contains); + } +} |