| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0aed332 commit a9703d1
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,7 @@ | |||
| 37 | 37 | #include <iosfwd> | |
| 38 | 38 | #include <ostream> | |
| 39 | 39 | #include <string> | |
| 40 | + #include <string_view> | ||
| 40 | 41 | #include <vector> | |
| 41 | 42 | ||
| 42 | 43 | #include "gtest/internal/gtest-internal.h" | |
@@ -65,10 +66,10 @@ class GTEST_API_ [[nodiscard]] TestPartResult { | |||
| 65 | 66 | // C'tor. TestPartResult does NOT have a default constructor. | |
| 66 | 67 | // Always use this constructor (with parameters) to create a | |
| 67 | 68 | // TestPartResult object. | |
| 68 | - TestPartResult(Type a_type, const char* a_file_name, int a_line_number, | ||
| 69 | - const char* a_message) | ||
| 69 | + TestPartResult(Type a_type, std::string_view a_file_name, int a_line_number, | ||
| 70 | + std::string_view a_message) | ||
| 70 | 71 | : type_(a_type), | |
| 71 | - file_name_(a_file_name == nullptr ? "" : a_file_name), | ||
| 72 | + file_name_(a_file_name), | ||
| 72 | 73 | line_number_(a_line_number), | |
| 73 | 74 | summary_(ExtractSummary(a_message)), | |
| 74 | 75 | message_(a_message) {} | |
@@ -112,7 +113,7 @@ class GTEST_API_ [[nodiscard]] TestPartResult { | |||
| 112 | 113 | ||
| 113 | 114 | // Gets the summary of the failure message by omitting the stack | |
| 114 | 115 | // trace in it. | |
| 115 | - static std::string ExtractSummary(const char* message); | ||
| 116 | + static std::string ExtractSummary(std::string_view message); | ||
| 116 | 117 | ||
| 117 | 118 | // The name of the source file where the test part took place, or | |
| 118 | 119 | // "" if the source file is unknown. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,6 +57,7 @@ | |||
| 57 | 57 | #include <set> | |
| 58 | 58 | #include <sstream> | |
| 59 | 59 | #include <string> | |
| 60 | + #include <string_view> | ||
| 60 | 61 | #include <type_traits> | |
| 61 | 62 | #include <vector> | |
| 62 | 63 | ||
@@ -1246,7 +1247,7 @@ class GTEST_API_ [[nodiscard]] UnitTest { | |||
| 1246 | 1247 | // eventually call this to report their results. The user code | |
| 1247 | 1248 | // should use the assertion macros instead of calling this directly. | |
| 1248 | 1249 | void AddTestPartResult(TestPartResult::Type result_type, | |
| 1249 | - const char* file_name, int line_number, | ||
| 1250 | + std::string_view file_name, int line_number, | ||
| 1250 | 1251 | const std::string& message, | |
| 1251 | 1252 | const std::string& os_stack_trace) | |
| 1252 | 1253 | GTEST_LOCK_EXCLUDED_(mutex_); | |
@@ -1619,6 +1620,8 @@ class GTEST_API_ [[nodiscard]] AssertHelper { | |||
| 1619 | 1620 | // Constructor. | |
| 1620 | 1621 | AssertHelper(TestPartResult::Type type, const char* file, int line, | |
| 1621 | 1622 | const char* message); | |
| 1623 | + AssertHelper(TestPartResult::Type type, std::string_view file, int line, | ||
| 1624 | + std::string_view message); | ||
| 1622 | 1625 | ~AssertHelper(); | |
| 1623 | 1626 | ||
| 1624 | 1627 | // Message assignment is a semantic trick to enable assertion | |
@@ -1632,12 +1635,12 @@ class GTEST_API_ [[nodiscard]] AssertHelper { | |||
| 1632 | 1635 | // re-using stack space even for temporary variables, so every EXPECT_EQ | |
| 1633 | 1636 | // reserves stack space for another AssertHelper. | |
| 1634 | 1637 | struct AssertHelperData { | |
| 1635 | - AssertHelperData(TestPartResult::Type t, const char* srcfile, int line_num, | ||
| 1636 | - const char* msg) | ||
| 1638 | + AssertHelperData(TestPartResult::Type t, std::string_view srcfile, | ||
| 1639 | + int line_num, std::string_view msg) | ||
| 1637 | 1640 | : type(t), file(srcfile), line(line_num), message(msg) {} | |
| 1638 | 1641 | ||
| 1639 | 1642 | TestPartResult::Type const type; | |
| 1640 | - const char* const file; | ||
| 1643 | + const std::string_view file; | ||
| 1641 | 1644 | int const line; | |
| 1642 | 1645 | std::string const message; | |
| 1643 | 1646 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1452,8 +1452,7 @@ class [[nodiscard]] NeverThrown { | |||
| 1452 | 1452 | ; \ | |
| 1453 | 1453 | else \ | |
| 1454 | 1454 | fail(::testing::internal::GetBoolAssertionFailureMessage( \ | |
| 1455 | - gtest_ar_, text, #actual, #expected) \ | ||
| 1456 | - .c_str()) | ||
| 1455 | + gtest_ar_, text, #actual, #expected)) | ||
| 1457 | 1456 | ||
| 1458 | 1457 | #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ | |
| 1459 | 1458 | GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,17 +34,19 @@ | |||
| 34 | 34 | ||
| 35 | 35 | #include <ostream> | |
| 36 | 36 | #include <string> | |
| 37 | + #include <string_view> | ||
| 37 | 38 | ||
| 39 | + #include "gtest/internal/gtest-internal.h" | ||
| 38 | 40 | #include "gtest/internal/gtest-port.h" | |
| 39 | 41 | #include "src/gtest-internal-inl.h" | |
| 40 | 42 | ||
| 41 | 43 | namespace testing { | |
| 42 | 44 | ||
| 43 | 45 | // Gets the summary of the failure message by omitting the stack trace | |
| 44 | 46 | // in it. | |
| 45 | - std::string TestPartResult::ExtractSummary(const char* message) { | ||
| 46 | - const char* const stack_trace = strstr(message, internal::kStackTraceMarker); | ||
| 47 | - return stack_trace == nullptr ? message : std::string(message, stack_trace); | ||
| 47 | + std::string TestPartResult::ExtractSummary(const std::string_view message) { | ||
| 48 | + auto stack_trace = message.find(internal::kStackTraceMarker); | ||
| 49 | + return std::string(message.substr(0, stack_trace)); | ||
| 48 | 50 | } | |
| 49 | 51 | ||
| 50 | 52 | // Prints a TestPartResult object. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,7 @@ | |||
| 58 | 58 | #include <ostream> // NOLINT | |
| 59 | 59 | #include <set> | |
| 60 | 60 | #include <sstream> | |
| 61 | + #include <string_view> | ||
| 61 | 62 | #include <unordered_set> | |
| 62 | 63 | #include <utility> | |
| 63 | 64 | #include <vector> | |
@@ -485,6 +486,15 @@ bool ShouldEmitStackTraceForResultType(TestPartResult::Type type) { | |||
| 485 | 486 | // AssertHelper constructor. | |
| 486 | 487 | AssertHelper::AssertHelper(TestPartResult::Type type, const char* file, | |
| 487 | 488 | int line, const char* message) | |
| 489 | + : AssertHelper( | ||
| 490 | + type, file == nullptr ? std::string_view() : std::string_view(file), | ||
| 491 | + line, | ||
| 492 | + message == nullptr ? std::string_view() : std::string_view(message)) { | ||
| 493 | + } | ||
| 494 | + | ||
| 495 | + AssertHelper::AssertHelper(TestPartResult::Type type, | ||
| 496 | + const std::string_view file, int line, | ||
| 497 | + const std::string_view message) | ||
| 488 | 498 | : data_(new AssertHelperData(type, file, line, message)) {} | |
| 489 | 499 | ||
| 490 | 500 | AssertHelper::~AssertHelper() { delete data_; } | |
@@ -875,7 +885,11 @@ class PositiveAndNegativeUnitTestFilter { | |||
| 875 | 885 | // and does not match the negative filter. | |
| 876 | 886 | bool MatchesTest(const std::string& test_suite_name, | |
| 877 | 887 | const std::string& test_name) const { | |
| 888 | + #ifdef GTEST_HAS_ABSL | ||
| 889 | + return MatchesName(absl::StrCat(test_suite_name, ".", test_name)); | ||
| 890 | + #else | ||
| 878 | 891 | return MatchesName(test_suite_name + "." + test_name); | |
| 892 | + #endif | ||
| 879 | 893 | } | |
| 880 | 894 | ||
| 881 | 895 | // Returns true if and only if name matches the positive filter and does not | |
@@ -2547,8 +2561,9 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, | |||
| 2547 | 2561 | // AddTestPartResult. | |
| 2548 | 2562 | UnitTest::GetInstance()->AddTestPartResult( | |
| 2549 | 2563 | result_type, | |
| 2550 | - nullptr, // No info about the source file where the exception occurred. | ||
| 2551 | - -1, // We have no info on which line caused the exception. | ||
| 2564 | + std::string_view(), // No info about the source file where the exception | ||
| 2565 | + // occurred. | ||
| 2566 | + -1, // We have no info on which line caused the exception. | ||
| 2552 | 2567 | message, | |
| 2553 | 2568 | ""); // No stack trace, either. | |
| 2554 | 2569 | } | |
@@ -5428,8 +5443,8 @@ Environment* UnitTest::AddEnvironment(Environment* env) { | |||
| 5428 | 5443 | // this to report their results. The user code should use the | |
| 5429 | 5444 | // assertion macros instead of calling this directly. | |
| 5430 | 5445 | void UnitTest::AddTestPartResult(TestPartResult::Type result_type, | |
| 5431 | - const char* file_name, int line_number, | ||
| 5432 | - const std::string& message, | ||
| 5446 | + const std::string_view file_name, | ||
| 5447 | + int line_number, const std::string& message, | ||
| 5433 | 5448 | const std::string& os_stack_trace) | |
| 5434 | 5449 | GTEST_LOCK_EXCLUDED_(mutex_) { | |
| 5435 | 5450 | Message msg; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments