googletest/googletest/src/gtest-test-part.cc
Go to the documentation of this file.
1 // Copyright 2008, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 //
31 // The Google C++ Testing and Mocking Framework (Google Test)
32 
33 #include "gtest/gtest-test-part.h"
34 
35 #include "gtest/internal/gtest-port.h"
36 #include "src/gtest-internal-inl.h"
37 
38 namespace testing {
39 
41 
42 // Gets the summary of the failure message by omitting the stack trace
43 // in it.
45  const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
46  return stack_trace == nullptr ? message : std::string(message, stack_trace);
47 }
48 
49 // Prints a TestPartResult object.
50 std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
51  return os << internal::FormatFileLocation(result.file_name(),
52  result.line_number())
53  << " "
54  << (result.type() == TestPartResult::kSuccess
55  ? "Success"
56  : result.type() == TestPartResult::kSkip
57  ? "Skipped"
59  ? "Fatal failure"
60  : "Non-fatal failure")
61  << ":\n"
62  << result.message() << std::endl;
63 }
64 
65 // Appends a TestPartResult to the array.
66 void TestPartResultArray::Append(const TestPartResult& result) {
67  array_.push_back(result);
68 }
69 
70 // Returns the TestPartResult at the given index (0-based).
71 const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
72  if (index < 0 || index >= size()) {
73  printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
75  }
76 
77  return array_[static_cast<size_t>(index)];
78 }
79 
80 // Returns the number of TestPartResult objects in the array.
81 int TestPartResultArray::size() const {
82  return static_cast<int>(array_.size());
83 }
84 
85 namespace internal {
86 
88  : has_new_fatal_failure_(false),
89  original_reporter_(GetUnitTestImpl()->
90  GetTestPartResultReporterForCurrentThread()) {
92 }
93 
97 }
98 
100  const TestPartResult& result) {
101  if (result.fatally_failed())
102  has_new_fatal_failure_ = true;
104 }
105 
106 } // namespace internal
107 
108 } // namespace testing
testing::TestPartResult::ExtractSummary
static std::string ExtractSummary(const char *message)
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:42
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
testing
Definition: aws_request_signer_test.cc:25
false
#define false
Definition: setup_once.h:323
testing::TestPartResult::kFatalFailure
@ kFatalFailure
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18279
testing::internal::FormatFileLocation
GTEST_API_ ::std::string FormatFileLocation(const char *file, int line)
Definition: bloaty/third_party/googletest/googletest/src/gtest-port.cc:1018
testing::internal::GetUnitTestImpl
UnitTestImpl * GetUnitTestImpl()
Definition: gmock-gtest-all.cc:1334
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
testing::internal::HasNewFatalFailureHelper::ReportTestPartResult
virtual void ReportTestPartResult(const TestPartResult &result)
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:95
testing::TestPartResultReporterInterface::ReportTestPartResult
virtual void ReportTestPartResult(const TestPartResult &result)=0
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
testing::operator<<
std::ostream & operator<<(std::ostream &os, const Message &sb)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-message.h:198
testing::internal::HasNewFatalFailureHelper::original_reporter_
TestPartResultReporterInterface * original_reporter_
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18395
testing::TestPartResultArray::size
int size() const
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:77
testing::internal::HasNewFatalFailureHelper::has_new_fatal_failure_
bool has_new_fatal_failure_
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18394
testing::internal::posix::Abort
void Abort()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2076
testing::TestPartResult::message
const char * message() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18313
testing::TestPartResultArray::Append
void Append(const TestPartResult &result)
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:62
testing::internal::HasNewFatalFailureHelper::~HasNewFatalFailureHelper
virtual ~HasNewFatalFailureHelper()
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:90
testing::TestPartResultArray::GetTestPartResult
const TestPartResult & GetTestPartResult(int index) const
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:67
testing::internal::HasNewFatalFailureHelper::HasNewFatalFailureHelper
HasNewFatalFailureHelper()
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:83
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
testing::TestPartResultArray::array_
std::vector< TestPartResult > array_
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18365
testing::internal::kStackTraceMarker
const GTEST_API_ char kStackTraceMarker[]
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:178
testing::TestPartResult::kSuccess
@ kSuccess
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18277
internal
Definition: benchmark/test/output_test_helper.cc:20
testing::internal::UnitTestImpl::SetTestPartResultReporterForCurrentThread
void SetTestPartResultReporterForCurrentThread(TestPartResultReporterInterface *reporter)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:749


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:48