75#elif GTEST_OS_WINDOWS_MOBILE
90# include <sys/timeb.h>
91# include <sys/types.h>
94# if GTEST_OS_WINDOWS_MINGW
102# include <sys/time.h>
107#if GTEST_HAS_EXCEPTIONS
111#if GTEST_CAN_STREAM_RESULTS_
112# include <arpa/inet.h>
114# include <sys/socket.h>
115# include <sys/types.h>
121# define vsnprintf _vsnprintf
126#include <crt_externs.h>
131#include "absl/debugging/failure_signal_handler.h"
132#include "absl/debugging/stacktrace.h"
133#include "absl/debugging/symbolize.h"
134#include "absl/strings/str_cat.h"
139using internal::CountIf;
140using internal::ForEach;
141using internal::GetElementOr;
142using internal::Shuffle;
148static const char kDisableTestFilter[] =
"DISABLED_*:*/DISABLED_*";
153static const char kDeathTestSuiteFilter[] =
"*DeathTest:*DeathTest/*";
156static const char kUniversalFilter[] =
"*";
159static const char kDefaultOutputFormat[] =
"xml";
161static const char kDefaultOutputFile[] =
"test_detail";
164static const char kTestShardIndex[] =
"GTEST_SHARD_INDEX";
166static const char kTestTotalShards[] =
"GTEST_TOTAL_SHARDS";
168static const char kTestShardStatusFile[] =
"GTEST_SHARD_STATUS_FILE";
181static FILE* OpenFileForWriting(
const std::string& output_file) {
182 FILE* fileout =
nullptr;
183 FilePath output_file_path(output_file);
184 FilePath output_dir(output_file_path.RemoveFileName());
186 if (output_dir.CreateDirectoriesRecursively()) {
189 if (fileout ==
nullptr) {
199static const char* GetDefaultFilter() {
200 const char*
const testbridge_test_only =
202 if (testbridge_test_only !=
nullptr) {
203 return testbridge_test_only;
205 return kUniversalFilter;
210static bool GetDefaultFailFast() {
211 const char*
const testbridge_test_runner_fail_fast =
213 if (testbridge_test_runner_fail_fast !=
nullptr) {
214 return strcmp(testbridge_test_runner_fail_fast,
"1") == 0;
221 "True if and only if a test failure should stop further test execution.");
224 also_run_disabled_tests,
226 "Run disabled tests too, in addition to the tests normally being run.");
230 "True if and only if a failed assertion should be a debugger "
236 " should catch exceptions and treat them as test failures.");
241 "Whether to use colors in the output. Valid values: yes, no, "
242 "and auto. 'auto' means to use colors if the output is "
243 "being sent to a terminal and the TERM environment variable "
244 "is set to a terminal type that supports colors.");
249 "A colon-separated list of glob (not regex) patterns "
250 "for filtering the tests to run, optionally followed by a "
251 "'-' and a : separated list of negative patterns (tests to "
252 "exclude). A test is run if it matches one of the positive "
253 "patterns and does not match any of the negative patterns.");
256 install_failure_signal_handler,
258 "If true and supported on the current platform, " GTEST_NAME_ " should "
259 "install a signal handler that dumps debugging information when fatal "
260 "signals are raised.");
263 "List all tests without running them.");
274 "A format (defaults to \"xml\" but can be specified to be \"json\"), "
275 "optionally followed by a colon and an output file name or directory. "
276 "A directory is indicated by a trailing pathname separator. "
277 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
278 "If a directory is specified, output files will be created "
279 "within that directory, with file-names based on the test "
280 "executable's name and, if necessary, made unique by adding "
285 "True if only test failures should be displayed in text output.");
289 " should display elapsed time in text output.");
293 " prints UTF8 characters as text.");
298 "Random number seed to use when shuffling test orders. Must be in range "
299 "[1, 99999], or 0 to use a seed based on the current time.");
304 "How many times to repeat each test. Specify a negative number "
305 "for repeating forever. Useful for shaking out flaky tests.");
309 " should include internal stack frames when "
310 "printing test failure stack traces.");
314 " should randomize tests' order on every run.");
319 "The maximum number of stack frames to print when an "
320 "assertion fails. The valid range is 0 through 100, inclusive.");
325 "This flag specifies the host name and the port number on which to stream "
326 "test results. Example: \"localhost:555\". The flag is effective only on "
332 "When this flag is specified, a failed assertion will throw an exception "
333 "if exceptions are enabled or exit the program with a non-zero code "
334 "otherwise. For use with an external test framework.");
336#if GTEST_USE_OWN_FLAGFILE_FLAG_
340 "This flag specifies the flagfile to read command-line flags from.");
351 state_ =
static_cast<uint32_t
>(1103515245ULL*state_ + 12345U) %
kMaxRange;
354 <<
"Cannot generate a number in the range [0, 0).";
356 <<
"Generation of a number in [0, " << range <<
") was requested, "
357 <<
"but this can only generate numbers in [0, " <<
kMaxRange <<
").";
362 return state_ % range;
368static bool GTestIsInitialized() {
return GetArgvs().size() > 0; }
373static int SumOverTestSuiteList(
const std::vector<TestSuite*>& case_list,
376 for (
size_t i = 0;
i < case_list.size();
i++) {
377 sum += (case_list[
i]->*method)();
383static bool TestSuitePassed(
const TestSuite* test_suite) {
384 return test_suite->should_run() && test_suite->Passed();
388static bool TestSuiteFailed(
const TestSuite* test_suite) {
389 return test_suite->should_run() && test_suite->Failed();
394static bool ShouldRunTestSuite(
const TestSuite* test_suite) {
395 return test_suite->should_run();
413 AddTestPartResult(data_->type, data_->file, data_->line,
416 ->CurrentOsStackTraceExceptTop(1)
428constexpr bool kErrorOnUninstantiatedParameterizedTest =
true;
429constexpr bool kErrorOnUninstantiatedTypeParameterizedTest =
true;
432class FailureTest :
public Test {
434 explicit FailureTest(
const CodeLocation& loc, std::string error_message,
437 error_message_(
std::move(error_message)),
438 as_error_(as_error) {}
440 void TestBody()
override {
442 AssertHelper(TestPartResult::kNonFatalFailure, loc_.file.c_str(),
443 loc_.line,
"") =
Message() << error_message_;
445 std::cout << error_message_ << std::endl;
450 const CodeLocation loc_;
451 const std::string error_message_;
452 const bool as_error_;
472 if (ignored.find(name) != ignored.end())
return;
474 const char kMissingInstantiation[] =
475 " is defined via TEST_P, but never instantiated. None of the test cases "
476 "will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only "
477 "ones provided expand to nothing."
479 "Ideally, TEST_P definitions should only ever be included as part of "
480 "binaries that intend to use them. (As opposed to, for example, being "
481 "placed in a library that may be linked in to get other utilities.)";
483 const char kMissingTestCase[] =
484 " is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are "
485 "defined via TEST_P . No test cases will run."
487 "Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from "
488 "code that always depend on code that provides TEST_P. Failing to do "
489 "so is often an indication of dead code, e.g. the last TEST_P was "
490 "removed but the rest got left behind.";
493 "Parameterized test suite " + name +
494 (has_test_p ? kMissingInstantiation : kMissingTestCase) +
496 "To suppress this error for this test suite, insert the following line "
497 "(in a non-header) in the namespace it is defined in:"
499 "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" + name +
");";
501 std::string full_name =
"UninstantiatedParameterizedTestSuite<" + name +
">";
503 "GoogleTestVerification", full_name.c_str(),
507 return new FailureTest(location, message,
508 kErrorOnUninstantiatedParameterizedTest);
514 GetUnitTestImpl()->type_parameterized_test_registry().RegisterTestSuite(
515 test_suite_name, code_location);
520 ->type_parameterized_test_registry()
521 .RegisterInstantiation(case_name);
525 const char* test_suite_name,
CodeLocation code_location) {
526 suites_.emplace(std::string(test_suite_name),
527 TypeParameterizedTestSuiteInfo(code_location));
531 const char* test_suite_name) {
532 auto it = suites_.find(std::string(test_suite_name));
533 if (it != suites_.end()) {
534 it->second.instantiated =
true;
537 << test_suite_name <<
"'";
543 for (
const auto& testcase : suites_) {
544 if (testcase.second.instantiated)
continue;
545 if (ignored.find(testcase.first) != ignored.end())
continue;
548 "Type parameterized test suite " + testcase.first +
549 " is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated "
550 "via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run."
552 "Ideally, TYPED_TEST_P definitions should only ever be included as "
553 "part of binaries that intend to use them. (As opposed to, for "
554 "example, being placed in a library that may be linked in to get other "
557 "To suppress this error for this test suite, insert the following line "
558 "(in a non-header) in the namespace it is defined in:"
560 "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" +
561 testcase.first +
");";
563 std::string full_name =
564 "UninstantiatedTypeParameterizedTestSuite<" + testcase.first +
">";
566 "GoogleTestVerification", full_name.c_str(),
569 testcase.second.code_location.file.c_str(),
570 testcase.second.code_location.line, [
message, testcase] {
571 return new FailureTest(testcase.second.code_location, message,
572 kErrorOnUninstantiatedTypeParameterizedTest);
581#if defined(GTEST_CUSTOM_GET_ARGVS_)
584 const auto& custom = GTEST_CUSTOM_GET_ARGVS_();
585 return ::std::vector<std::string>(custom.begin(), custom.end());
596#if GTEST_OS_WINDOWS || GTEST_OS_OS2
597 result.Set(FilePath(
GetArgvs()[0]).RemoveExtension(
"exe"));
599 result.Set(FilePath(
GetArgvs()[0]));
602 return result.RemoveDirectoryName();
608std::string UnitTestOptions::GetOutputFormat() {
610 const char*
const colon = strchr(gtest_output_flag,
':');
611 return (colon ==
nullptr)
612 ? std::string(gtest_output_flag)
613 :
std::string(gtest_output_flag,
614 static_cast<size_t>(colon - gtest_output_flag));
619std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
622 std::string format = GetOutputFormat();
624 format = std::string(kDefaultOutputFormat);
626 const char*
const colon = strchr(gtest_output_flag,
':');
627 if (colon ==
nullptr)
628 return internal::FilePath::MakeFileName(
631 internal::FilePath(kDefaultOutputFile), 0,
632 format.c_str()).string();
634 internal::FilePath output_name(colon + 1);
635 if (!output_name.IsAbsolutePath())
636 output_name = internal::FilePath::ConcatPaths(
638 internal::FilePath(colon + 1));
640 if (!output_name.IsDirectory())
641 return output_name.string();
643 internal::FilePath result(internal::FilePath::GenerateUniqueFileName(
645 GetOutputFormat().c_str()));
646 return result.string();
655static bool PatternMatchesString(
const std::string& name_str,
656 const char* pattern,
const char* pattern_end) {
657 const char* name = name_str.c_str();
658 const char*
const name_begin = name;
659 const char*
const name_end = name + name_str.size();
661 const char* pattern_next = pattern;
662 const char* name_next = name;
664 while (pattern < pattern_end || name < name_end) {
665 if (pattern < pattern_end) {
668 if (name < name_end && *name == *pattern) {
675 if (name < name_end) {
685 pattern_next = pattern;
686 name_next = name + 1;
692 if (name_begin < name_next && name_next <= name_end) {
693 pattern = pattern_next;
702bool UnitTestOptions::MatchesFilter(
const std::string& name_str,
703 const char* filter) {
705 const char* pattern = filter;
708 const char*
const next_sep = strchr(pattern,
':');
709 const char*
const pattern_end =
710 next_sep !=
nullptr ? next_sep : pattern + strlen(pattern);
713 if (PatternMatchesString(name_str, pattern, pattern_end)) {
719 if (next_sep ==
nullptr) {
722 pattern = next_sep + 1;
729bool UnitTestOptions::FilterMatchesTest(
const std::string& test_suite_name,
730 const std::string& test_name) {
731 const std::string& full_name = test_suite_name +
"." + test_name.c_str();
736 const char*
const dash = strchr(
p,
'-');
737 std::string positive;
738 std::string negative;
739 if (dash ==
nullptr) {
743 positive = std::string(
p, dash);
744 negative = std::string(dash + 1);
745 if (positive.empty()) {
747 positive = kUniversalFilter;
753 return (MatchesFilter(full_name, positive.c_str()) &&
754 !MatchesFilter(full_name, negative.c_str()));
761int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
770 const DWORD kCxxExceptionCode = 0xe06d7363;
772 bool should_handle =
true;
775 should_handle =
false;
776 else if (exception_code == EXCEPTION_BREAKPOINT)
777 should_handle =
false;
778 else if (exception_code == kCxxExceptionCode)
779 should_handle =
false;
781 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
790ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
791 TestPartResultArray* result)
792 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
800ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
801 InterceptMode intercept_mode, TestPartResultArray* result)
802 : intercept_mode_(intercept_mode),
807void ScopedFakeTestPartResultReporter::Init() {
808 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
809 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
810 old_reporter_ = impl->GetGlobalTestPartResultReporter();
811 impl->SetGlobalTestPartResultReporter(
this);
813 old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
814 impl->SetTestPartResultReporterForCurrentThread(
this);
820ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
821 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
822 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
823 impl->SetGlobalTestPartResultReporter(old_reporter_);
825 impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
831void ScopedFakeTestPartResultReporter::ReportTestPartResult(
832 const TestPartResult& result) {
833 result_->Append(result);
848 return GetTypeId<Test>();
858static AssertionResult HasOneFailure(
const char* ,
861 const TestPartResultArray& results,
862 TestPartResult::Type
type,
863 const std::string& substr) {
864 const std::string expected(
type == TestPartResult::kFatalFailure ?
866 "1 non-fatal failure");
868 if (results.size() != 1) {
869 msg <<
"Expected: " << expected <<
"\n"
870 <<
" Actual: " << results.size() <<
" failures";
871 for (
int i = 0;
i < results.size();
i++) {
872 msg <<
"\n" << results.GetTestPartResult(
i);
877 const TestPartResult& r = results.GetTestPartResult(0);
878 if (r.type() !=
type) {
884 if (strstr(r.message(), substr.c_str()) ==
nullptr) {
897SingleFailureChecker::SingleFailureChecker(
const TestPartResultArray* results,
898 TestPartResult::Type
type,
899 const std::string& substr)
900 : results_(results), type_(
type), substr_(substr) {}
906SingleFailureChecker::~SingleFailureChecker() {
910DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
911 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
913void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
914 const TestPartResult& result) {
915 unit_test_->current_test_result()->AddTestPartResult(result);
916 unit_test_->listeners()->repeater()->OnTestPartResult(result);
919DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
920 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
922void DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
923 const TestPartResult& result) {
924 unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
928TestPartResultReporterInterface*
929UnitTestImpl::GetGlobalTestPartResultReporter() {
931 return global_test_part_result_repoter_;
935void UnitTestImpl::SetGlobalTestPartResultReporter(
936 TestPartResultReporterInterface* reporter) {
938 global_test_part_result_repoter_ = reporter;
942TestPartResultReporterInterface*
943UnitTestImpl::GetTestPartResultReporterForCurrentThread() {
944 return per_thread_test_part_result_reporter_.get();
948void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
949 TestPartResultReporterInterface* reporter) {
950 per_thread_test_part_result_reporter_.set(reporter);
954int UnitTestImpl::successful_test_suite_count()
const {
955 return CountIf(test_suites_, TestSuitePassed);
959int UnitTestImpl::failed_test_suite_count()
const {
960 return CountIf(test_suites_, TestSuiteFailed);
964int UnitTestImpl::total_test_suite_count()
const {
965 return static_cast<int>(test_suites_.size());
970int UnitTestImpl::test_suite_to_run_count()
const {
971 return CountIf(test_suites_, ShouldRunTestSuite);
975int UnitTestImpl::successful_test_count()
const {
980int UnitTestImpl::skipped_test_count()
const {
985int UnitTestImpl::failed_test_count()
const {
990int UnitTestImpl::reportable_disabled_test_count()
const {
991 return SumOverTestSuiteList(test_suites_,
996int UnitTestImpl::disabled_test_count()
const {
1001int UnitTestImpl::reportable_test_count()
const {
1006int UnitTestImpl::total_test_count()
const {
1011int UnitTestImpl::test_to_run_count()
const {
1025std::string UnitTestImpl::CurrentOsStackTraceExceptTop(
int skip_count) {
1026 return os_stack_trace_getter()->CurrentStackTrace(
1027 static_cast<int>(
GTEST_FLAG(stack_trace_depth)),
1041 return std::chrono::duration_cast<std::chrono::milliseconds>(
1042 std::chrono::steady_clock::now() - start_)
1047 std::chrono::steady_clock::time_point start_;
1054 return std::chrono::duration_cast<std::chrono::milliseconds>(
1055 std::chrono::system_clock::now() -
1056 std::chrono::system_clock::from_time_t(0))
1064#if GTEST_OS_WINDOWS_MOBILE
1069LPCWSTR String::AnsiToUtf16(
const char* ansi) {
1070 if (!ansi)
return nullptr;
1071 const int length = strlen(ansi);
1072 const int unicode_length =
1073 MultiByteToWideChar(CP_ACP, 0, ansi, length,
nullptr, 0);
1074 WCHAR* unicode =
new WCHAR[unicode_length + 1];
1075 MultiByteToWideChar(CP_ACP, 0, ansi, length,
1076 unicode, unicode_length);
1077 unicode[unicode_length] = 0;
1085const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
1086 if (!utf16_str)
return nullptr;
1087 const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
nullptr,
1088 0,
nullptr,
nullptr);
1089 char* ansi =
new char[ansi_length + 1];
1090 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, ansi, ansi_length,
nullptr,
1092 ansi[ansi_length] = 0;
1104bool String::CStringEquals(
const char * lhs,
const char * rhs) {
1105 if (lhs ==
nullptr)
return rhs ==
nullptr;
1107 if (rhs ==
nullptr)
return false;
1109 return strcmp(lhs, rhs) == 0;
1112#if GTEST_HAS_STD_WSTRING
1116static void StreamWideCharsToMessage(
const wchar_t* wstr,
size_t length,
1118 for (
size_t i = 0;
i != length; ) {
1119 if (wstr[
i] != L
'\0') {
1120 *msg << WideStringToUtf8(wstr + i, static_cast<int>(length -
i));
1121 while (
i != length && wstr[
i] != L
'\0')
1133 ::std::vector< ::std::string>*
dest) {
1134 ::std::vector< ::std::string> parsed;
1135 ::std::string::size_type pos = 0;
1137 const ::std::string::size_type colon = str.find(delimiter, pos);
1138 if (colon == ::std::string::npos) {
1139 parsed.push_back(str.substr(pos));
1142 parsed.push_back(str.substr(pos, colon - pos));
1156Message::Message() : ss_(new ::
std::stringstream) {
1159 *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
1171#if GTEST_HAS_STD_WSTRING
1175 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
1188AssertionResult::AssertionResult(
const AssertionResult& other)
1189 : success_(other.success_),
1190 message_(other.message_.get() != nullptr
1191 ? new ::
std::string(*other.message_)
1192 : static_cast< ::
std::string*>(nullptr)) {}
1195void AssertionResult::swap(AssertionResult& other) {
1197 swap(success_, other.success_);
1198 swap(message_, other.message_);
1203 AssertionResult negation(!success_);
1204 if (message_.get() !=
nullptr) negation << *message_;
1210 return AssertionResult(
true);
1215 return AssertionResult(
false);
1226namespace edit_distance {
1228 const std::vector<size_t>& right) {
1229 std::vector<std::vector<double> > costs(
1230 left.size() + 1, std::vector<double>(right.size() + 1));
1231 std::vector<std::vector<EditType> > best_move(
1232 left.size() + 1, std::vector<EditType>(right.size() + 1));
1235 for (
size_t l_i = 0; l_i < costs.size(); ++l_i) {
1236 costs[l_i][0] =
static_cast<double>(l_i);
1240 for (
size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
1241 costs[0][r_i] =
static_cast<double>(r_i);
1242 best_move[0][r_i] =
kAdd;
1245 for (
size_t l_i = 0; l_i < left.size(); ++l_i) {
1246 for (
size_t r_i = 0; r_i < right.size(); ++r_i) {
1247 if (left[l_i] == right[r_i]) {
1249 costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
1250 best_move[l_i + 1][r_i + 1] =
kMatch;
1254 const double add = costs[l_i + 1][r_i];
1255 const double remove = costs[l_i][r_i + 1];
1256 const double replace = costs[l_i][r_i];
1257 if (add < remove && add < replace) {
1258 costs[l_i + 1][r_i + 1] = add + 1;
1259 best_move[l_i + 1][r_i + 1] =
kAdd;
1260 }
else if (remove < add && remove < replace) {
1261 costs[l_i + 1][r_i + 1] = remove + 1;
1262 best_move[l_i + 1][r_i + 1] =
kRemove;
1266 costs[l_i + 1][r_i + 1] = replace + 1.00001;
1267 best_move[l_i + 1][r_i + 1] =
kReplace;
1273 std::vector<EditType> best_path;
1274 for (
size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
1275 EditType move = best_move[l_i][r_i];
1276 best_path.push_back(move);
1277 l_i -= move !=
kAdd;
1280 std::reverse(best_path.begin(), best_path.end());
1287class InternalStrings {
1289 size_t GetId(
const std::string& str) {
1290 IdMap::iterator it = ids_.find(str);
1291 if (it != ids_.end())
return it->second;
1292 size_t id = ids_.size();
1293 return ids_[str] = id;
1297 typedef std::map<std::string, size_t> IdMap;
1304 const std::vector<std::string>& left,
1305 const std::vector<std::string>& right) {
1306 std::vector<size_t> left_ids, right_ids;
1308 InternalStrings intern_table;
1309 for (
size_t i = 0;
i < left.size(); ++
i) {
1310 left_ids.push_back(intern_table.GetId(left[
i]));
1312 for (
size_t i = 0;
i < right.size(); ++
i) {
1313 right_ids.push_back(intern_table.GetId(right[
i]));
1327 Hunk(
size_t left_start,
size_t right_start)
1328 : left_start_(left_start),
1329 right_start_(right_start),
1334 void PushLine(
char edit,
const char* line) {
1339 hunk_.push_back(std::make_pair(
' ', line));
1343 hunk_removes_.push_back(std::make_pair(
'-', line));
1347 hunk_adds_.push_back(std::make_pair(
'+', line));
1352 void PrintTo(std::ostream* os) {
1355 for (std::list<std::pair<char, const char*> >::const_iterator it =
1357 it != hunk_.end(); ++it) {
1358 *os << it->first << it->second <<
"\n";
1362 bool has_edits()
const {
return adds_ || removes_; }
1366 hunk_.splice(hunk_.end(), hunk_removes_);
1367 hunk_.splice(hunk_.end(), hunk_adds_);
1374 void PrintHeader(std::ostream* ss)
const {
1377 *ss <<
"-" << left_start_ <<
"," << (removes_ + common_);
1379 if (removes_ && adds_) {
1383 *ss <<
"+" << right_start_ <<
"," << (adds_ + common_);
1388 size_t left_start_, right_start_;
1389 size_t adds_, removes_, common_;
1390 std::list<std::pair<char, const char*> > hunk_, hunk_adds_, hunk_removes_;
1403 const std::vector<std::string>& right,
1407 size_t l_i = 0, r_i = 0, edit_i = 0;
1408 std::stringstream ss;
1409 while (edit_i < edits.size()) {
1411 while (edit_i < edits.size() && edits[edit_i] ==
kMatch) {
1418 const size_t prefix_context = std::min(l_i, context);
1419 Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
1420 for (
size_t i = prefix_context;
i > 0; --
i) {
1421 hunk.PushLine(
' ', left[l_i -
i].c_str());
1426 size_t n_suffix = 0;
1427 for (; edit_i < edits.size(); ++edit_i) {
1428 if (n_suffix >= context) {
1430 auto it = edits.begin() +
static_cast<int>(edit_i);
1431 while (it != edits.end() && *it ==
kMatch) ++it;
1432 if (it == edits.end() ||
1433 static_cast<size_t>(it - edits.begin()) - edit_i >= context) {
1441 n_suffix = edit ==
kMatch ? n_suffix + 1 : 0;
1444 hunk.PushLine(edit ==
kMatch ?
' ' :
'-', left[l_i].c_str());
1447 hunk.PushLine(
'+', right[r_i].c_str());
1451 l_i += edit !=
kAdd;
1455 if (!hunk.has_edits()) {
1472std::vector<std::string> SplitEscapedString(
const std::string& str) {
1473 std::vector<std::string> lines;
1474 size_t start = 0, end = str.size();
1475 if (end > 2 && str[0] ==
'"' && str[end - 1] ==
'"') {
1479 bool escaped =
false;
1480 for (
size_t i = start;
i + 1 < end; ++
i) {
1483 if (str[
i] ==
'n') {
1484 lines.push_back(str.substr(start,
i - start - 1));
1488 escaped = str[
i] ==
'\\';
1491 lines.push_back(str.substr(start, end - start));
1513 const char* rhs_expression,
1514 const std::string& lhs_value,
1515 const std::string& rhs_value,
1516 bool ignoring_case) {
1518 msg <<
"Expected equality of these values:";
1519 msg <<
"\n " << lhs_expression;
1520 if (lhs_value != lhs_expression) {
1521 msg <<
"\n Which is: " << lhs_value;
1523 msg <<
"\n " << rhs_expression;
1524 if (rhs_value != rhs_expression) {
1525 msg <<
"\n Which is: " << rhs_value;
1528 if (ignoring_case) {
1529 msg <<
"\nIgnoring case";
1532 if (!lhs_value.empty() && !rhs_value.empty()) {
1533 const std::vector<std::string> lhs_lines =
1534 SplitEscapedString(lhs_value);
1535 const std::vector<std::string> rhs_lines =
1536 SplitEscapedString(rhs_value);
1537 if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
1538 msg <<
"\nWith diff:\n"
1548 const AssertionResult& assertion_result,
1549 const char* expression_text,
1550 const char* actual_predicate_value,
1551 const char* expected_predicate_value) {
1552 const char* actual_message = assertion_result.message();
1554 msg <<
"Value of: " << expression_text
1555 <<
"\n Actual: " << actual_predicate_value;
1556 if (actual_message[0] !=
'\0')
1557 msg <<
" (" << actual_message <<
")";
1558 msg <<
"\nExpected: " << expected_predicate_value;
1565 const char* abs_error_expr,
1569 const double diff = fabs(val1 - val2);
1573 const double min_abs = std::min(fabs(val1), fabs(val2));
1575 const double epsilon =
1576 nextafter(min_abs, std::numeric_limits<double>::infinity()) - min_abs;
1583 if (!(std::isnan)(val1) && !(std::isnan)(val2) && abs_error > 0 &&
1584 abs_error < epsilon) {
1586 <<
"The difference between " << expr1 <<
" and " << expr2 <<
" is "
1587 << diff <<
", where\n"
1588 << expr1 <<
" evaluates to " << val1 <<
",\n"
1589 << expr2 <<
" evaluates to " << val2 <<
".\nThe abs_error parameter "
1590 << abs_error_expr <<
" evaluates to " << abs_error
1591 <<
" which is smaller than the minimum distance between doubles for "
1592 "numbers of this magnitude which is "
1594 <<
", thus making this EXPECT_NEAR check equivalent to "
1595 "EXPECT_EQUAL. Consider using EXPECT_DOUBLE_EQ instead.";
1598 <<
"The difference between " << expr1 <<
" and " << expr2
1599 <<
" is " << diff <<
", which exceeds " << abs_error_expr <<
", where\n"
1600 << expr1 <<
" evaluates to " << val1 <<
",\n"
1601 << expr2 <<
" evaluates to " << val2 <<
", and\n"
1602 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1607template <
typename RawType>
1619 if (lhs.AlmostEquals(rhs)) {
1627 ::std::stringstream val1_ss;
1628 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1631 ::std::stringstream val2_ss;
1632 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1636 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n"
1645AssertionResult
FloatLE(
const char* expr1,
const char* expr2,
1646 float val1,
float val2) {
1647 return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
1652AssertionResult
DoubleLE(
const char* expr1,
const char* expr2,
1653 double val1,
double val2) {
1654 return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
1661 const char* rhs_expression,
1677 const char* rhs_expression,
1693 const char* s2_expression,
1700 << s2_expression <<
"), actual: \""
1701 << s1 <<
"\" vs \"" << s2 <<
"\"";
1707 const char* s2_expression,
1714 <<
"Expected: (" << s1_expression <<
") != ("
1715 << s2_expression <<
") (ignoring case), actual: \""
1716 << s1 <<
"\" vs \"" << s2 <<
"\"";
1730bool IsSubstringPred(
const char* needle,
const char* haystack) {
1731 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1733 return strstr(haystack, needle) !=
nullptr;
1736bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1737 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1739 return wcsstr(haystack, needle) !=
nullptr;
1743template <
typename StringType>
1744bool IsSubstringPred(
const StringType& needle,
1745 const StringType& haystack) {
1746 return haystack.find(needle) != StringType::npos;
1753template <
typename StringType>
1754AssertionResult IsSubstringImpl(
1755 bool expected_to_be_substring,
1756 const char* needle_expr,
const char* haystack_expr,
1757 const StringType& needle,
const StringType& haystack) {
1758 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1761 const bool is_wide_string =
sizeof(needle[0]) > 1;
1762 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1764 <<
"Value of: " << needle_expr <<
"\n"
1765 <<
" Actual: " << begin_string_quote << needle <<
"\"\n"
1766 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1767 <<
"a substring of " << haystack_expr <<
"\n"
1768 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1778 const char* needle_expr,
const char* haystack_expr,
1779 const char* needle,
const char* haystack) {
1780 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1784 const char* needle_expr,
const char* haystack_expr,
1785 const wchar_t* needle,
const wchar_t* haystack) {
1786 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1790 const char* needle_expr,
const char* haystack_expr,
1791 const char* needle,
const char* haystack) {
1792 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1796 const char* needle_expr,
const char* haystack_expr,
1797 const wchar_t* needle,
const wchar_t* haystack) {
1798 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1802 const char* needle_expr,
const char* haystack_expr,
1803 const ::std::string& needle, const ::std::string& haystack) {
1804 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1808 const char* needle_expr,
const char* haystack_expr,
1809 const ::std::string& needle, const ::std::string& haystack) {
1810 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1813#if GTEST_HAS_STD_WSTRING
1815 const char* needle_expr,
const char* haystack_expr,
1816 const ::std::wstring& needle, const ::std::wstring& haystack) {
1817 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1821 const char* needle_expr,
const char* haystack_expr,
1822 const ::std::wstring& needle, const ::std::wstring& haystack) {
1823 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1834AssertionResult HRESULTFailureHelper(
const char* expr,
1835 const char* expected,
1837# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
1840 const char error_text[] =
"";
1847 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1848 FORMAT_MESSAGE_IGNORE_INSERTS;
1849 const DWORD kBufSize = 4096;
1851 char error_text[kBufSize] = {
'\0' };
1852 DWORD message_length = ::FormatMessageA(kFlags,
1854 static_cast<DWORD
>(hr),
1860 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1862 error_text[message_length - 1] =
'\0';
1869 <<
"Expected: " << expr <<
" " << expected <<
".\n"
1870 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1875AssertionResult IsHRESULTSuccess(
const char* expr,
long hr) {
1876 if (SUCCEEDED(hr)) {
1879 return HRESULTFailureHelper(expr,
"succeeds", hr);
1882AssertionResult IsHRESULTFailure(
const char* expr,
long hr) {
1886 return HRESULTFailureHelper(expr,
"fails", hr);
1919 const uint32_t low_bits = *bits & ((
static_cast<uint32_t
>(1) << n) - 1);
1938 str[0] =
static_cast<char>(code_point);
1941 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1942 str[0] =
static_cast<char>(0xC0 | code_point);
1945 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1946 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1947 str[0] =
static_cast<char>(0xE0 | code_point);
1950 str[3] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1951 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1952 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1953 str[0] =
static_cast<char>(0xF0 | code_point);
1966 return sizeof(wchar_t) == 2 &&
1967 (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
1973 const auto first_u =
static_cast<uint32_t
>(first);
1974 const auto second_u =
static_cast<uint32_t
>(second);
1975 const uint32_t mask = (1 << 10) - 1;
1976 return (
sizeof(
wchar_t) == 2)
1977 ? (((first_u & mask) << 10) | (second_u & mask)) + 0x10000
1998 if (num_chars == -1)
1999 num_chars =
static_cast<int>(wcslen(str));
2001 ::std::stringstream stream;
2002 for (
int i = 0;
i < num_chars; ++
i) {
2003 uint32_t unicode_code_point;
2005 if (str[
i] == L
'\0') {
2012 unicode_code_point =
static_cast<uint32_t
>(str[
i]);
2023 if (wide_c_str ==
nullptr)
return "(null)";
2035 if (lhs ==
nullptr)
return rhs ==
nullptr;
2037 if (rhs ==
nullptr)
return false;
2039 return wcscmp(lhs, rhs) == 0;
2044 const char* rhs_expression,
2046 const wchar_t* rhs) {
2060 const char* s2_expression,
2062 const wchar_t* s2) {
2068 << s2_expression <<
"), actual: "
2080 if (lhs ==
nullptr)
return rhs ==
nullptr;
2081 if (rhs ==
nullptr)
return false;
2098 const wchar_t* rhs) {
2099 if (lhs ==
nullptr)
return rhs ==
nullptr;
2101 if (rhs ==
nullptr)
return false;
2104 return _wcsicmp(lhs, rhs) == 0;
2105#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
2106 return wcscasecmp(lhs, rhs) == 0;
2112 left = towlower(
static_cast<wint_t
>(*lhs++));
2113 right = towlower(
static_cast<wint_t
>(*rhs++));
2114 }
while (left && left == right);
2115 return left == right;
2122 const std::string& str,
const std::string& suffix) {
2123 const size_t str_len = str.length();
2124 const size_t suffix_len = suffix.length();
2125 return (str_len >= suffix_len) &&
2137 std::stringstream ss;
2138 ss << std::setfill(
'0') << std::setw(width) <<
value;
2144 std::stringstream ss;
2145 ss << std::hex << std::uppercase <<
value;
2156 std::stringstream ss;
2157 ss << std::setfill(
'0') << std::setw(2) << std::hex << std::uppercase
2158 <<
static_cast<unsigned int>(
value);
2165 const ::std::string& str = ss->str();
2166 const char*
const start = str.c_str();
2167 const char*
const end = start + str.length();
2170 result.reserve(
static_cast<size_t>(2 * (end - start)));
2171 for (
const char*
ch = start;
ch != end; ++
ch) {
2186 const std::string user_msg_string = user_msg.
GetString();
2187 if (user_msg_string.empty()) {
2190 if (gtest_msg.empty()) {
2191 return user_msg_string;
2193 return gtest_msg +
"\n" + user_msg_string;
2202 : death_test_count_(0), start_timestamp_(0), elapsed_time_(0) {}
2214 return test_part_results_.at(
static_cast<size_t>(
i));
2223 return test_properties_.at(
static_cast<size_t>(
i));
2227void TestResult::ClearTestPartResults() {
2228 test_part_results_.clear();
2232void TestResult::AddTestPartResult(
const TestPartResult& test_part_result) {
2233 test_part_results_.push_back(test_part_result);
2239void TestResult::RecordProperty(
const std::string& xml_element,
2240 const TestProperty& test_property) {
2241 if (!ValidateTestProperty(xml_element, test_property)) {
2245 const std::vector<TestProperty>::iterator property_with_matching_key =
2246 std::find_if(test_properties_.begin(), test_properties_.end(),
2247 internal::TestPropertyKeyIs(test_property.key()));
2248 if (property_with_matching_key == test_properties_.end()) {
2249 test_properties_.push_back(test_property);
2252 property_with_matching_key->SetValue(test_property.value());
2257static const char*
const kReservedTestSuitesAttributes[] = {
2270static const char*
const kReservedTestSuiteAttributes[] = {
2271 "disabled",
"errors",
"failures",
"name",
2272 "tests",
"time",
"timestamp",
"skipped"};
2275static const char*
const kReservedTestCaseAttributes[] = {
2276 "classname",
"name",
"status",
"time",
"type_param",
2277 "value_param",
"file",
"line"};
2281static const char*
const kReservedOutputTestCaseAttributes[] = {
2282 "classname",
"name",
"status",
"time",
"type_param",
2283 "value_param",
"file",
"line",
"result",
"timestamp"};
2285template <
size_t kSize>
2287 return std::vector<std::string>(array, array + kSize);
2290static std::vector<std::string> GetReservedAttributesForElement(
2291 const std::string& xml_element) {
2292 if (xml_element ==
"testsuites") {
2294 }
else if (xml_element ==
"testsuite") {
2296 }
else if (xml_element ==
"testcase") {
2299 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2302 return std::vector<std::string>();
2306static std::vector<std::string> GetReservedOutputAttributesForElement(
2307 const std::string& xml_element) {
2308 if (xml_element ==
"testsuites") {
2310 }
else if (xml_element ==
"testsuite") {
2312 }
else if (xml_element ==
"testcase") {
2315 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2318 return std::vector<std::string>();
2321static std::string FormatWordList(
const std::vector<std::string>& words) {
2323 for (
size_t i = 0;
i < words.size(); ++
i) {
2324 if (
i > 0 && words.size() > 2) {
2327 if (
i == words.size() - 1) {
2328 word_list <<
"and ";
2330 word_list <<
"'" << words[
i] <<
"'";
2332 return word_list.GetString();
2335static bool ValidateTestPropertyName(
2336 const std::string& property_name,
2337 const std::vector<std::string>& reserved_names) {
2338 if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
2339 reserved_names.end()) {
2340 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
2341 <<
" (" << FormatWordList(reserved_names)
2350bool TestResult::ValidateTestProperty(
const std::string& xml_element,
2351 const TestProperty& test_property) {
2352 return ValidateTestPropertyName(test_property.key(),
2353 GetReservedAttributesForElement(xml_element));
2357void TestResult::Clear() {
2358 test_part_results_.clear();
2359 test_properties_.clear();
2360 death_test_count_ = 0;
2365static bool TestPartSkipped(
const TestPartResult& result) {
2366 return result.skipped();
2371 return !
Failed() && CountIf(test_part_results_, TestPartSkipped) > 0;
2384static bool TestPartFatallyFailed(
const TestPartResult& result) {
2385 return result.fatally_failed();
2390 return CountIf(test_part_results_, TestPartFatallyFailed) > 0;
2394static bool TestPartNonfatallyFailed(
const TestPartResult& result) {
2395 return result.nonfatally_failed();
2400 return CountIf(test_part_results_, TestPartNonfatallyFailed) > 0;
2406 return static_cast<int>(test_part_results_.size());
2411 return static_cast<int>(test_properties_.size());
2449 value_message <<
value;
2474bool Test::HasSameFixtureClass() {
2475 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
2476 const TestSuite*
const test_suite = impl->current_test_suite();
2479 const TestInfo*
const first_test_info = test_suite->test_info_list()[0];
2480 const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
2481 const char*
const first_test_name = first_test_info->name();
2484 const TestInfo*
const this_test_info = impl->current_test_info();
2485 const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
2486 const char*
const this_test_name = this_test_info->name();
2488 if (this_fixture_id != first_fixture_id) {
2494 if (first_is_TEST || this_is_TEST) {
2501 const char*
const TEST_name =
2502 first_is_TEST ? first_test_name : this_test_name;
2503 const char*
const TEST_F_name =
2504 first_is_TEST ? this_test_name : first_test_name;
2507 <<
"All tests in the same test suite must use the same test fixture\n"
2508 <<
"class, so mixing TEST_F and TEST in the same test suite is\n"
2509 <<
"illegal. In test suite " << this_test_info->test_suite_name()
2511 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n"
2512 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n"
2513 <<
"want to change the TEST to TEST_F or move it to another test\n"
2519 <<
"All tests in the same test suite must use the same test fixture\n"
2520 <<
"class. However, in test suite "
2521 << this_test_info->test_suite_name() <<
",\n"
2522 <<
"you defined test " << first_test_name <<
" and test "
2523 << this_test_name <<
"\n"
2524 <<
"using two different test fixture classes. This can happen if\n"
2525 <<
"the two classes are from different namespaces or translation\n"
2526 <<
"units and have the same name. You should probably rename one\n"
2527 <<
"of the classes to put the tests into different test suites.";
2541static std::string* FormatSehExceptionMessage(DWORD exception_code,
2542 const char* location) {
2544 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2545 exception_code << std::setbase(10) <<
" thrown in " << location <<
".";
2547 return new std::string(
message.GetString());
2554#if GTEST_HAS_EXCEPTIONS
2557static std::string FormatCxxExceptionMessage(
const char* description,
2558 const char* location) {
2560 if (description !=
nullptr) {
2561 message <<
"C++ exception with description \"" << description <<
"\"";
2563 message <<
"Unknown C++ exception";
2565 message <<
" thrown in " << location <<
".";
2570static std::string PrintTestPartResultToString(
2571 const TestPartResult& test_part_result);
2573GoogleTestFailureException::GoogleTestFailureException(
2574 const TestPartResult& failure)
2575 : ::
std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}
2587template <
class T,
typename Result>
2589 T*
object, Result (T::*method)(),
const char* location) {
2592 return (object->*method)();
2593 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2594 GetExceptionCode())) {
2598 std::string* exception_message = FormatSehExceptionMessage(
2599 GetExceptionCode(), location);
2601 *exception_message);
2602 delete exception_message;
2603 return static_cast<Result
>(0);
2607 return (object->*method)();
2614template <
class T,
typename Result>
2616 T*
object, Result (T::*method)(),
const char* location) {
2640 if (internal::GetUnitTestImpl()->catch_exceptions()) {
2641#if GTEST_HAS_EXCEPTIONS
2644 }
catch (
const AssertionException&) {
2646 }
catch (
const internal::GoogleTestFailureException&) {
2651 }
catch (
const std::exception& e) {
2653 TestPartResult::kFatalFailure,
2654 FormatCxxExceptionMessage(e.what(), location));
2657 TestPartResult::kFatalFailure,
2658 FormatCxxExceptionMessage(
nullptr, location));
2660 return static_cast<Result
>(0);
2665 return (object->*method)();
2673 if (!HasSameFixtureClass())
return;
2675 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
2676 impl->os_stack_trace_getter()->UponLeavingGTest();
2680 if (!HasFatalFailure() && !IsSkipped()) {
2681 impl->os_stack_trace_getter()->UponLeavingGTest();
2683 this, &Test::TestBody,
"the test body");
2689 impl->os_stack_trace_getter()->UponLeavingGTest();
2691 this, &Test::TearDown,
"TearDown()");
2695bool Test::HasFatalFailure() {
2696 return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();
2700bool Test::HasNonfatalFailure() {
2701 return internal::GetUnitTestImpl()->current_test_result()->
2702 HasNonfatalFailure();
2706bool Test::IsSkipped() {
2707 return internal::GetUnitTestImpl()->current_test_result()->Skipped();
2714TestInfo::TestInfo(
const std::string& a_test_suite_name,
2715 const std::string& a_name,
const char* a_type_param,
2716 const char* a_value_param,
2720 : test_suite_name_(a_test_suite_name),
2722 type_param_(a_type_param ? new
std::string(a_type_param) : nullptr),
2723 value_param_(a_value_param ? new
std::string(a_value_param) : nullptr),
2724 location_(a_code_location),
2725 fixture_class_id_(fixture_class_id),
2727 is_disabled_(false),
2728 matches_filter_(false),
2729 is_in_another_shard_(false),
2757 const char* test_suite_name,
const char* name,
const char* type_param,
2762 new TestInfo(test_suite_name, name, type_param, value_param,
2763 code_location, fixture_class_id, factory);
2764 GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);
2772 <<
"Attempted redefinition of test suite " << test_suite_name <<
".\n"
2773 <<
"All tests in the same test suite must use the same test fixture\n"
2774 <<
"class. However, in test suite " << test_suite_name <<
", you tried\n"
2775 <<
"to define a test using a fixture class different from the one\n"
2776 <<
"used earlier. This can happen if the two fixture classes are\n"
2777 <<
"from different namespaces and have the same name. You should\n"
2778 <<
"probably rename one of the classes to put the tests into different\n"
2802 explicit TestNameIs(
const char* name)
2806 bool operator()(
const TestInfo * test_info)
const {
2807 return test_info && test_info->name() == name_;
2821void UnitTestImpl::RegisterParameterizedTests() {
2822 if (!parameterized_tests_registered_) {
2823 parameterized_test_registry_.RegisterTests();
2824 type_parameterized_test_registry_.CheckForInstantiations();
2825 parameterized_tests_registered_ =
true;
2833void TestInfo::Run() {
2834 if (!should_run_)
return;
2838 impl->set_current_test_info(
this);
2846 internal::Timer timer;
2848 impl->os_stack_trace_getter()->UponLeavingGTest();
2853 "the test fixture's constructor");
2864 if (test !=
nullptr) {
2866 impl->os_stack_trace_getter()->UponLeavingGTest();
2868 test, &Test::DeleteSelf_,
"the test fixture's destructor");
2871 result_.set_elapsed_time(timer.Elapsed());
2874 repeater->OnTestEnd(*
this);
2878 impl->set_current_test_info(
nullptr);
2882void TestInfo::Skip() {
2883 if (!should_run_)
return;
2886 impl->set_current_test_info(
this);
2893 const TestPartResult test_part_result =
2894 TestPartResult(TestPartResult::kSkip, this->
file(), this->
line(),
"");
2895 impl->GetTestPartResultReporterForCurrentThread()->ReportTestPartResult(
2899 repeater->OnTestEnd(*
this);
2900 impl->set_current_test_info(
nullptr);
2907 return CountIf(test_info_list_, TestPassed);
2912 return CountIf(test_info_list_, TestSkipped);
2917 return CountIf(test_info_list_, TestFailed);
2922 return CountIf(test_info_list_, TestReportableDisabled);
2927 return CountIf(test_info_list_, TestDisabled);
2932 return CountIf(test_info_list_, TestReportable);
2937 return CountIf(test_info_list_, ShouldRunTest);
2942 return static_cast<int>(test_info_list_.size());
2958 type_param_(a_type_param ? new
std::string(a_type_param) : nullptr),
2959 set_up_tc_(set_up_tc),
2960 tear_down_tc_(tear_down_tc),
2962 start_timestamp_(0),
2968 ForEach(test_info_list_, internal::Delete<TestInfo>);
2974 const int index = GetElementOr(test_indices_,
i, -1);
2975 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(index)];
2980TestInfo* TestSuite::GetMutableTestInfo(
int i) {
2981 const int index = GetElementOr(test_indices_,
i, -1);
2982 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(index)];
2987void TestSuite::AddTestInfo(TestInfo* test_info) {
2988 test_info_list_.push_back(test_info);
2989 test_indices_.push_back(
static_cast<int>(test_indices_.size()));
2993void TestSuite::Run() {
2994 if (!should_run_)
return;
2997 impl->set_current_test_suite(
this);
3004#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3005 repeater->OnTestCaseStart(*
this);
3008 impl->os_stack_trace_getter()->UponLeavingGTest();
3010 this, &TestSuite::RunSetUpTestSuite,
"SetUpTestSuite()");
3013 internal::Timer timer;
3015 GetMutableTestInfo(
i)->Run();
3018 GetMutableTestInfo(j)->Skip();
3023 elapsed_time_ = timer.Elapsed();
3025 impl->os_stack_trace_getter()->UponLeavingGTest();
3027 this, &TestSuite::RunTearDownTestSuite,
"TearDownTestSuite()");
3030 repeater->OnTestSuiteEnd(*
this);
3032#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3033 repeater->OnTestCaseEnd(*
this);
3036 impl->set_current_test_suite(
nullptr);
3040void TestSuite::Skip() {
3041 if (!should_run_)
return;
3044 impl->set_current_test_suite(
this);
3051#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3052 repeater->OnTestCaseStart(*
this);
3056 GetMutableTestInfo(
i)->Skip();
3060 repeater->OnTestSuiteEnd(*
this);
3062#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3063 repeater->OnTestCaseEnd(*
this);
3066 impl->set_current_test_suite(
nullptr);
3070void TestSuite::ClearResult() {
3071 ad_hoc_test_result_.Clear();
3072 ForEach(test_info_list_, TestInfo::ClearTestResult);
3076void TestSuite::ShuffleTests(internal::Random* random) {
3077 Shuffle(random, &test_indices_);
3081void TestSuite::UnshuffleTests() {
3082 for (
size_t i = 0;
i < test_indices_.size();
i++) {
3083 test_indices_[
i] =
static_cast<int>(
i);
3092static std::string FormatCountableNoun(
int count,
3093 const char * singular_form,
3094 const char * plural_form) {
3096 (
count == 1 ? singular_form : plural_form);
3100static std::string FormatTestCount(
int test_count) {
3101 return FormatCountableNoun(test_count,
"test",
"tests");
3105static std::string FormatTestSuiteCount(
int test_suite_count) {
3106 return FormatCountableNoun(test_suite_count,
"test suite",
"test suites");
3113static const char * TestPartResultTypeToString(TestPartResult::Type
type) {
3115 case TestPartResult::kSkip:
3117 case TestPartResult::kSuccess:
3120 case TestPartResult::kNonFatalFailure:
3121 case TestPartResult::kFatalFailure:
3128 return "Unknown result type";
3134enum class GTestColor { kDefault, kRed, kGreen, kYellow };
3138static std::string PrintTestPartResultToString(
3139 const TestPartResult& test_part_result) {
3142 test_part_result.line_number())
3143 <<
" " << TestPartResultTypeToString(test_part_result.type())
3144 << test_part_result.message()).GetString();
3148static void PrintTestPartResult(
const TestPartResult& test_part_result) {
3149 const std::string& result =
3150 PrintTestPartResultToString(test_part_result);
3151 printf(
"%s\n", result.c_str());
3157#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
3161 ::OutputDebugStringA(result.c_str());
3162 ::OutputDebugStringA(
"\n");
3167#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
3168 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
3171static WORD GetColorAttribute(GTestColor color) {
3173 case GTestColor::kRed:
3174 return FOREGROUND_RED;
3175 case GTestColor::kGreen:
3176 return FOREGROUND_GREEN;
3177 case GTestColor::kYellow:
3178 return FOREGROUND_RED | FOREGROUND_GREEN;
3183static int GetBitOffset(
WORD color_mask) {
3184 if (color_mask == 0)
return 0;
3187 while ((color_mask & 1) == 0) {
3194static WORD GetNewColor(GTestColor color,
WORD old_color_attrs) {
3196 static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
3197 BACKGROUND_RED | BACKGROUND_INTENSITY;
3198 static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
3199 FOREGROUND_RED | FOREGROUND_INTENSITY;
3200 const WORD existing_bg = old_color_attrs & background_mask;
3203 GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY;
3204 static const int bg_bitOffset = GetBitOffset(background_mask);
3205 static const int fg_bitOffset = GetBitOffset(foreground_mask);
3207 if (((new_color & background_mask) >> bg_bitOffset) ==
3208 ((new_color & foreground_mask) >> fg_bitOffset)) {
3209 new_color ^= FOREGROUND_INTENSITY;
3218static const char* GetAnsiColorCode(GTestColor color) {
3220 case GTestColor::kRed:
3222 case GTestColor::kGreen:
3224 case GTestColor::kYellow:
3235 const char*
const gtest_color =
GTEST_FLAG(color).c_str();
3238#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
3241 return stdout_is_tty;
3245 const bool term_supports_color =
3257 return stdout_is_tty && term_supports_color;
3276static
void ColoredPrintf(GTestColor color,
const char *fmt, ...) {
3278 va_start(args, fmt);
3280#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \
3281 GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM)
3284 static const bool in_color_mode =
3286 const bool use_color = in_color_mode && (color != GTestColor::kDefault);
3295#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
3296 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
3297 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
3300 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
3301 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
3302 const WORD old_color_attrs = buffer_info.wAttributes;
3303 const WORD new_color = GetNewColor(color, old_color_attrs);
3309 SetConsoleTextAttribute(stdout_handle, new_color);
3315 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
3317 printf(
"\033[0;3%sm", GetAnsiColorCode(color));
3326static const char kTypeParamLabel[] =
"TypeParam";
3327static const char kValueParamLabel[] =
"GetParam()";
3329static void PrintFullTestCommentIfPresent(
const TestInfo& test_info) {
3330 const char*
const type_param = test_info.type_param();
3331 const char*
const value_param = test_info.value_param();
3333 if (type_param !=
nullptr || value_param !=
nullptr) {
3335 if (type_param !=
nullptr) {
3336 printf(
"%s = %s", kTypeParamLabel, type_param);
3337 if (value_param !=
nullptr) printf(
" and ");
3339 if (value_param !=
nullptr) {
3340 printf(
"%s = %s", kValueParamLabel, value_param);
3352 printf(
"%s.%s", test_suite, test);
3360#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3370#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3382 static void PrintFailedTests(
const UnitTest& unit_test);
3383 static void PrintFailedTestSuites(
const UnitTest& unit_test);
3384 static void PrintSkippedTests(
const UnitTest& unit_test);
3389 const UnitTest& unit_test,
int iteration) {
3391 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
3393 const char*
const filter =
GTEST_FLAG(filter).c_str();
3398 ColoredPrintf(GTestColor::kYellow,
"Note: %s filter = %s\n",
GTEST_NAME_,
3404 ColoredPrintf(GTestColor::kYellow,
"Note: This is test shard %d of %s.\n",
3405 static_cast<int>(shard_index) + 1,
3410 ColoredPrintf(GTestColor::kYellow,
3411 "Note: Randomizing tests' orders with a seed of %d .\n",
3415 ColoredPrintf(GTestColor::kGreen,
"[==========] ");
3416 printf(
"Running %s from %s.\n",
3424 ColoredPrintf(GTestColor::kGreen,
"[----------] ");
3425 printf(
"Global test environment set-up.\n");
3429#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3431 const std::string counts =
3432 FormatCountableNoun(test_case.test_to_run_count(),
"test",
"tests");
3433 ColoredPrintf(GTestColor::kGreen,
"[----------] ");
3434 printf(
"%s from %s", counts.c_str(), test_case.name());
3435 if (test_case.type_param() ==
nullptr) {
3438 printf(
", where %s = %s\n", kTypeParamLabel, test_case.type_param());
3445 const std::string counts =
3447 ColoredPrintf(GTestColor::kGreen,
"[----------] ");
3448 printf(
"%s from %s", counts.c_str(), test_suite.
name());
3452 printf(
", where %s = %s\n", kTypeParamLabel, test_suite.
type_param());
3459 ColoredPrintf(GTestColor::kGreen,
"[ RUN ] ");
3467 const TestPartResult& result) {
3468 switch (result.type()) {
3470 case TestPartResult::kSuccess:
3475 PrintTestPartResult(result);
3482 ColoredPrintf(GTestColor::kGreen,
"[ OK ] ");
3484 ColoredPrintf(GTestColor::kGreen,
"[ SKIPPED ] ");
3486 ColoredPrintf(GTestColor::kRed,
"[ FAILED ] ");
3490 PrintFullTestCommentIfPresent(test_info);
3501#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3505 const std::string counts =
3506 FormatCountableNoun(test_case.test_to_run_count(),
"test",
"tests");
3507 ColoredPrintf(GTestColor::kGreen,
"[----------] ");
3508 printf(
"%s from %s (%s ms total)\n\n", counts.c_str(), test_case.name(),
3516 const std::string counts =
3518 ColoredPrintf(GTestColor::kGreen,
"[----------] ");
3519 printf(
"%s from %s (%s ms total)\n\n", counts.c_str(), test_suite.
name(),
3527 ColoredPrintf(GTestColor::kGreen,
"[----------] ");
3528 printf(
"Global test environment tear-down\n");
3533void PrettyUnitTestResultPrinter::PrintFailedTests(
const UnitTest& unit_test) {
3535 ColoredPrintf(GTestColor::kRed,
"[ FAILED ] ");
3536 printf(
"%s, listed below:\n", FormatTestCount(failed_test_count).c_str());
3548 ColoredPrintf(GTestColor::kRed,
"[ FAILED ] ");
3549 printf(
"%s.%s", test_suite.
name(), test_info.
name());
3550 PrintFullTestCommentIfPresent(test_info);
3554 printf(
"\n%2d FAILED %s\n", failed_test_count,
3555 failed_test_count == 1 ?
"TEST" :
"TESTS");
3560void PrettyUnitTestResultPrinter::PrintFailedTestSuites(
3561 const UnitTest& unit_test) {
3562 int suite_failure_count = 0;
3563 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
3564 const TestSuite& test_suite = *unit_test.GetTestSuite(
i);
3565 if (!test_suite.should_run()) {
3568 if (test_suite.ad_hoc_test_result().Failed()) {
3569 ColoredPrintf(GTestColor::kRed,
"[ FAILED ] ");
3570 printf(
"%s: SetUpTestSuite or TearDownTestSuite\n", test_suite.name());
3571 ++suite_failure_count;
3574 if (suite_failure_count > 0) {
3575 printf(
"\n%2d FAILED TEST %s\n", suite_failure_count,
3576 suite_failure_count == 1 ?
"SUITE" :
"SUITES");
3581void PrettyUnitTestResultPrinter::PrintSkippedTests(
const UnitTest& unit_test) {
3582 const int skipped_test_count = unit_test.skipped_test_count();
3583 if (skipped_test_count == 0) {
3587 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
3588 const TestSuite& test_suite = *unit_test.GetTestSuite(
i);
3589 if (!test_suite.should_run() || (test_suite.skipped_test_count() == 0)) {
3592 for (
int j = 0; j < test_suite.total_test_count(); ++j) {
3593 const TestInfo& test_info = *test_suite.GetTestInfo(j);
3594 if (!test_info.should_run() || !test_info.result()->Skipped()) {
3597 ColoredPrintf(GTestColor::kGreen,
"[ SKIPPED ] ");
3598 printf(
"%s.%s", test_suite.name(), test_info.name());
3606 ColoredPrintf(GTestColor::kGreen,
"[==========] ");
3607 printf(
"%s from %s ran.",
3611 printf(
" (%s ms total)",
3615 ColoredPrintf(GTestColor::kGreen,
"[ PASSED ] ");
3619 if (skipped_test_count > 0) {
3620 ColoredPrintf(GTestColor::kGreen,
"[ SKIPPED ] ");
3621 printf(
"%s, listed below:\n", FormatTestCount(skipped_test_count).c_str());
3622 PrintSkippedTests(unit_test);
3625 if (!unit_test.
Passed()) {
3626 PrintFailedTests(unit_test);
3627 PrintFailedTestSuites(unit_test);
3631 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3632 if (unit_test.
Passed()) {
3635 ColoredPrintf(GTestColor::kYellow,
" YOU HAVE %d DISABLED %s\n\n",
3636 num_disabled, num_disabled == 1 ?
"TEST" :
"TESTS");
3651 printf(
"%s.%s", test_suite, test);
3660#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3670#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3684 const TestPartResult& result) {
3685 switch (result.type()) {
3687 case TestPartResult::kSuccess:
3692 PrintTestPartResult(result);
3699 ColoredPrintf(GTestColor::kRed,
"[ FAILED ] ");
3701 PrintFullTestCommentIfPresent(test_info);
3704 printf(
" (%s ms)\n",
3716 ColoredPrintf(GTestColor::kGreen,
"[==========] ");
3717 printf(
"%s from %s ran.",
3721 printf(
" (%s ms total)",
3725 ColoredPrintf(GTestColor::kGreen,
"[ PASSED ] ");
3729 if (skipped_test_count > 0) {
3730 ColoredPrintf(GTestColor::kGreen,
"[ SKIPPED ] ");
3731 printf(
"%s.\n", FormatTestCount(skipped_test_count).c_str());
3735 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3736 if (unit_test.
Passed()) {
3739 ColoredPrintf(GTestColor::kYellow,
" YOU HAVE %d DISABLED %s\n\n",
3740 num_disabled, num_disabled == 1 ?
"TEST" :
"TESTS");
3768#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3776#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3788 bool forwarding_enabled_;
3790 std::vector<TestEventListener*> listeners_;
3796 ForEach(listeners_, Delete<TestEventListener>);
3800 listeners_.push_back(listener);
3804 for (
size_t i = 0;
i < listeners_.size(); ++
i) {
3805 if (listeners_[
i] == listener) {
3806 listeners_.erase(listeners_.begin() +
static_cast<int>(
i));
3816#define GTEST_REPEATER_METHOD_(Name, Type) \
3817void TestEventRepeater::Name(const Type& parameter) { \
3818 if (forwarding_enabled_) { \
3819 for (size_t i = 0; i < listeners_.size(); i++) { \
3820 listeners_[i]->Name(parameter); \
3826#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
3827 void TestEventRepeater::Name(const Type& parameter) { \
3828 if (forwarding_enabled_) { \
3829 for (size_t i = listeners_.size(); i != 0; i--) { \
3830 listeners_[i - 1]->Name(parameter); \
3838#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3849#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3855#undef GTEST_REPEATER_METHOD_
3856#undef GTEST_REVERSE_REPEATER_METHOD_
3860 if (forwarding_enabled_) {
3861 for (
size_t i = 0;
i < listeners_.size();
i++) {
3862 listeners_[
i]->OnTestIterationStart(unit_test, iteration);
3869 if (forwarding_enabled_) {
3870 for (
size_t i = listeners_.size();
i > 0;
i--) {
3871 listeners_[
i - 1]->OnTestIterationEnd(unit_test, iteration);
3888 const std::vector<TestSuite*>& test_suites);
3893 static bool IsNormalizableWhitespace(
char c) {
3894 return c == 0x9 || c == 0xA || c == 0xD;
3898 static bool IsValidXmlCharacter(
char c) {
3899 return IsNormalizableWhitespace(c) || c >= 0x20;
3906 static std::string EscapeXml(
const std::string& str,
bool is_attribute);
3909 static std::string RemoveInvalidXmlCharacters(
const std::string& str);
3912 static std::string EscapeXmlAttribute(
const std::string& str) {
3913 return EscapeXml(str,
true);
3917 static std::string EscapeXmlText(
const char* str) {
3918 return EscapeXml(str,
false);
3923 static void OutputXmlAttribute(std::ostream* stream,
3924 const std::string& element_name,
3925 const std::string& name,
3926 const std::string&
value);
3929 static void OutputXmlCDataSection(::std::ostream* stream,
const char* data);
3934 static void OutputXmlTestSuiteForTestResult(::std::ostream* stream,
3938 static void OutputXmlTestResult(::std::ostream* stream,
3942 static void OutputXmlTestInfo(::std::ostream* stream,
3943 const char* test_suite_name,
3947 static void PrintXmlTestSuite(::std::ostream* stream,
3951 static void PrintXmlUnitTest(::std::ostream* stream,
3958 static std::string TestPropertiesAsXmlAttributes(
const TestResult& result);
3962 static void OutputXmlTestProperties(std::ostream* stream,
3966 const std::string output_file_;
3973 : output_file_(output_file) {
3974 if (output_file_.empty()) {
3982 FILE* xmlout = OpenFileForWriting(output_file_);
3983 std::stringstream stream;
3984 PrintXmlUnitTest(&stream, unit_test);
3990 const std::vector<TestSuite*>& test_suites) {
3991 FILE* xmlout = OpenFileForWriting(output_file_);
3992 std::stringstream stream;
4008std::string XmlUnitTestResultPrinter::EscapeXml(
4009 const std::string& str,
bool is_attribute) {
4012 for (
size_t i = 0;
i < str.size(); ++
i) {
4013 const char ch = str[
i];
4037 if (IsValidXmlCharacter(
ch)) {
4038 if (is_attribute && IsNormalizableWhitespace(
ch))
4054std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(
4055 const std::string& str) {
4057 output.reserve(str.size());
4058 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
4059 if (IsValidXmlCharacter(*it))
4084 ::std::stringstream ss;
4085 ss << (static_cast<double>(ms) * 1e-3);
4089static bool PortableLocaltime(time_t seconds,
struct tm* out) {
4090#if defined(_MSC_VER)
4091 return localtime_s(out, &seconds) == 0;
4092#elif defined(__MINGW32__) || defined(__MINGW64__)
4095 struct tm* tm_ptr = localtime(&seconds);
4096 if (tm_ptr ==
nullptr)
return false;
4099#elif defined(__STDC_LIB_EXT1__)
4102 return localtime_s(&seconds, out) !=
nullptr;
4104 return localtime_r(&seconds, out) !=
nullptr;
4111 struct tm time_struct;
4112 if (!PortableLocaltime(
static_cast<time_t
>(ms / 1000), &time_struct))
4125void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream,
4127 const char* segment = data;
4128 *stream <<
"<![CDATA[";
4130 const char*
const next_segment = strstr(segment,
"]]>");
4131 if (next_segment !=
nullptr) {
4133 segment,
static_cast<std::streamsize
>(next_segment - segment));
4134 *stream <<
"]]>]]><![CDATA[";
4135 segment = next_segment + strlen(
"]]>");
4144void XmlUnitTestResultPrinter::OutputXmlAttribute(
4145 std::ostream* stream,
4146 const std::string& element_name,
4147 const std::string& name,
4148 const std::string&
value) {
4149 const std::vector<std::string>& allowed_names =
4150 GetReservedOutputAttributesForElement(element_name);
4152 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
4153 allowed_names.end())
4154 <<
"Attribute " << name <<
" is not allowed for element <" << element_name
4157 *stream <<
" " << name <<
"=\"" << EscapeXmlAttribute(
value) <<
"\"";
4161void XmlUnitTestResultPrinter::OutputXmlTestSuiteForTestResult(
4162 ::std::ostream* stream,
const TestResult& result) {
4164 *stream <<
" <testsuite";
4165 OutputXmlAttribute(stream,
"testsuite",
"name",
"NonTestSuiteFailure");
4166 OutputXmlAttribute(stream,
"testsuite",
"tests",
"1");
4167 OutputXmlAttribute(stream,
"testsuite",
"failures",
"1");
4168 OutputXmlAttribute(stream,
"testsuite",
"disabled",
"0");
4169 OutputXmlAttribute(stream,
"testsuite",
"skipped",
"0");
4170 OutputXmlAttribute(stream,
"testsuite",
"errors",
"0");
4171 OutputXmlAttribute(stream,
"testsuite",
"time",
4174 stream,
"testsuite",
"timestamp",
4179 *stream <<
" <testcase";
4180 OutputXmlAttribute(stream,
"testcase",
"name",
"");
4181 OutputXmlAttribute(stream,
"testcase",
"status",
"run");
4182 OutputXmlAttribute(stream,
"testcase",
"result",
"completed");
4183 OutputXmlAttribute(stream,
"testcase",
"classname",
"");
4184 OutputXmlAttribute(stream,
"testcase",
"time",
4187 stream,
"testcase",
"timestamp",
4191 OutputXmlTestResult(stream, result);
4194 *stream <<
" </testsuite>\n";
4198void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
4199 const char* test_suite_name,
4200 const TestInfo& test_info) {
4201 const TestResult& result = *test_info.result();
4202 const std::string kTestsuite =
"testcase";
4204 if (test_info.is_in_another_shard()) {
4208 *stream <<
" <testcase";
4209 OutputXmlAttribute(stream, kTestsuite,
"name", test_info.name());
4211 if (test_info.value_param() !=
nullptr) {
4212 OutputXmlAttribute(stream, kTestsuite,
"value_param",
4213 test_info.value_param());
4215 if (test_info.type_param() !=
nullptr) {
4216 OutputXmlAttribute(stream, kTestsuite,
"type_param",
4217 test_info.type_param());
4220 OutputXmlAttribute(stream, kTestsuite,
"file", test_info.file());
4221 OutputXmlAttribute(stream, kTestsuite,
"line",
4227 OutputXmlAttribute(stream, kTestsuite,
"status",
4228 test_info.should_run() ?
"run" :
"notrun");
4229 OutputXmlAttribute(stream, kTestsuite,
"result",
4230 test_info.should_run()
4231 ? (result.Skipped() ?
"skipped" :
"completed")
4233 OutputXmlAttribute(stream, kTestsuite,
"time",
4236 stream, kTestsuite,
"timestamp",
4238 OutputXmlAttribute(stream, kTestsuite,
"classname", test_suite_name);
4240 OutputXmlTestResult(stream, result);
4243void XmlUnitTestResultPrinter::OutputXmlTestResult(::std::ostream* stream,
4244 const TestResult& result) {
4247 for (
int i = 0;
i < result.total_part_count(); ++
i) {
4248 const TestPartResult& part = result.GetTestPartResult(
i);
4249 if (part.failed()) {
4250 if (++failures == 1 && skips == 0) {
4253 const std::string location =
4255 part.line_number());
4256 const std::string summary = location +
"\n" + part.summary();
4257 *stream <<
" <failure message=\""
4258 << EscapeXmlAttribute(summary)
4260 const std::string detail = location +
"\n" + part.message();
4261 OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str());
4262 *stream <<
"</failure>\n";
4263 }
else if (part.skipped()) {
4264 if (++skips == 1 && failures == 0) {
4267 const std::string location =
4269 part.line_number());
4270 const std::string summary = location +
"\n" + part.summary();
4271 *stream <<
" <skipped message=\""
4272 << EscapeXmlAttribute(summary.c_str()) <<
"\">";
4273 const std::string detail = location +
"\n" + part.message();
4274 OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str());
4275 *stream <<
"</skipped>\n";
4279 if (failures == 0 && skips == 0 && result.test_property_count() == 0) {
4282 if (failures == 0 && skips == 0) {
4285 OutputXmlTestProperties(stream, result);
4286 *stream <<
" </testcase>\n";
4291void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream,
4292 const TestSuite& test_suite) {
4293 const std::string kTestsuite =
"testsuite";
4294 *stream <<
" <" << kTestsuite;
4295 OutputXmlAttribute(stream, kTestsuite,
"name", test_suite.name());
4296 OutputXmlAttribute(stream, kTestsuite,
"tests",
4299 OutputXmlAttribute(stream, kTestsuite,
"failures",
4302 stream, kTestsuite,
"disabled",
4304 OutputXmlAttribute(stream, kTestsuite,
"skipped",
4307 OutputXmlAttribute(stream, kTestsuite,
"errors",
"0");
4309 OutputXmlAttribute(stream, kTestsuite,
"time",
4312 stream, kTestsuite,
"timestamp",
4314 *stream << TestPropertiesAsXmlAttributes(test_suite.ad_hoc_test_result());
4317 for (
int i = 0;
i < test_suite.total_test_count(); ++
i) {
4318 if (test_suite.GetTestInfo(
i)->is_reportable())
4319 OutputXmlTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(
i));
4321 *stream <<
" </" << kTestsuite <<
">\n";
4325void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream,
4326 const UnitTest& unit_test) {
4327 const std::string kTestsuites =
"testsuites";
4329 *stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
4330 *stream <<
"<" << kTestsuites;
4332 OutputXmlAttribute(stream, kTestsuites,
"tests",
4334 OutputXmlAttribute(stream, kTestsuites,
"failures",
4337 stream, kTestsuites,
"disabled",
4339 OutputXmlAttribute(stream, kTestsuites,
"errors",
"0");
4340 OutputXmlAttribute(stream, kTestsuites,
"time",
4343 stream, kTestsuites,
"timestamp",
4347 OutputXmlAttribute(stream, kTestsuites,
"random_seed",
4350 *stream << TestPropertiesAsXmlAttributes(unit_test.ad_hoc_test_result());
4352 OutputXmlAttribute(stream, kTestsuites,
"name",
"AllTests");
4355 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
4356 if (unit_test.GetTestSuite(
i)->reportable_test_count() > 0)
4357 PrintXmlTestSuite(stream, *unit_test.GetTestSuite(
i));
4362 if (unit_test.ad_hoc_test_result().Failed()) {
4363 OutputXmlTestSuiteForTestResult(stream, unit_test.ad_hoc_test_result());
4366 *stream <<
"</" << kTestsuites <<
">\n";
4370 std::ostream* stream,
const std::vector<TestSuite*>& test_suites) {
4371 const std::string kTestsuites =
"testsuites";
4373 *stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
4374 *stream <<
"<" << kTestsuites;
4376 int total_tests = 0;
4377 for (
auto test_suite : test_suites) {
4378 total_tests += test_suite->total_test_count();
4380 OutputXmlAttribute(stream, kTestsuites,
"tests",
4382 OutputXmlAttribute(stream, kTestsuites,
"name",
"AllTests");
4385 for (
auto test_suite : test_suites) {
4386 PrintXmlTestSuite(stream, *test_suite);
4388 *stream <<
"</" << kTestsuites <<
">\n";
4393std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
4398 attributes <<
" " <<
property.key() <<
"="
4399 <<
"\"" << EscapeXmlAttribute(property.value()) <<
"\"";
4404void XmlUnitTestResultPrinter::OutputXmlTestProperties(
4405 std::ostream* stream,
const TestResult& result) {
4406 const std::string kProperties =
"properties";
4407 const std::string kProperty =
"property";
4409 if (result.test_property_count() <= 0) {
4413 *stream <<
"<" << kProperties <<
">\n";
4414 for (
int i = 0;
i < result.test_property_count(); ++
i) {
4415 const TestProperty&
property = result.GetTestProperty(
i);
4416 *stream <<
"<" << kProperty;
4417 *stream <<
" name=\"" << EscapeXmlAttribute(property.key()) <<
"\"";
4418 *stream <<
" value=\"" << EscapeXmlAttribute(property.value()) <<
"\"";
4421 *stream <<
"</" << kProperties <<
">\n";
4435 const std::vector<TestSuite*>& test_suites);
4439 static std::string EscapeJson(
const std::string& str);
4443 static void OutputJsonKey(std::ostream* stream,
4444 const std::string& element_name,
4445 const std::string& name,
4446 const std::string&
value,
4447 const std::string& indent,
4449 static void OutputJsonKey(std::ostream* stream,
4450 const std::string& element_name,
4451 const std::string& name,
4453 const std::string& indent,
4459 static void OutputJsonTestSuiteForTestResult(::std::ostream* stream,
4463 static void OutputJsonTestResult(::std::ostream* stream,
4467 static void OutputJsonTestInfo(::std::ostream* stream,
4468 const char* test_suite_name,
4472 static void PrintJsonTestSuite(::std::ostream* stream,
4476 static void PrintJsonUnitTest(::std::ostream* stream,
4481 static std::string TestPropertiesAsJson(
const TestResult& result,
4482 const std::string& indent);
4485 const std::string output_file_;
4492 : output_file_(output_file) {
4493 if (output_file_.empty()) {
4500 FILE* jsonout = OpenFileForWriting(output_file_);
4501 std::stringstream stream;
4502 PrintJsonUnitTest(&stream, unit_test);
4508std::string JsonUnitTestResultPrinter::EscapeJson(
const std::string& str) {
4511 for (
size_t i = 0;
i < str.size(); ++
i) {
4512 const char ch = str[
i];
4551static std::string FormatTimeInMillisAsDuration(
TimeInMillis ms) {
4552 ::std::stringstream ss;
4553 ss << (static_cast<double>(ms) * 1e-3) <<
"s";
4559static std::string FormatEpochTimeInMillisAsRFC3339(
TimeInMillis ms) {
4560 struct tm time_struct;
4561 if (!PortableLocaltime(
static_cast<time_t
>(ms / 1000), &time_struct))
4572static inline std::string Indent(
size_t width) {
4573 return std::string(width,
' ');
4576void JsonUnitTestResultPrinter::OutputJsonKey(
4577 std::ostream* stream,
4578 const std::string& element_name,
4579 const std::string& name,
4580 const std::string&
value,
4581 const std::string& indent,
4583 const std::vector<std::string>& allowed_names =
4584 GetReservedOutputAttributesForElement(element_name);
4586 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
4587 allowed_names.end())
4588 <<
"Key \"" << name <<
"\" is not allowed for value \"" << element_name
4591 *stream << indent <<
"\"" << name <<
"\": \"" << EscapeJson(
value) <<
"\"";
4596void JsonUnitTestResultPrinter::OutputJsonKey(
4597 std::ostream* stream,
4598 const std::string& element_name,
4599 const std::string& name,
4601 const std::string& indent,
4603 const std::vector<std::string>& allowed_names =
4604 GetReservedOutputAttributesForElement(element_name);
4606 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
4607 allowed_names.end())
4608 <<
"Key \"" << name <<
"\" is not allowed for value \"" << element_name
4617void JsonUnitTestResultPrinter::OutputJsonTestSuiteForTestResult(
4618 ::std::ostream* stream,
const TestResult& result) {
4620 *stream << Indent(4) <<
"{\n";
4621 OutputJsonKey(stream,
"testsuite",
"name",
"NonTestSuiteFailure", Indent(6));
4622 OutputJsonKey(stream,
"testsuite",
"tests", 1, Indent(6));
4624 OutputJsonKey(stream,
"testsuite",
"failures", 1, Indent(6));
4625 OutputJsonKey(stream,
"testsuite",
"disabled", 0, Indent(6));
4626 OutputJsonKey(stream,
"testsuite",
"skipped", 0, Indent(6));
4627 OutputJsonKey(stream,
"testsuite",
"errors", 0, Indent(6));
4628 OutputJsonKey(stream,
"testsuite",
"time",
4629 FormatTimeInMillisAsDuration(result.elapsed_time()),
4631 OutputJsonKey(stream,
"testsuite",
"timestamp",
4632 FormatEpochTimeInMillisAsRFC3339(result.start_timestamp()),
4635 *stream << Indent(6) <<
"\"testsuite\": [\n";
4638 *stream << Indent(8) <<
"{\n";
4639 OutputJsonKey(stream,
"testcase",
"name",
"", Indent(10));
4640 OutputJsonKey(stream,
"testcase",
"status",
"RUN", Indent(10));
4641 OutputJsonKey(stream,
"testcase",
"result",
"COMPLETED", Indent(10));
4642 OutputJsonKey(stream,
"testcase",
"timestamp",
4643 FormatEpochTimeInMillisAsRFC3339(result.start_timestamp()),
4645 OutputJsonKey(stream,
"testcase",
"time",
4646 FormatTimeInMillisAsDuration(result.elapsed_time()),
4648 OutputJsonKey(stream,
"testcase",
"classname",
"", Indent(10),
false);
4649 *stream << TestPropertiesAsJson(result, Indent(10));
4652 OutputJsonTestResult(stream, result);
4655 *stream <<
"\n" << Indent(6) <<
"]\n" << Indent(4) <<
"}";
4659void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
4660 const char* test_suite_name,
4661 const TestInfo& test_info) {
4662 const TestResult& result = *test_info.result();
4663 const std::string kTestsuite =
"testcase";
4664 const std::string kIndent = Indent(10);
4666 *stream << Indent(8) <<
"{\n";
4667 OutputJsonKey(stream, kTestsuite,
"name", test_info.name(), kIndent);
4669 if (test_info.value_param() !=
nullptr) {
4670 OutputJsonKey(stream, kTestsuite,
"value_param", test_info.value_param(),
4673 if (test_info.type_param() !=
nullptr) {
4674 OutputJsonKey(stream, kTestsuite,
"type_param", test_info.type_param(),
4678 OutputJsonKey(stream, kTestsuite,
"file", test_info.file(), kIndent);
4679 OutputJsonKey(stream, kTestsuite,
"line", test_info.line(), kIndent,
false);
4680 *stream <<
"\n" << Indent(8) <<
"}";
4684 OutputJsonKey(stream, kTestsuite,
"status",
4685 test_info.should_run() ?
"RUN" :
"NOTRUN", kIndent);
4686 OutputJsonKey(stream, kTestsuite,
"result",
4687 test_info.should_run()
4688 ? (result.Skipped() ?
"SKIPPED" :
"COMPLETED")
4691 OutputJsonKey(stream, kTestsuite,
"timestamp",
4692 FormatEpochTimeInMillisAsRFC3339(result.start_timestamp()),
4694 OutputJsonKey(stream, kTestsuite,
"time",
4695 FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent);
4696 OutputJsonKey(stream, kTestsuite,
"classname", test_suite_name, kIndent,
4698 *stream << TestPropertiesAsJson(result, kIndent);
4700 OutputJsonTestResult(stream, result);
4703void JsonUnitTestResultPrinter::OutputJsonTestResult(::std::ostream* stream,
4704 const TestResult& result) {
4705 const std::string kIndent = Indent(10);
4708 for (
int i = 0;
i < result.total_part_count(); ++
i) {
4709 const TestPartResult& part = result.GetTestPartResult(
i);
4710 if (part.failed()) {
4712 if (++failures == 1) {
4713 *stream << kIndent <<
"\"" <<
"failures" <<
"\": [\n";
4715 const std::string location =
4717 part.line_number());
4718 const std::string
message = EscapeJson(location +
"\n" + part.message());
4719 *stream << kIndent <<
" {\n"
4720 << kIndent <<
" \"failure\": \"" <<
message <<
"\",\n"
4721 << kIndent <<
" \"type\": \"\"\n"
4727 *stream <<
"\n" << kIndent <<
"]";
4728 *stream <<
"\n" << Indent(8) <<
"}";
4732void JsonUnitTestResultPrinter::PrintJsonTestSuite(
4733 std::ostream* stream,
const TestSuite& test_suite) {
4734 const std::string kTestsuite =
"testsuite";
4735 const std::string kIndent = Indent(6);
4737 *stream << Indent(4) <<
"{\n";
4738 OutputJsonKey(stream, kTestsuite,
"name", test_suite.name(), kIndent);
4739 OutputJsonKey(stream, kTestsuite,
"tests", test_suite.reportable_test_count(),
4742 OutputJsonKey(stream, kTestsuite,
"failures",
4743 test_suite.failed_test_count(), kIndent);
4744 OutputJsonKey(stream, kTestsuite,
"disabled",
4745 test_suite.reportable_disabled_test_count(), kIndent);
4746 OutputJsonKey(stream, kTestsuite,
"errors", 0, kIndent);
4748 stream, kTestsuite,
"timestamp",
4749 FormatEpochTimeInMillisAsRFC3339(test_suite.start_timestamp()),
4751 OutputJsonKey(stream, kTestsuite,
"time",
4752 FormatTimeInMillisAsDuration(test_suite.elapsed_time()),
4754 *stream << TestPropertiesAsJson(test_suite.ad_hoc_test_result(), kIndent)
4758 *stream << kIndent <<
"\"" << kTestsuite <<
"\": [\n";
4761 for (
int i = 0;
i < test_suite.total_test_count(); ++
i) {
4762 if (test_suite.GetTestInfo(
i)->is_reportable()) {
4768 OutputJsonTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(
i));
4771 *stream <<
"\n" << kIndent <<
"]\n" << Indent(4) <<
"}";
4775void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
4776 const UnitTest& unit_test) {
4777 const std::string kTestsuites =
"testsuites";
4778 const std::string kIndent = Indent(2);
4781 OutputJsonKey(stream, kTestsuites,
"tests", unit_test.reportable_test_count(),
4783 OutputJsonKey(stream, kTestsuites,
"failures", unit_test.failed_test_count(),
4785 OutputJsonKey(stream, kTestsuites,
"disabled",
4786 unit_test.reportable_disabled_test_count(), kIndent);
4787 OutputJsonKey(stream, kTestsuites,
"errors", 0, kIndent);
4789 OutputJsonKey(stream, kTestsuites,
"random_seed", unit_test.random_seed(),
4792 OutputJsonKey(stream, kTestsuites,
"timestamp",
4793 FormatEpochTimeInMillisAsRFC3339(unit_test.start_timestamp()),
4795 OutputJsonKey(stream, kTestsuites,
"time",
4796 FormatTimeInMillisAsDuration(unit_test.elapsed_time()), kIndent,
4799 *stream << TestPropertiesAsJson(unit_test.ad_hoc_test_result(), kIndent)
4802 OutputJsonKey(stream, kTestsuites,
"name",
"AllTests", kIndent);
4803 *stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4806 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
4807 if (unit_test.GetTestSuite(
i)->reportable_test_count() > 0) {
4813 PrintJsonTestSuite(stream, *unit_test.GetTestSuite(
i));
4819 if (unit_test.ad_hoc_test_result().Failed()) {
4820 OutputJsonTestSuiteForTestResult(stream, unit_test.ad_hoc_test_result());
4823 *stream <<
"\n" << kIndent <<
"]\n" <<
"}\n";
4827 std::ostream* stream,
const std::vector<TestSuite*>& test_suites) {
4828 const std::string kTestsuites =
"testsuites";
4829 const std::string kIndent = Indent(2);
4831 int total_tests = 0;
4832 for (
auto test_suite : test_suites) {
4833 total_tests += test_suite->total_test_count();
4835 OutputJsonKey(stream, kTestsuites,
"tests", total_tests, kIndent);
4837 OutputJsonKey(stream, kTestsuites,
"name",
"AllTests", kIndent);
4838 *stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4840 for (
size_t i = 0;
i < test_suites.size(); ++
i) {
4844 PrintJsonTestSuite(stream, *test_suites[
i]);
4853std::string JsonUnitTestResultPrinter::TestPropertiesAsJson(
4854 const TestResult& result,
const std::string& indent) {
4858 attributes <<
",\n" << indent <<
"\"" <<
property.key() <<
"\": "
4859 <<
"\"" << EscapeJson(property.value()) <<
"\"";
4866#if GTEST_CAN_STREAM_RESULTS_
4873std::string StreamingListener::UrlEncode(
const char* str) {
4875 result.reserve(strlen(str) + 1);
4876 for (
char ch = *str;
ch !=
'\0';
ch = *++str) {
4885 result.push_back(
ch);
4892void StreamingListener::SocketWriter::MakeConnection() {
4894 <<
"MakeConnection() can't be called when there is already a connection.";
4897 memset(&hints, 0,
sizeof(hints));
4898 hints.ai_family = AF_UNSPEC;
4899 hints.ai_socktype = SOCK_STREAM;
4900 addrinfo* servinfo =
nullptr;
4904 const int error_num = getaddrinfo(
4905 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
4906 if (error_num != 0) {
4908 << gai_strerror(error_num);
4912 for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr !=
nullptr;
4913 cur_addr = cur_addr->ai_next) {
4915 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
4916 if (sockfd_ != -1) {
4918 if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
4925 freeaddrinfo(servinfo);
4927 if (sockfd_ == -1) {
4929 << host_name_ <<
":" << port_num_;
4938const char*
const OsStackTraceGetterInterface::kElidedFramesMarker =
4941std::string OsStackTraceGetter::CurrentStackTrace(
int max_depth,
int skip_count)
4946 if (max_depth <= 0) {
4950 max_depth = std::min(max_depth, kMaxStackTraceDepth);
4952 std::vector<void*> raw_stack(max_depth);
4954 const int raw_stack_size =
4955 absl::GetStackTrace(&raw_stack[0], max_depth, skip_count + 1);
4957 void* caller_frame =
nullptr;
4960 caller_frame = caller_frame_;
4963 for (
int i = 0;
i < raw_stack_size; ++
i) {
4964 if (raw_stack[
i] == caller_frame &&
4967 absl::StrAppend(&result, kElidedFramesMarker,
"\n");
4972 const char* symbol =
"(unknown)";
4973 if (absl::Symbolize(raw_stack[
i], tmp,
sizeof(tmp))) {
4978 snprintf(line,
sizeof(line),
" %p: %s\n", raw_stack[
i], symbol);
4985 static_cast<void>(max_depth);
4986 static_cast<void>(skip_count);
4993 void* caller_frame =
nullptr;
4994 if (absl::GetStackTrace(&caller_frame, 1, 3) <= 0) {
4995 caller_frame =
nullptr;
4999 caller_frame_ = caller_frame;
5008 : premature_exit_filepath_(premature_exit_filepath ?
5009 premature_exit_filepath :
"") {
5011 if (!premature_exit_filepath_.empty()) {
5015 FILE* pfile =
posix::FOpen(premature_exit_filepath,
"w");
5016 fwrite(
"0", 1, 1, pfile);
5022#if !defined GTEST_OS_ESP8266
5023 if (!premature_exit_filepath_.empty()) {
5024 int retval = remove(premature_exit_filepath_.c_str());
5027 << premature_exit_filepath_ <<
"\" with error "
5035 const std::string premature_exit_filepath_;
5045 : repeater_(new internal::TestEventRepeater()),
5046 default_result_printer_(nullptr),
5047 default_xml_generator_(nullptr) {}
5056 repeater_->
Append(listener);
5063 if (listener == default_result_printer_)
5064 default_result_printer_ =
nullptr;
5065 else if (listener == default_xml_generator_)
5066 default_xml_generator_ =
nullptr;
5067 return repeater_->
Release(listener);
5079void TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) {
5080 if (default_result_printer_ != listener) {
5083 delete Release(default_result_printer_);
5084 default_result_printer_ = listener;
5085 if (listener !=
nullptr)
Append(listener);
5094void TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) {
5095 if (default_xml_generator_ != listener) {
5098 delete Release(default_xml_generator_);
5099 default_xml_generator_ = listener;
5100 if (listener !=
nullptr)
Append(listener);
5106bool TestEventListeners::EventForwardingEnabled()
const {
5110void TestEventListeners::SuppressEventForwarding() {
5128#if defined(__BORLANDC__)
5139 return impl()->successful_test_suite_count();
5144 return impl()->failed_test_suite_count();
5149 return impl()->total_test_suite_count();
5155 return impl()->test_suite_to_run_count();
5159#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5161 return impl()->successful_test_suite_count();
5164 return impl()->failed_test_suite_count();
5167 return impl()->total_test_suite_count();
5170 return impl()->test_suite_to_run_count();
5176 return impl()->successful_test_count();
5181 return impl()->skipped_test_count();
5189 return impl()->reportable_disabled_test_count();
5194 return impl()->disabled_test_count();
5199 return impl()->reportable_test_count();
5211 return impl()->start_timestamp();
5216 return impl()->elapsed_time();
5230 return impl()->GetTestSuite(
i);
5234#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5236 return impl()->GetTestCase(
i);
5243 return *impl()->ad_hoc_test_result();
5248TestSuite* UnitTest::GetMutableTestSuite(
int i) {
5249 return impl()->GetMutableSuiteCase(
i);
5255 return *impl()->listeners();
5269 if (env ==
nullptr) {
5273 impl_->environments().push_back(env);
5281void UnitTest::AddTestPartResult(
5282 TestPartResult::Type result_type,
5283 const char* file_name,
5291 if (impl_->gtest_trace_stack().size() > 0) {
5294 for (
size_t i = impl_->gtest_trace_stack().size();
i > 0; --
i) {
5295 const internal::TraceInfo& trace = impl_->gtest_trace_stack()[
i - 1];
5297 <<
" " << trace.message;
5301 if (os_stack_trace.c_str() !=
nullptr && !os_stack_trace.empty()) {
5305 const TestPartResult result = TestPartResult(
5306 result_type, file_name, line_number, msg.GetString().c_str());
5307 impl_->GetTestPartResultReporterForCurrentThread()->
5308 ReportTestPartResult(result);
5310 if (result_type != TestPartResult::kSuccess &&
5311 result_type != TestPartResult::kSkip) {
5318#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
5323#elif (!defined(__native_client__)) && \
5324 ((defined(__clang__) || defined(__GNUC__)) && \
5325 (defined(__x86_64__) || defined(__i386__)))
5332 *
static_cast<volatile int*
>(
nullptr) = 1;
5335#if GTEST_HAS_EXCEPTIONS
5336 throw internal::GoogleTestFailureException(result);
5351void UnitTest::RecordProperty(
const std::string& key,
5352 const std::string&
value) {
5353 impl_->RecordProperty(TestProperty(key,
value));
5362 const bool in_death_test_child_process =
5387 in_death_test_child_process
5393 impl()->set_catch_exceptions(
GTEST_FLAG(catch_exceptions));
5400 if (impl()->catch_exceptions() || in_death_test_child_process) {
5401# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
5403 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
5404 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
5407# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
5411 _set_error_mode(_OUT_TO_STDERR);
5414# if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
5421 _set_abort_behavior(
5423 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
5429 if (!IsDebuggerPresent()) {
5430 (void)_CrtSetReportMode(_CRT_ASSERT,
5431 _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
5432 (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
5441 "auxiliary test code (environments or event listeners)") ? 0 : 1;
5447 return impl_->original_working_dir_.c_str();
5455 return impl_->current_test_suite();
5459#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5463 return impl_->current_test_suite();
5472 return impl_->current_test_info();
5482 return impl_->parameterized_test_registry();
5486UnitTest::UnitTest() {
5487 impl_ =
new internal::UnitTestImpl(
this);
5491UnitTest::~UnitTest() {
5497void UnitTest::PushGTestTrace(
const internal::TraceInfo& trace)
5500 impl_->gtest_trace_stack().push_back(trace);
5504void UnitTest::PopGTestTrace()
5507 impl_->gtest_trace_stack().pop_back();
5512UnitTestImpl::UnitTestImpl(UnitTest* parent)
5515 default_global_test_part_result_reporter_(this),
5516 default_per_thread_test_part_result_reporter_(this),
5518 &default_global_test_part_result_reporter_),
5519 per_thread_test_part_result_reporter_(
5520 &default_per_thread_test_part_result_reporter_),
5521 parameterized_test_registry_(),
5522 parameterized_tests_registered_(false),
5523 last_death_test_suite_(-1),
5524 current_test_suite_(nullptr),
5525 current_test_info_(nullptr),
5526 ad_hoc_test_result_(),
5527 os_stack_trace_getter_(nullptr),
5528 post_flag_parse_init_performed_(false),
5531 start_timestamp_(0),
5533#if GTEST_HAS_DEATH_TEST
5534 death_test_factory_(new DefaultDeathTestFactory),
5537 catch_exceptions_(false) {
5538 listeners()->SetDefaultResultPrinter(
new PrettyUnitTestResultPrinter);
5541UnitTestImpl::~UnitTestImpl() {
5543 ForEach(test_suites_, internal::Delete<TestSuite>);
5546 ForEach(environments_, internal::Delete<Environment>);
5548 delete os_stack_trace_getter_;
5556void UnitTestImpl::RecordProperty(
const TestProperty& test_property) {
5557 std::string xml_element;
5558 TestResult* test_result;
5560 if (current_test_info_ !=
nullptr) {
5561 xml_element =
"testcase";
5562 test_result = &(current_test_info_->result_);
5563 }
else if (current_test_suite_ !=
nullptr) {
5564 xml_element =
"testsuite";
5565 test_result = &(current_test_suite_->ad_hoc_test_result_);
5567 xml_element =
"testsuites";
5568 test_result = &ad_hoc_test_result_;
5570 test_result->RecordProperty(xml_element, test_property);
5573#if GTEST_HAS_DEATH_TEST
5576void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
5577 if (internal_run_death_test_flag_.get() !=
nullptr)
5578 listeners()->SuppressEventForwarding();
5584void UnitTestImpl::ConfigureXmlOutput() {
5585 const std::string& output_format = UnitTestOptions::GetOutputFormat();
5586 if (output_format ==
"xml") {
5587 listeners()->SetDefaultXmlGenerator(
new XmlUnitTestResultPrinter(
5588 UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
5589 }
else if (output_format ==
"json") {
5590 listeners()->SetDefaultXmlGenerator(
new JsonUnitTestResultPrinter(
5591 UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
5592 }
else if (output_format !=
"") {
5594 << output_format <<
"\" ignored.";
5598#if GTEST_CAN_STREAM_RESULTS_
5601void UnitTestImpl::ConfigureStreamingOutput() {
5602 const std::string& target =
GTEST_FLAG(stream_result_to);
5603 if (!target.empty()) {
5604 const size_t pos = target.find(
':');
5605 if (pos != std::string::npos) {
5606 listeners()->Append(
new StreamingListener(target.substr(0, pos),
5607 target.substr(pos+1)));
5621void UnitTestImpl::PostFlagParsingInit() {
5623 if (!post_flag_parse_init_performed_) {
5624 post_flag_parse_init_performed_ =
true;
5626#if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
5628 listeners()->Append(
new GTEST_CUSTOM_TEST_EVENT_LISTENER_());
5631#if GTEST_HAS_DEATH_TEST
5632 InitDeathTestSubprocessControlInfo();
5633 SuppressTestEventsIfInSubprocess();
5639 RegisterParameterizedTests();
5643 ConfigureXmlOutput();
5646 listeners()->SetDefaultResultPrinter(
new BriefUnitTestResultPrinter);
5649#if GTEST_CAN_STREAM_RESULTS_
5651 ConfigureStreamingOutput();
5655 if (
GTEST_FLAG(install_failure_signal_handler)) {
5656 absl::FailureSignalHandlerOptions options;
5657 absl::InstallFailureSignalHandler(options);
5678 return test_suite !=
nullptr &&
5679 strcmp(test_suite->
name(), name_.c_str()) == 0;
5699 const char* test_suite_name,
const char* type_param,
5703 const auto test_suite =
5704 std::find_if(test_suites_.rbegin(), test_suites_.rend(),
5705 TestSuiteNameIs(test_suite_name));
5707 if (test_suite != test_suites_.rend())
return *test_suite;
5710 auto*
const new_test_suite =
5711 new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
5714 if (internal::UnitTestOptions::MatchesFilter(test_suite_name,
5715 kDeathTestSuiteFilter)) {
5720 ++last_death_test_suite_;
5721 test_suites_.insert(test_suites_.begin() + last_death_test_suite_,
5725 test_suites_.push_back(new_test_suite);
5728 test_suite_indices_.push_back(
static_cast<int>(test_suite_indices_.size()));
5729 return new_test_suite;
5734static void SetUpEnvironment(Environment* env) { env->SetUp(); }
5735static void TearDownEnvironment(Environment* env) { env->TearDown(); }
5749 const bool gtest_is_initialized_before_run_all_tests = GTestIsInitialized();
5757 PostFlagParsingInit();
5766 bool in_subprocess_for_death_test =
false;
5768#if GTEST_HAS_DEATH_TEST
5769 in_subprocess_for_death_test =
5770 (internal_run_death_test_flag_.get() !=
nullptr);
5771# if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
5772 if (in_subprocess_for_death_test) {
5773 GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
5778 const bool should_shard =
ShouldShard(kTestTotalShards, kTestShardIndex,
5779 in_subprocess_for_death_test);
5783 const bool has_tests_to_run = FilterTests(should_shard
5784 ? HONOR_SHARDING_PROTOCOL
5785 : IGNORE_SHARDING_PROTOCOL) > 0;
5790 ListTestsMatchingFilter();
5795 GetRandomSeedFromFlag(
GTEST_FLAG(random_seed)) : 0;
5798 bool failed =
false;
5800 TestEventListener* repeater = listeners()->repeater();
5803 repeater->OnTestProgramStart(*parent_);
5807 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG(repeat);
5809 const bool gtest_repeat_forever = repeat < 0;
5810 for (
int i = 0; gtest_repeat_forever ||
i != repeat;
i++) {
5813 ClearNonAdHocTestResult();
5818 if (has_tests_to_run &&
GTEST_FLAG(shuffle)) {
5819 random()->Reseed(
static_cast<uint32_t
>(random_seed_));
5827 repeater->OnTestIterationStart(*parent_,
i);
5830 if (has_tests_to_run) {
5832 repeater->OnEnvironmentsSetUpStart(*parent_);
5833 ForEach(environments_, SetUpEnvironment);
5834 repeater->OnEnvironmentsSetUpEnd(*parent_);
5841 TestResult& test_result =
5842 *internal::GetUnitTestImpl()->current_test_result();
5843 for (
int j = 0; j < test_result.total_part_count(); ++j) {
5844 const TestPartResult& test_part_result =
5845 test_result.GetTestPartResult(j);
5846 if (test_part_result.type() == TestPartResult::kSkip) {
5847 const std::string& result = test_part_result.message();
5848 printf(
"%s\n", result.c_str());
5853 for (
int test_index = 0; test_index < total_test_suite_count();
5855 GetMutableSuiteCase(test_index)->Run();
5857 GetMutableSuiteCase(test_index)->Failed()) {
5858 for (
int j = test_index + 1; j < total_test_suite_count(); j++) {
5859 GetMutableSuiteCase(j)->Skip();
5868 for (
int test_index = 0; test_index < total_test_suite_count();
5870 GetMutableSuiteCase(test_index)->Skip();
5875 repeater->OnEnvironmentsTearDownStart(*parent_);
5876 std::for_each(environments_.rbegin(), environments_.rend(),
5877 TearDownEnvironment);
5878 repeater->OnEnvironmentsTearDownEnd(*parent_);
5881 elapsed_time_ = timer.Elapsed();
5884 repeater->OnTestIterationEnd(*parent_,
i);
5901 random_seed_ = GetNextRandomSeed(random_seed_);
5905 repeater->OnTestProgramEnd(*parent_);
5907 if (!gtest_is_initialized_before_run_all_tests) {
5910 "\nIMPORTANT NOTICE - DO NOT IGNORE:\n"
5912 "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_
5913 " will start to enforce the valid usage. "
5914 "Please fix it ASAP, or IT WILL START TO FAIL.\n");
5915#if GTEST_FOR_GOOGLE_
5916 ColoredPrintf(GTestColor::kRed,
5917 "For more details, see http://wiki/Main/ValidGUnitMain.\n");
5929 const char*
const test_shard_file =
posix::GetEnv(kTestShardStatusFile);
5930 if (test_shard_file !=
nullptr) {
5932 if (
file ==
nullptr) {
5933 ColoredPrintf(GTestColor::kRed,
5934 "Could not write to the test shard status file \"%s\" "
5935 "specified by the %s environment variable.\n",
5936 test_shard_file, kTestShardStatusFile);
5951 const char* shard_index_env,
5952 bool in_subprocess_for_death_test) {
5953 if (in_subprocess_for_death_test) {
5960 if (total_shards == -1 && shard_index == -1) {
5962 }
else if (total_shards == -1 && shard_index != -1) {
5964 <<
"Invalid environment variables: you have "
5965 << kTestShardIndex <<
" = " << shard_index
5966 <<
", but have left " << kTestTotalShards <<
" unset.\n";
5967 ColoredPrintf(GTestColor::kRed,
"%s", msg.
GetString().c_str());
5970 }
else if (total_shards != -1 && shard_index == -1) {
5972 <<
"Invalid environment variables: you have "
5973 << kTestTotalShards <<
" = " << total_shards
5974 <<
", but have left " << kTestShardIndex <<
" unset.\n";
5975 ColoredPrintf(GTestColor::kRed,
"%s", msg.
GetString().c_str());
5978 }
else if (shard_index < 0 || shard_index >= total_shards) {
5980 <<
"Invalid environment variables: we require 0 <= "
5981 << kTestShardIndex <<
" < " << kTestTotalShards
5982 <<
", but you have " << kTestShardIndex <<
"=" << shard_index
5983 <<
", " << kTestTotalShards <<
"=" << total_shards <<
".\n";
5984 ColoredPrintf(GTestColor::kRed,
"%s", msg.
GetString().c_str());
5989 return total_shards > 1;
5997 if (str_val ==
nullptr) {
6003 str_val, &result)) {
6014 return (test_id % total_shards) == shard_index;
6024int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
6025 const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
6027 const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
6034 int num_runnable_tests = 0;
6035 int num_selected_tests = 0;
6036 for (
auto* test_suite : test_suites_) {
6037 const std::string& test_suite_name = test_suite->name();
6038 test_suite->set_should_run(
false);
6040 for (
size_t j = 0; j < test_suite->test_info_list().size(); j++) {
6041 TestInfo*
const test_info = test_suite->test_info_list()[j];
6042 const std::string test_name(test_info->
name());
6045 const bool is_disabled = internal::UnitTestOptions::MatchesFilter(
6046 test_suite_name, kDisableTestFilter) ||
6047 internal::UnitTestOptions::MatchesFilter(
6048 test_name, kDisableTestFilter);
6049 test_info->is_disabled_ = is_disabled;
6051 const bool matches_filter = internal::UnitTestOptions::FilterMatchesTest(
6052 test_suite_name, test_name);
6053 test_info->matches_filter_ = matches_filter;
6055 const bool is_runnable =
6056 (
GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
6059 const bool is_in_another_shard =
6060 shard_tests != IGNORE_SHARDING_PROTOCOL &&
6062 test_info->is_in_another_shard_ = is_in_another_shard;
6063 const bool is_selected = is_runnable && !is_in_another_shard;
6065 num_runnable_tests += is_runnable;
6066 num_selected_tests += is_selected;
6068 test_info->should_run_ = is_selected;
6069 test_suite->set_should_run(test_suite->should_run() || is_selected);
6072 return num_selected_tests;
6079static void PrintOnOneLine(
const char* str,
int max_length) {
6080 if (str !=
nullptr) {
6081 for (
int i = 0; *str !=
'\0'; ++str) {
6082 if (
i >= max_length) {
6098void UnitTestImpl::ListTestsMatchingFilter() {
6100 const int kMaxParamLength = 250;
6102 for (
auto* test_suite : test_suites_) {
6103 bool printed_test_suite_name =
false;
6105 for (
size_t j = 0; j < test_suite->test_info_list().size(); j++) {
6106 const TestInfo*
const test_info = test_suite->test_info_list()[j];
6107 if (test_info->matches_filter_) {
6108 if (!printed_test_suite_name) {
6109 printed_test_suite_name =
true;
6110 printf(
"%s.", test_suite->name());
6111 if (test_suite->type_param() !=
nullptr) {
6112 printf(
" # %s = ", kTypeParamLabel);
6115 PrintOnOneLine(test_suite->type_param(), kMaxParamLength);
6119 printf(
" %s", test_info->name());
6120 if (test_info->value_param() !=
nullptr) {
6121 printf(
" # %s = ", kValueParamLabel);
6124 PrintOnOneLine(test_info->value_param(), kMaxParamLength);
6131 const std::string& output_format = UnitTestOptions::GetOutputFormat();
6132 if (output_format ==
"xml" || output_format ==
"json") {
6133 FILE* fileout = OpenFileForWriting(
6134 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
6135 std::stringstream stream;
6136 if (output_format ==
"xml") {
6137 XmlUnitTestResultPrinter(
6138 UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
6139 .PrintXmlTestsList(&stream, test_suites_);
6140 }
else if (output_format ==
"json") {
6141 JsonUnitTestResultPrinter(
6142 UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
6143 .PrintJsonTestList(&stream, test_suites_);
6155void UnitTestImpl::set_os_stack_trace_getter(
6156 OsStackTraceGetterInterface* getter) {
6157 if (os_stack_trace_getter_ != getter) {
6158 delete os_stack_trace_getter_;
6159 os_stack_trace_getter_ = getter;
6166OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
6167 if (os_stack_trace_getter_ ==
nullptr) {
6168#ifdef GTEST_OS_STACK_TRACE_GETTER_
6169 os_stack_trace_getter_ =
new GTEST_OS_STACK_TRACE_GETTER_;
6171 os_stack_trace_getter_ =
new OsStackTraceGetter;
6175 return os_stack_trace_getter_;
6179TestResult* UnitTestImpl::current_test_result() {
6180 if (current_test_info_ !=
nullptr) {
6181 return ¤t_test_info_->result_;
6183 if (current_test_suite_ !=
nullptr) {
6184 return ¤t_test_suite_->ad_hoc_test_result_;
6186 return &ad_hoc_test_result_;
6191void UnitTestImpl::ShuffleTests() {
6193 ShuffleRange(random(), 0, last_death_test_suite_ + 1, &test_suite_indices_);
6196 ShuffleRange(random(), last_death_test_suite_ + 1,
6197 static_cast<int>(test_suites_.size()), &test_suite_indices_);
6200 for (
auto& test_suite : test_suites_) {
6201 test_suite->ShuffleTests(random());
6206void UnitTestImpl::UnshuffleTests() {
6207 for (
size_t i = 0;
i < test_suites_.size();
i++) {
6209 test_suites_[
i]->UnshuffleTests();
6211 test_suite_indices_[
i] =
static_cast<int>(
i);
6229 return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
6235class ClassUniqueToAlwaysTrue {};
6238bool IsTrue(
bool condition) {
return condition; }
6241#if GTEST_HAS_EXCEPTIONS
6245 throw ClassUniqueToAlwaysTrue();
6254 const size_t prefix_len = strlen(prefix);
6255 if (strncmp(*pstr, prefix, prefix_len) == 0) {
6256 *pstr += prefix_len;
6267static const char* ParseFlagValue(
const char* str,
const char* flag,
6268 bool def_optional) {
6270 if (str ==
nullptr || flag ==
nullptr)
return nullptr;
6274 const size_t flag_len = flag_str.length();
6275 if (strncmp(str, flag_str.c_str(), flag_len) != 0)
return nullptr;
6278 const char* flag_end = str + flag_len;
6281 if (def_optional && (flag_end[0] ==
'\0')) {
6288 if (flag_end[0] !=
'=')
return nullptr;
6291 return flag_end + 1;
6304static bool ParseBoolFlag(
const char* str,
const char* flag,
bool*
value) {
6306 const char*
const value_str = ParseFlagValue(str, flag,
true);
6309 if (value_str ==
nullptr)
return false;
6312 *
value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
6322 const char*
const value_str = ParseFlagValue(str, flag,
false);
6325 if (value_str ==
nullptr)
return false;
6336template <
typename String>
6337static bool ParseStringFlag(
const char* str,
const char* flag, String*
value) {
6339 const char*
const value_str = ParseFlagValue(str, flag,
false);
6342 if (value_str ==
nullptr)
return false;
6355static bool HasGoogleTestFlagPrefix(
const char* str) {
6373static void PrintColorEncoded(
const char* str) {
6374 GTestColor color = GTestColor::kDefault;
6381 const char*
p = strchr(str,
'@');
6383 ColoredPrintf(color,
"%s", str);
6387 ColoredPrintf(color,
"%s", std::string(str,
p).c_str());
6389 const char ch =
p[1];
6392 ColoredPrintf(color,
"@");
6393 }
else if (
ch ==
'D') {
6394 color = GTestColor::kDefault;
6395 }
else if (
ch ==
'R') {
6396 color = GTestColor::kRed;
6397 }
else if (
ch ==
'G') {
6398 color = GTestColor::kGreen;
6399 }
else if (
ch ==
'Y') {
6400 color = GTestColor::kYellow;
6407static const char kColorEncodedHelpMessage[] =
6408 "This program contains tests written using " GTEST_NAME_
6409 ". You can use the\n"
6410 "following command line flags to control its behavior:\n"
6415 " List the names of all tests instead of running them. The name of\n"
6416 " TEST(Foo, Bar) is \"Foo.Bar\".\n"
6418 "filter=@YPOSITIVE_PATTERNS"
6419 "[@G-@YNEGATIVE_PATTERNS]@D\n"
6420 " Run only the tests whose name matches one of the positive patterns "
6422 " none of the negative patterns. '?' matches any single character; "
6424 " matches any substring; ':' separates two patterns.\n"
6426 "also_run_disabled_tests@D\n"
6427 " Run all disabled tests too.\n"
6431 "repeat=@Y[COUNT]@D\n"
6432 " Run the tests repeatedly; use a negative count to repeat forever.\n"
6435 " Randomize tests' orders on every iteration.\n"
6437 "random_seed=@Y[NUMBER]@D\n"
6438 " Random number seed to use for shuffling test orders (between 1 and\n"
6439 " 99999, or 0 to use a seed based on the current time).\n"
6443 "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n"
6444 " Enable/disable colored output. The default is @Gauto@D.\n"
6447 " Only print test failures.\n"
6450 " Don't print the elapsed time of each test.\n"
6453 "@Y|@G:@YFILE_PATH]@D\n"
6454 " Generate a JSON or XML report in the given directory or with the "
6456 " file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n"
6457# if GTEST_CAN_STREAM_RESULTS_
6459 "stream_result_to=@YHOST@G:@YPORT@D\n"
6460 " Stream test results to the given server.\n"
6463 "Assertion Behavior:\n"
6464# if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
6466 "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
6467 " Set the default death test style.\n"
6470 "break_on_failure@D\n"
6471 " Turn assertion failures into debugger break-points.\n"
6473 "throw_on_failure@D\n"
6474 " Turn assertion failures into C++ exceptions for use by an external\n"
6475 " test framework.\n"
6477 "catch_exceptions=0@D\n"
6478 " Do not report exceptions as test failures. Instead, allow them\n"
6479 " to crash the program or throw a pop-up (on Windows).\n"
6482 "list_tests@D, you can alternatively set "
6483 "the corresponding\n"
6484 "environment variable of a flag (all letters in upper-case). For example, "
6486 "disable colored text output, you can either specify "
6488 "color=no@D or set\n"
6490 "COLOR@D environment variable to @Gno@D.\n"
6492 "For more information, please read the " GTEST_NAME_
6493 " documentation at\n"
6496 "(not one in your own code or tests), please report it to\n"
6499static bool ParseGoogleTestFlag(
const char*
const arg) {
6500 return ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag,
6502 ParseBoolFlag(arg, kBreakOnFailureFlag,
6504 ParseBoolFlag(arg, kCatchExceptionsFlag,
6506 ParseStringFlag(arg, kColorFlag, &
GTEST_FLAG(color)) ||
6511 ParseBoolFlag(arg, kFailFast, &
GTEST_FLAG(fail_fast)) ||
6512 ParseStringFlag(arg, kFilterFlag, &
GTEST_FLAG(filter)) ||
6515 ParseBoolFlag(arg, kListTestsFlag, &
GTEST_FLAG(list_tests)) ||
6517 ParseBoolFlag(arg, kBriefFlag, &
GTEST_FLAG(brief)) ||
6518 ParseBoolFlag(arg, kPrintTimeFlag, &
GTEST_FLAG(print_time)) ||
6519 ParseBoolFlag(arg, kPrintUTF8Flag, &
GTEST_FLAG(print_utf8)) ||
6522 ParseBoolFlag(arg, kShuffleFlag, &
GTEST_FLAG(shuffle)) ||
6525 ParseStringFlag(arg, kStreamResultToFlag,
6527 ParseBoolFlag(arg, kThrowOnFailureFlag, &
GTEST_FLAG(throw_on_failure));
6530#if GTEST_USE_OWN_FLAGFILE_FLAG_
6531static void LoadFlagsFromFile(
const std::string& path) {
6539 std::vector<std::string> lines;
6541 for (
size_t i = 0;
i < lines.size(); ++
i) {
6542 if (lines[
i].empty())
6544 if (!ParseGoogleTestFlag(lines[
i].c_str()))
6553template <
typename CharType>
6555 for (
int i = 1;
i < *argc;
i++) {
6557 const char*
const arg = arg_string.c_str();
6559 using internal::ParseBoolFlag;
6561 using internal::ParseStringFlag;
6563 bool remove_flag =
false;
6564 if (ParseGoogleTestFlag(arg)) {
6566#if GTEST_USE_OWN_FLAGFILE_FLAG_
6567 }
else if (ParseStringFlag(arg, kFlagfileFlag, &
GTEST_FLAG(flagfile))) {
6571 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
6572 arg_string ==
"-?" || arg_string ==
"/?" ||
6573 HasGoogleTestFlagPrefix(arg)) {
6584 for (
int j =
i; j != *argc; j++) {
6585 argv[j] = argv[j + 1];
6601 PrintColorEncoded(kColorEncodedHelpMessage);
6615 if (*_NSGetArgv() == argv) {
6616 *_NSGetArgc() = *argc;
6629template <
typename CharType>
6632 if (GTestIsInitialized())
return;
6634 if (*argc <= 0)
return;
6637 for (
int i = 0;
i != *argc;
i++) {
6642 absl::InitializeSymbolizer(
g_argvs[0].c_str());
6646 GetUnitTestImpl()->PostFlagParsingInit();
6661#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6662 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6671#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6672 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6683 const auto arg0 =
"dummy";
6684 char* argv0 =
const_cast<char*
>(arg0);
6685 char** argv = &argv0;
6687#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6688 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(&argc, argv);
6695#if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
6696 return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
6697#elif GTEST_OS_WINDOWS_MOBILE
6699#elif GTEST_OS_WINDOWS
6701 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0') {
6703 }
else if (temp_dir[strlen(temp_dir) - 1] ==
'\\') {
6706 return std::string(temp_dir) +
"\\";
6708#elif GTEST_OS_LINUX_ANDROID
6710 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0') {
6711 return "/data/local/tmp/";
6717 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0') {
6731void ScopedTrace::PushTrace(
const char*
file,
int line, std::string
message) {
6732 internal::TraceInfo trace;
6737 UnitTest::GetInstance()->PushGTestTrace(trace);
6741ScopedTrace::~ScopedTrace()
6743 UnitTest::GetInstance()->PopGTestTrace();
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3)
#define GTEST_FLAG_PREFIX_
#define GTEST_FLAG_SAVER_
#define GTEST_FLAG_PREFIX_UPPER_
#define GTEST_FLAG_PREFIX_DASH_
#define GTEST_PROJECT_URL_
#define GTEST_LOCK_EXCLUDED_(locks)
#define GTEST_LOG_(severity)
#define GTEST_INIT_GOOGLE_TEST_NAME_
#define GTEST_CHECK_(condition)
#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
#define GTEST_REPEATER_METHOD_(Name, Type)
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type)
ICOORD operator!(const ICOORD &src)
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_DEFINE_bool_(death_test_use_fork, internal::BoolFromGTestEnv("death_test_use_fork", false), "Instructs to use fork()/_exit() instead of clone() in death tests. " "Ignored and always uses fork() on POSIX systems where clone() is not " "implemented. Useful when running under valgrind or similar tools if " "those do not support clone(). Valgrind 3.3.1 will just fail if " "it sees an unsupported combination of clone() flags. " "It is not recommended to use this flag w/o valgrind though it will " "work in 99% of the cases. Once valgrind is fixed, this flag will " "most likely be removed.")
AssertionResult AssertionFailure(const Message &message)
GTEST_DEFINE_string_(death_test_style, internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle), "Indicates how to run a death test in a forked child process: " "\"threadsafe\" (child process re-executes the test binary " "from the beginning, running only the specific death test) or " "\"fast\" (child process runs the death test immediately " "after forking).")
AssertionResult AssertionFailure()
TestInfo * RegisterTest(const char *test_suite_name, const char *test_name, const char *type_param, const char *value_param, const char *file, int line, Factory factory)
GTEST_DEFINE_int32_(random_seed, internal::Int32FromGTestEnv("random_seed", 0), "Random number seed to use when shuffling test orders. Must be in range " "[1, 99999], or 0 to use a seed based on the current time.")
::std::string PrintToString(const T &value)
GTEST_API_ std::string TempDir()
std::vector< std::string > ArrayAsVector(const char *const (&array)[kSize])
AssertionResult AssertionSuccess()
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
const char kDeathTestStyleFlag[]
std::string WideStringToUtf8(const wchar_t *str, int num_chars)
GTEST_API_ AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
std::string OutputFlagAlsoCheckEnvVar()
AssertionResult FloatingPointLE(const char *expr1, const char *expr2, RawType val1, RawType val2)
void WriteToShardStatusFileIfNeeded()
static ::std::vector< std::string > g_argvs
GTEST_API_::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251) class GTEST_API_ TypedTestSuitePState
GTEST_API_ std::string ReadEntireFile(FILE *file)
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
const char kDeathTestUseFork[]
GTEST_API_ void InsertSyntheticTestCase(const std::string &name, CodeLocation location, bool has_test_p)
bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
GTEST_API_ void RegisterTypeParameterizedTestSuite(const char *test_suite_name, CodeLocation code_location)
GTEST_API_ bool ParseInt32(const Message &src_text, const char *str, int32_t *value)
GTEST_API_ AssertionResult DoubleNearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, double val1, double val2, double abs_error)
GTEST_API_ bool IsTrue(bool condition)
std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
bool BoolFromGTestEnv(const char *flag, bool default_val)
uint32_t CreateCodePointFromUtf16SurrogatePair(wchar_t first, wchar_t second)
bool IsUtf16SurrogatePair(wchar_t first, wchar_t second)
int32_t Int32FromEnvOrDie(const char *var, int32_t default_val)
bool ParseInt32Flag(const char *str, const char *flag, int32_t *value)
GTEST_API_ AssertionResult CmpHelperSTREQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
FilePath GetCurrentExecutableName()
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
const char * StringFromGTestEnv(const char *flag, const char *default_val)
GTEST_API_ void RegisterTypeParameterizedTestSuiteInstantiation(const char *case_name)
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_suite_name, const char *name, const char *type_param, const char *value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc, TearDownTestSuiteFunc tear_down_tc, TestFactoryBase *factory)
void(*)() TearDownTestSuiteFunc
constexpr uint32_t kMaxCodePoint3
void(*)() SetUpTestSuiteFunc
const char kInternalRunDeathTestFlag[]
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string &message)
bool ShouldShard(const char *total_shards_env, const char *shard_index_env, bool in_subprocess_for_death_test)
void SplitString(const ::std::string &str, char delimiter, ::std::vector< ::std::string > *dest)
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
GTEST_API_ bool AlwaysTrue()
GTEST_API_ std::vector< std::string > GetArgvs()
void ParseGoogleTestFlagsOnly(int *argc, wchar_t **argv)
std::string StreamableToString(const T &streamable)
constexpr uint32_t kMaxCodePoint2
GTEST_API_ const char kStackTraceMarker[]
GTEST_API_ void ReportInvalidTestSuiteType(const char *test_suite_name, CodeLocation code_location)
GTEST_API_ int32_t Int32FromGTestEnv(const char *flag, int32_t default_val)
GTEST_API_ std::string StringStreamToString(::std::stringstream *stream)
bool ShouldUseColor(bool stdout_is_tty)
void InitGoogleTestImpl(int *argc, CharType **argv)
Result HandleSehExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
GTEST_DISABLE_MSC_WARNINGS_POP_() inline const char *SkipComma(const char *str)
const TypeId kTestTypeIdInGoogleTest
GTEST_API_ TypeId GetTestTypeId()
std::string CodePointToUtf8(uint32_t code_point)
void PrintTo(const T &value, ::std::ostream *os)
Result HandleExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
void ParseGoogleTestFlagsOnlyImpl(int *argc, CharType **argv)
TimeInMillis GetTimeInMillis()
constexpr uint32_t kMaxCodePoint1
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ AssertionResult CmpHelperSTRNE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
constexpr uint32_t kMaxCodePoint4
std::set< std::string > * GetIgnoredParameterizedTestSuites()
uint32_t ChopLowBits(uint32_t *bits, int n)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
int StrCaseCmp(const char *s1, const char *s2)
const char * GetEnv(const char *name)
FILE * FOpen(const char *path, const char *mode)
std::string GetString() const
Message & operator<<(const T &val)
static void RecordProperty(const std::string &key, const std::string &value)
static bool HasFatalFailure()
bool HasFatalFailure() const
bool HasNonfatalFailure() const
int total_part_count() const
const TestProperty & GetTestProperty(int i) const
TimeInMillis elapsed_time() const
const TestPartResult & GetTestPartResult(int i) const
int test_property_count() const
const char * file() const
const char * name() const
const TestResult * result() const
friend class internal::UnitTestImpl
const char * test_suite_name() const
int test_to_run_count() const
int reportable_test_count() const
const char * name() const
TestSuite(const char *name, const char *a_type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc)
TimeInMillis elapsed_time() const
int total_test_count() const
const char * type_param() const
const TestInfo * GetTestInfo(int i) const
int successful_test_count() const
int failed_test_count() const
int reportable_disabled_test_count() const
friend class internal::UnitTestImpl
int disabled_test_count() const
int skipped_test_count() const
virtual void OnTestSuiteStart(const TestSuite &)
virtual void OnTestSuiteEnd(const TestSuite &)
virtual void OnTestStart(const TestInfo &test_info)=0
TestEventListener * Release(TestEventListener *listener)
void Append(TestEventListener *listener)
int skipped_test_count() const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
int failed_test_suite_count() const
static UnitTest * GetInstance()
int reportable_disabled_test_count() const
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
int Run() GTEST_MUST_USE_RESULT_
TimeInMillis start_timestamp() const
int reportable_test_count() const
int test_to_run_count() const
int successful_test_count() const
const TestCase * GetTestCase(int i) const
int total_test_case_count() const
int test_case_to_run_count() const
const TestSuite * GetTestSuite(int i) const
internal::ParameterizedTestSuiteRegistry & parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_)
const TestResult & ad_hoc_test_result() const
TestEventListeners & listeners()
const TestSuite * current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_)
int failed_test_case_count() const
int successful_test_case_count() const
int failed_test_count() const
TimeInMillis elapsed_time() const
int disabled_test_count() const
int test_suite_to_run_count() const
int successful_test_suite_count() const
const char * original_working_dir() const
int total_test_count() const
int total_test_suite_count() const
void operator=(const Message &message) const
AssertHelper(TestPartResult::Type type, const char *file, int line, const char *message)
virtual Test * CreateTest()=0
uint32_t Generate(uint32_t range)
static const uint32_t kMaxRange
MarkAsIgnored(const char *test_suite)
void RegisterTestSuite(const char *test_suite_name, CodeLocation code_location)
void CheckForInstantiations()
void RegisterInstantiation(const char *test_suite_name)
static bool CaseInsensitiveCStringEquals(const char *lhs, const char *rhs)
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
static std::string FormatHexUInt32(uint32_t value)
static bool CStringEquals(const char *lhs, const char *rhs)
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
static std::string ShowWideCString(const wchar_t *wide_c_str)
static bool WideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
static std::string FormatIntWidthN(int value, int width)
static std::string FormatIntWidth2(int value)
static std::string FormatByte(unsigned char value)
static std::string FormatHexInt(int value)
void OnTestStart(const TestInfo &test_info) override
void OnTestEnd(const TestInfo &test_info) override
void OnTestIterationStart(const UnitTest &unit_test, int iteration) override
void OnTestProgramStart(const UnitTest &) override
void OnTestProgramEnd(const UnitTest &) override
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
void OnEnvironmentsTearDownEnd(const UnitTest &) override
void OnTestCaseStart(const TestCase &test_case) override
void OnTestPartResult(const TestPartResult &result) override
PrettyUnitTestResultPrinter()
void OnEnvironmentsTearDownStart(const UnitTest &unit_test) override
void OnEnvironmentsSetUpEnd(const UnitTest &) override
static void PrintTestName(const char *test_suite, const char *test)
void OnEnvironmentsSetUpStart(const UnitTest &unit_test) override
void OnTestCaseEnd(const TestCase &test_case) override
void OnEnvironmentsTearDownStart(const UnitTest &) override
void OnTestIterationStart(const UnitTest &, int) override
BriefUnitTestResultPrinter()
void OnTestCaseStart(const TestCase &) override
void OnEnvironmentsSetUpStart(const UnitTest &) override
void OnEnvironmentsTearDownEnd(const UnitTest &) override
void OnTestProgramStart(const UnitTest &) override
void OnTestProgramEnd(const UnitTest &) override
void OnTestEnd(const TestInfo &test_info) override
static void PrintTestName(const char *test_suite, const char *test)
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
void OnTestStart(const TestInfo &) override
void OnTestCaseEnd(const TestCase &) override
void OnTestPartResult(const TestPartResult &result) override
void OnEnvironmentsSetUpEnd(const UnitTest &) override
void OnEnvironmentsTearDownEnd(const UnitTest &unit_test) override
void OnTestEnd(const TestInfo &test_info) override
void OnTestProgramEnd(const UnitTest &unit_test) override
void OnTestStart(const TestInfo &test_info) override
void OnTestSuiteEnd(const TestSuite ¶meter) override
void OnEnvironmentsSetUpStart(const UnitTest &unit_test) override
void OnEnvironmentsSetUpEnd(const UnitTest &unit_test) override
void OnTestCaseStart(const TestSuite ¶meter) override
void set_forwarding_enabled(bool enable)
~TestEventRepeater() override
void OnTestCaseEnd(const TestCase ¶meter) override
void OnTestIterationStart(const UnitTest &unit_test, int iteration) override
void OnEnvironmentsTearDownStart(const UnitTest &unit_test) override
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
void OnTestSuiteStart(const TestSuite ¶meter) override
void OnTestPartResult(const TestPartResult &result) override
bool forwarding_enabled() const
void OnTestProgramStart(const UnitTest &unit_test) override
TestEventListener * Release(TestEventListener *listener)
void Append(TestEventListener *listener)
static void PrintXmlTestsList(std::ostream *stream, const std::vector< TestSuite * > &test_suites)
void ListTestsMatchingFilter(const std::vector< TestSuite * > &test_suites)
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
XmlUnitTestResultPrinter(const char *output_file)
JsonUnitTestResultPrinter(const char *output_file)
static void PrintJsonTestList(::std::ostream *stream, const std::vector< TestSuite * > &test_suites)
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
ScopedPrematureExitFile(const char *premature_exit_filepath)
~ScopedPrematureExitFile()
bool operator()(const TestSuite *test_suite) const
TestSuiteNameIs(const std::string &name)