57 # define GTEST_HAS_GETTIMEOFDAY_ 1
64 # include <sys/mman.h>
65 # include <sys/time.h>
70 # define GTEST_HAS_GETTIMEOFDAY_ 1
71 # include <sys/time.h>
76 #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE.
81 #elif GTEST_OS_WINDOWS // We are on Windows proper.
84 # include <sys/timeb.h>
85 # include <sys/types.h>
86 # include <sys/stat.h>
88 # if GTEST_OS_WINDOWS_MINGW
90 # define GTEST_HAS_GETTIMEOFDAY_ 1
91 # include <sys/time.h>
92 # endif // GTEST_OS_WINDOWS_MINGW
102 # define GTEST_HAS_GETTIMEOFDAY_ 1
106 # include <sys/time.h>
109 #endif // GTEST_OS_LINUX
111 #if GTEST_HAS_EXCEPTIONS
112 # include <stdexcept>
115 #if GTEST_CAN_STREAM_RESULTS_
116 # include <arpa/inet.h>
118 # include <sys/socket.h>
119 # include <sys/types.h>
125 # define vsnprintf _vsnprintf
126 #endif // GTEST_OS_WINDOWS
130 #include <crt_externs.h>
135 #include "absl/debugging/failure_signal_handler.h"
136 #include "absl/debugging/stacktrace.h"
137 #include "absl/debugging/symbolize.h"
138 #include "absl/strings/str_cat.h"
139 #endif // GTEST_HAS_ABSL
143 using internal::CountIf;
144 using internal::ForEach;
145 using internal::GetElementOr;
146 using internal::Shuffle;
186 FILE* fileout =
nullptr;
187 FilePath output_file_path(output_file);
190 if (
output_dir.CreateDirectoriesRecursively()) {
193 if (fileout ==
nullptr) {
204 const char*
const testbridge_test_only =
206 if (testbridge_test_only !=
nullptr) {
207 return testbridge_test_only;
213 also_run_disabled_tests,
215 "Run disabled tests too, in addition to the tests normally being run.");
220 "True iff a failed assertion should be a debugger break-point.");
226 " should catch exceptions and treat them as test failures.");
231 "Whether to use colors in the output. Valid values: yes, no, "
232 "and auto. 'auto' means to use colors if the output is "
233 "being sent to a terminal and the TERM environment variable "
234 "is set to a terminal type that supports colors.");
239 "A colon-separated list of glob (not regex) patterns "
240 "for filtering the tests to run, optionally followed by a "
241 "'-' and a : separated list of negative patterns (tests to "
242 "exclude). A test is run if it matches one of the positive "
243 "patterns and does not match any of the negative patterns.");
246 install_failure_signal_handler,
248 "If true and supported on the current platform, " GTEST_NAME_ " should "
249 "install a signal handler that dumps debugging information when fatal "
250 "signals are raised.");
253 "List all tests without running them.");
264 "A format (defaults to \"xml\" but can be specified to be \"json\"), "
265 "optionally followed by a colon and an output file name or directory. "
266 "A directory is indicated by a trailing pathname separator. "
267 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
268 "If a directory is specified, output files will be created "
269 "within that directory, with file-names based on the test "
270 "executable's name and, if necessary, made unique by adding "
277 " should display elapsed time in text output.");
283 " prints UTF8 characters as text.");
288 "Random number seed to use when shuffling test orders. Must be in range "
289 "[1, 99999], or 0 to use a seed based on the current time.");
294 "How many times to repeat each test. Specify a negative number "
295 "for repeating forever. Useful for shaking out flaky tests.");
298 show_internal_stack_frames,
false,
299 "True iff " GTEST_NAME_ " should include internal stack frames when "
300 "printing test failure stack traces.");
306 " should randomize tests' order on every run.");
311 "The maximum number of stack frames to print when an "
312 "assertion fails. The valid range is 0 through 100, inclusive.");
317 "This flag specifies the host name and the port number on which to stream "
318 "test results. Example: \"localhost:555\". The flag is effective only on "
324 "When this flag is specified, a failed assertion will throw an exception "
325 "if exceptions are enabled or exit the program with a non-zero code "
326 "otherwise. For use with an external test framework.");
328 #if GTEST_USE_OWN_FLAGFILE_FLAG_
332 "This flag specifies the flagfile to read command-line flags from.");
333 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
346 <<
"Cannot generate a number in the range [0, 0).";
348 <<
"Generation of a number in [0, " <<
range <<
") was requested, "
349 <<
"but this can only generate numbers in [0, " <<
kMaxRange <<
").";
368 for (
size_t i = 0;
i < case_list.size();
i++) {
369 sum += (case_list[
i]->*
method)();
408 ->CurrentOsStackTraceExceptTop(1)
417 #if defined(GTEST_CUSTOM_GET_ARGVS_)
420 const auto& custom = GTEST_CUSTOM_GET_ARGVS_();
421 return ::std::vector<std::string>(custom.begin(), custom.end());
422 #else // defined(GTEST_CUSTOM_GET_ARGVS_)
424 #endif // defined(GTEST_CUSTOM_GET_ARGVS_)
432 #if GTEST_OS_WINDOWS || GTEST_OS_OS2
436 #endif // GTEST_OS_WINDOWS
438 return result.RemoveDirectoryName();
446 const char*
const colon = strchr(gtest_output_flag,
':');
447 return (colon ==
nullptr)
449 :
std::
string(gtest_output_flag, colon - gtest_output_flag);
454 std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
461 const char*
const colon = strchr(gtest_output_flag,
':');
462 if (colon ==
nullptr)
463 return internal::FilePath::MakeFileName(
470 if (!output_name.IsAbsolutePath())
471 output_name = internal::FilePath::ConcatPaths(
475 if (!output_name.IsDirectory())
476 return output_name.string();
480 GetOutputFormat().c_str()));
481 return result.string();
489 bool UnitTestOptions::PatternMatchesString(
const char *pattern,
496 return *
str !=
'\0' && PatternMatchesString(pattern + 1,
str + 1);
498 return (*
str !=
'\0' && PatternMatchesString(pattern,
str + 1)) ||
499 PatternMatchesString(pattern + 1,
str);
501 return *pattern == *
str &&
502 PatternMatchesString(pattern + 1,
str + 1);
506 bool UnitTestOptions::MatchesFilter(
508 const char *cur_pattern =
filter;
510 if (PatternMatchesString(cur_pattern,
name.c_str())) {
515 cur_pattern = strchr(cur_pattern,
':');
518 if (cur_pattern ==
nullptr) {
529 bool UnitTestOptions::FilterMatchesTest(
const std::string& test_suite_name,
531 const std::string& full_name = test_suite_name +
"." + test_name.c_str();
536 const char*
const dash = strchr(
p,
'-');
539 if (dash ==
nullptr) {
545 if (positive.empty()) {
553 return (MatchesFilter(full_name, positive.c_str()) &&
554 !MatchesFilter(full_name, negative.c_str()));
561 int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
570 const DWORD kCxxExceptionCode = 0xe06d7363;
572 bool should_handle =
true;
575 should_handle =
false;
576 else if (exception_code == EXCEPTION_BREAKPOINT)
577 should_handle =
false;
578 else if (exception_code == kCxxExceptionCode)
579 should_handle =
false;
581 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
583 #endif // GTEST_HAS_SEH
590 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
591 TestPartResultArray* result)
592 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
600 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
601 InterceptMode intercept_mode, TestPartResultArray* result)
602 : intercept_mode_(intercept_mode),
608 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
609 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
610 old_reporter_ = impl->GetGlobalTestPartResultReporter();
611 impl->SetGlobalTestPartResultReporter(
this);
613 old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
614 impl->SetTestPartResultReporterForCurrentThread(
this);
620 ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
621 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
622 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
623 impl->SetGlobalTestPartResultReporter(old_reporter_);
625 impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
631 void ScopedFakeTestPartResultReporter::ReportTestPartResult(
632 const TestPartResult& result) {
633 result_->Append(result);
648 return GetTypeId<Test>();
661 const TestPartResultArray&
results,
666 "1 non-fatal failure");
669 msg <<
"Expected: " << expected <<
"\n"
670 <<
" Actual: " <<
results.size() <<
" failures";
672 msg <<
"\n" <<
results.GetTestPartResult(
i);
677 const TestPartResult&
r =
results.GetTestPartResult(0);
678 if (
r.type() !=
type) {
684 if (strstr(
r.message(), substr.c_str()) ==
nullptr) {
697 SingleFailureChecker::SingleFailureChecker(
const TestPartResultArray*
results,
700 : results_(
results), type_(
type), substr_(substr) {}
706 SingleFailureChecker::~SingleFailureChecker() {
710 DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
711 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
713 void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
714 const TestPartResult& result) {
715 unit_test_->current_test_result()->AddTestPartResult(result);
716 unit_test_->listeners()->repeater()->OnTestPartResult(result);
719 DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
720 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
722 void DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
723 const TestPartResult& result) {
724 unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
728 TestPartResultReporterInterface*
729 UnitTestImpl::GetGlobalTestPartResultReporter() {
731 return global_test_part_result_repoter_;
735 void UnitTestImpl::SetGlobalTestPartResultReporter(
736 TestPartResultReporterInterface* reporter) {
738 global_test_part_result_repoter_ = reporter;
742 TestPartResultReporterInterface*
743 UnitTestImpl::GetTestPartResultReporterForCurrentThread() {
744 return per_thread_test_part_result_reporter_.get();
748 void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
749 TestPartResultReporterInterface* reporter) {
750 per_thread_test_part_result_reporter_.set(reporter);
754 int UnitTestImpl::successful_test_suite_count()
const {
759 int UnitTestImpl::failed_test_suite_count()
const {
764 int UnitTestImpl::total_test_suite_count()
const {
765 return static_cast<int>(test_suites_.size());
770 int UnitTestImpl::test_suite_to_run_count()
const {
775 int UnitTestImpl::successful_test_count()
const {
780 int UnitTestImpl::skipped_test_count()
const {
785 int UnitTestImpl::failed_test_count()
const {
790 int UnitTestImpl::reportable_disabled_test_count()
const {
796 int UnitTestImpl::disabled_test_count()
const {
801 int UnitTestImpl::reportable_test_count()
const {
806 int UnitTestImpl::total_test_count()
const {
811 int UnitTestImpl::test_to_run_count()
const {
825 std::string UnitTestImpl::CurrentOsStackTraceExceptTop(
int skip_count) {
826 return os_stack_trace_getter()->CurrentStackTrace(
827 static_cast<int>(
GTEST_FLAG(stack_trace_depth)),
836 #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
841 const DWORD kTenthMicrosInMilliSecond = 10000;
843 SYSTEMTIME now_systime;
844 FILETIME now_filetime;
845 ULARGE_INTEGER now_int64;
846 GetSystemTime(&now_systime);
847 if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
848 now_int64.LowPart = now_filetime.dwLowDateTime;
849 now_int64.HighPart = now_filetime.dwHighDateTime;
850 now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
851 kJavaEpochToWinFileTimeDelta;
852 return now_int64.QuadPart;
855 #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
864 return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
867 gettimeofday(&now,
nullptr);
868 return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
870 #
error "Don't know how to get the current time on your system."
878 #if GTEST_OS_WINDOWS_MOBILE
883 LPCWSTR String::AnsiToUtf16(
const char* ansi) {
884 if (!ansi)
return nullptr;
885 const int length = strlen(ansi);
886 const int unicode_length =
887 MultiByteToWideChar(CP_ACP, 0, ansi,
length,
nullptr, 0);
888 WCHAR* unicode =
new WCHAR[unicode_length + 1];
889 MultiByteToWideChar(CP_ACP, 0, ansi,
length,
890 unicode, unicode_length);
891 unicode[unicode_length] = 0;
899 const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
900 if (!utf16_str)
return nullptr;
901 const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
nullptr,
902 0,
nullptr,
nullptr);
903 char* ansi =
new char[ansi_length + 1];
904 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, ansi, ansi_length,
nullptr,
906 ansi[ansi_length] = 0;
910 #endif // GTEST_OS_WINDOWS_MOBILE
917 bool String::CStringEquals(
const char * lhs,
const char * rhs) {
918 if (lhs ==
nullptr)
return rhs ==
nullptr;
920 if (rhs ==
nullptr)
return false;
922 return strcmp(lhs, rhs) == 0;
925 #if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
929 static void StreamWideCharsToMessage(
const wchar_t* wstr,
size_t length,
932 if (wstr[
i] != L
'\0') {
933 *msg << WideStringToUtf8(wstr + i, static_cast<int>(
length -
i));
934 while (
i !=
length && wstr[
i] != L
'\0')
943 #endif // GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
946 ::std::vector< ::std::string>*
dest) {
947 ::std::vector< ::std::string> parsed;
948 ::std::string::size_type pos = 0;
950 const ::std::string::size_type colon =
str.find(delimiter, pos);
951 if (colon == ::std::string::npos) {
952 parsed.push_back(
str.substr(pos));
955 parsed.push_back(
str.substr(pos, colon - pos));
969 Message::Message() : ss_(new ::
std::stringstream) {
972 *
ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
984 #if GTEST_HAS_STD_WSTRING
988 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
991 #endif // GTEST_HAS_STD_WSTRING
993 #if GTEST_HAS_GLOBAL_WSTRING
997 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
1000 #endif // GTEST_HAS_GLOBAL_WSTRING
1010 AssertionResult::AssertionResult(
const AssertionResult& other)
1011 : success_(other.success_),
1012 message_(other.message_.
get() != nullptr
1014 : static_cast< ::
std::
string*>(nullptr)) {}
1019 swap(success_, other.success_);
1020 swap(message_, other.message_);
1025 AssertionResult negation(!success_);
1026 if (message_.get() !=
nullptr) negation << *message_;
1032 return AssertionResult(
true);
1037 return AssertionResult(
false);
1048 namespace edit_distance {
1050 const std::vector<size_t>& right) {
1051 std::vector<std::vector<double> > costs(
1052 left.size() + 1, std::vector<double>(right.size() + 1));
1053 std::vector<std::vector<EditType> > best_move(
1054 left.size() + 1, std::vector<EditType>(right.size() + 1));
1057 for (
size_t l_i = 0; l_i < costs.size(); ++l_i) {
1058 costs[l_i][0] =
static_cast<double>(l_i);
1062 for (
size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
1063 costs[0][r_i] =
static_cast<double>(r_i);
1064 best_move[0][r_i] =
kAdd;
1067 for (
size_t l_i = 0; l_i <
left.size(); ++l_i) {
1068 for (
size_t r_i = 0; r_i < right.size(); ++r_i) {
1069 if (
left[l_i] == right[r_i]) {
1071 costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
1072 best_move[l_i + 1][r_i + 1] =
kMatch;
1076 const double add = costs[l_i + 1][r_i];
1077 const double remove = costs[l_i][r_i + 1];
1078 const double replace = costs[l_i][r_i];
1079 if (add < remove && add < replace) {
1080 costs[l_i + 1][r_i + 1] = add + 1;
1081 best_move[l_i + 1][r_i + 1] =
kAdd;
1082 }
else if (remove < add && remove < replace) {
1083 costs[l_i + 1][r_i + 1] = remove + 1;
1084 best_move[l_i + 1][r_i + 1] =
kRemove;
1088 costs[l_i + 1][r_i + 1] = replace + 1.00001;
1089 best_move[l_i + 1][r_i + 1] =
kReplace;
1095 std::vector<EditType> best_path;
1096 for (
size_t l_i =
left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
1097 EditType move = best_move[l_i][r_i];
1098 best_path.push_back(move);
1099 l_i -= move !=
kAdd;
1102 std::reverse(best_path.begin(), best_path.end());
1109 class InternalStrings {
1113 if (
it !=
ids_.end())
return it->second;
1114 size_t id =
ids_.size();
1119 typedef std::map<std::string, size_t> IdMap;
1126 const std::vector<std::string>&
left,
1127 const std::vector<std::string>& right) {
1128 std::vector<size_t> left_ids, right_ids;
1130 InternalStrings intern_table;
1131 for (
size_t i = 0;
i <
left.size(); ++
i) {
1132 left_ids.push_back(intern_table.GetId(
left[
i]));
1134 for (
size_t i = 0;
i < right.size(); ++
i) {
1135 right_ids.push_back(intern_table.GetId(right[
i]));
1149 Hunk(
size_t left_start,
size_t right_start)
1156 void PushLine(
char edit,
const char* line) {
1161 hunk_.push_back(std::make_pair(
' ', line));
1169 hunk_adds_.push_back(std::make_pair(
'+', line));
1174 void PrintTo(std::ostream* os) {
1177 for (std::list<std::pair<char, const char*> >::const_iterator
it =
1180 *os <<
it->first <<
it->second <<
"\n";
1196 void PrintHeader(std::ostream* ss)
const {
1225 const std::vector<std::string>& right,
1229 size_t l_i = 0, r_i = 0, edit_i = 0;
1230 std::stringstream ss;
1231 while (edit_i < edits.size()) {
1233 while (edit_i < edits.size() && edits[edit_i] ==
kMatch) {
1240 const size_t prefix_context = std::min(l_i, context);
1241 Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
1242 for (
size_t i = prefix_context;
i > 0; --
i) {
1243 hunk.PushLine(
' ',
left[l_i -
i].c_str());
1248 size_t n_suffix = 0;
1249 for (; edit_i < edits.size(); ++edit_i) {
1250 if (n_suffix >= context) {
1252 std::vector<EditType>::const_iterator
it = edits.begin() + edit_i;
1254 if (
it == edits.end() || (
it - edits.begin()) - edit_i >= context) {
1262 n_suffix = edit ==
kMatch ? n_suffix + 1 : 0;
1265 hunk.PushLine(edit ==
kMatch ?
' ' :
'-',
left[l_i].c_str());
1268 hunk.PushLine(
'+', right[r_i].c_str());
1272 l_i += edit !=
kAdd;
1276 if (!hunk.has_edits()) {
1293 std::vector<std::string> SplitEscapedString(
const std::string&
str) {
1294 std::vector<std::string> lines;
1300 bool escaped =
false;
1304 if (
str[
i] ==
'n') {
1309 escaped =
str[
i] ==
'\\';
1334 const char* rhs_expression,
1337 bool ignoring_case) {
1339 msg <<
"Expected equality of these values:";
1340 msg <<
"\n " << lhs_expression;
1341 if (lhs_value != lhs_expression) {
1342 msg <<
"\n Which is: " << lhs_value;
1344 msg <<
"\n " << rhs_expression;
1345 if (rhs_value != rhs_expression) {
1346 msg <<
"\n Which is: " << rhs_value;
1349 if (ignoring_case) {
1350 msg <<
"\nIgnoring case";
1353 if (!lhs_value.empty() && !rhs_value.empty()) {
1354 const std::vector<std::string> lhs_lines =
1355 SplitEscapedString(lhs_value);
1356 const std::vector<std::string> rhs_lines =
1357 SplitEscapedString(rhs_value);
1358 if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
1359 msg <<
"\nWith diff:\n"
1369 const AssertionResult& assertion_result,
1370 const char* expression_text,
1371 const char* actual_predicate_value,
1372 const char* expected_predicate_value) {
1373 const char* actual_message = assertion_result.message();
1375 msg <<
"Value of: " << expression_text
1376 <<
"\n Actual: " << actual_predicate_value;
1377 if (actual_message[0] !=
'\0')
1378 msg <<
" (" << actual_message <<
")";
1379 msg <<
"\nExpected: " << expected_predicate_value;
1386 const char* abs_error_expr,
1390 const double diff = fabs(val1 - val2);
1394 <<
"The difference between " << expr1 <<
" and " << expr2
1395 <<
" is " << diff <<
", which exceeds " << abs_error_expr <<
", where\n"
1396 << expr1 <<
" evaluates to " << val1 <<
",\n"
1397 << expr2 <<
" evaluates to " << val2 <<
", and\n"
1398 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1403 template <
typename RawType>
1415 if (lhs.AlmostEquals(rhs)) {
1423 ::std::stringstream val1_ss;
1424 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1427 ::std::stringstream val2_ss;
1428 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1432 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n"
1441 AssertionResult
FloatLE(
const char* expr1,
const char* expr2,
1442 float val1,
float val2) {
1443 return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
1448 AssertionResult
DoubleLE(
const char* expr1,
const char* expr2,
1449 double val1,
double val2) {
1450 return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
1458 const char* rhs_expression,
1475 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
1476 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1477 BiggestInt val1, BiggestInt val2) {\
1478 if (val1 op val2) {\
1479 return AssertionSuccess();\
1481 return AssertionFailure() \
1482 << "Expected: (" << expr1 << ") " #op " (" << expr2\
1483 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
1484 << " vs " << FormatForComparisonFailureMessage(val2, val1);\
1504 #undef GTEST_IMPL_CMP_HELPER_
1508 const char* rhs_expression,
1524 const char* rhs_expression,
1540 const char* s2_expression,
1547 << s2_expression <<
"), actual: \""
1548 << s1 <<
"\" vs \"" << s2 <<
"\"";
1554 const char* s2_expression,
1561 <<
"Expected: (" << s1_expression <<
") != ("
1562 << s2_expression <<
") (ignoring case), actual: \""
1563 << s1 <<
"\" vs \"" << s2 <<
"\"";
1577 bool IsSubstringPred(
const char* needle,
const char* haystack) {
1578 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1580 return strstr(haystack, needle) !=
nullptr;
1583 bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1584 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1586 return wcsstr(haystack, needle) !=
nullptr;
1590 template <
typename StringType>
1591 bool IsSubstringPred(
const StringType& needle,
1593 return haystack.find(needle) != StringType::npos;
1600 template <
typename StringType>
1601 AssertionResult IsSubstringImpl(
1602 bool expected_to_be_substring,
1603 const char* needle_expr,
const char* haystack_expr,
1605 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1608 const bool is_wide_string =
sizeof(needle[0]) > 1;
1609 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1611 <<
"Value of: " << needle_expr <<
"\n"
1612 <<
" Actual: " << begin_string_quote << needle <<
"\"\n"
1613 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1614 <<
"a substring of " << haystack_expr <<
"\n"
1615 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1625 const char* needle_expr,
const char* haystack_expr,
1626 const char* needle,
const char* haystack) {
1627 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1631 const char* needle_expr,
const char* haystack_expr,
1632 const wchar_t* needle,
const wchar_t* haystack) {
1633 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1637 const char* needle_expr,
const char* haystack_expr,
1638 const char* needle,
const char* haystack) {
1639 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1643 const char* needle_expr,
const char* haystack_expr,
1644 const wchar_t* needle,
const wchar_t* haystack) {
1645 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1649 const char* needle_expr,
const char* haystack_expr,
1651 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1655 const char* needle_expr,
const char* haystack_expr,
1657 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1660 #if GTEST_HAS_STD_WSTRING
1662 const char* needle_expr,
const char* haystack_expr,
1664 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1668 const char* needle_expr,
const char* haystack_expr,
1670 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1672 #endif // GTEST_HAS_STD_WSTRING
1676 #if GTEST_OS_WINDOWS
1681 AssertionResult HRESULTFailureHelper(
const char* expr,
1682 const char* expected,
1684 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
1687 const char error_text[] =
"";
1694 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1695 FORMAT_MESSAGE_IGNORE_INSERTS;
1696 const DWORD kBufSize = 4096;
1698 char error_text[kBufSize] = {
'\0' };
1699 DWORD message_length = ::FormatMessageA(kFlags,
1707 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1709 error_text[message_length - 1] =
'\0';
1712 # endif // GTEST_OS_WINDOWS_MOBILE
1716 <<
"Expected: " << expr <<
" " << expected <<
".\n"
1717 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1722 AssertionResult IsHRESULTSuccess(
const char* expr,
long hr) {
1723 if (SUCCEEDED(hr)) {
1726 return HRESULTFailureHelper(expr,
"succeeds", hr);
1729 AssertionResult IsHRESULTFailure(
const char* expr,
long hr) {
1733 return HRESULTFailureHelper(expr,
"fails", hr);
1736 #endif // GTEST_OS_WINDOWS
1766 const UInt32 low_bits = *bits & ((
static_cast<UInt32>(1) <<
n) - 1);
1785 str[0] =
static_cast<char>(code_point);
1789 str[0] =
static_cast<char>(0xC0 | code_point);
1794 str[0] =
static_cast<char>(0xE0 | code_point);
1800 str[0] =
static_cast<char>(0xF0 | code_point);
1813 return sizeof(wchar_t) == 2 &&
1814 (
first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
1821 return (
sizeof(
wchar_t) == 2) ?
1842 if (num_chars == -1)
1843 num_chars =
static_cast<int>(wcslen(
str));
1845 ::std::stringstream
stream;
1846 for (
int i = 0;
i < num_chars; ++
i) {
1847 UInt32 unicode_code_point;
1849 if (
str[
i] == L
'\0') {
1856 unicode_code_point =
static_cast<UInt32>(
str[
i]);
1867 if (wide_c_str ==
nullptr)
return "(null)";
1879 if (lhs ==
nullptr)
return rhs ==
nullptr;
1881 if (rhs ==
nullptr)
return false;
1883 return wcscmp(lhs, rhs) == 0;
1888 const char* rhs_expression,
1890 const wchar_t* rhs) {
1904 const char* s2_expression,
1906 const wchar_t* s2) {
1912 << s2_expression <<
"), actual: "
1924 if (lhs ==
nullptr)
return rhs ==
nullptr;
1925 if (rhs ==
nullptr)
return false;
1942 const wchar_t* rhs) {
1943 if (lhs ==
nullptr)
return rhs ==
nullptr;
1945 if (rhs ==
nullptr)
return false;
1947 #if GTEST_OS_WINDOWS
1948 return _wcsicmp(lhs, rhs) == 0;
1949 #elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
1950 return wcscasecmp(lhs, rhs) == 0;
1956 left = towlower(*lhs++);
1957 right = towlower(*rhs++);
1959 return left == right;
1960 #endif // OS selector
1967 const size_t str_len =
str.length();
1968 const size_t suffix_len = suffix.length();
1969 return (str_len >= suffix_len) &&
1976 std::stringstream ss;
1977 ss << std::setfill(
'0') << std::setw(2) <<
value;
1983 std::stringstream ss;
1984 ss << std::hex << std::uppercase <<
value;
1990 std::stringstream ss;
1991 ss << std::setfill(
'0') << std::setw(2) << std::hex << std::uppercase
1992 <<
static_cast<unsigned int>(
value);
2000 const char*
const start =
str.c_str();
2021 if (user_msg_string.empty()) {
2025 return gtest_msg +
"\n" + user_msg_string;
2034 : death_test_count_(0),
2079 const std::vector<TestProperty>::iterator property_with_matching_key =
2081 internal::TestPropertyKeyIs(test_property.
key()));
2086 property_with_matching_key->SetValue(test_property.
value());
2115 "classname",
"name",
"status",
"time",
2116 "type_param",
"value_param",
"file",
"line"};
2118 template <
int kSize>
2120 return std::vector<std::string>(
array,
array + kSize);
2125 if (xml_element ==
"testsuites") {
2127 }
else if (xml_element ==
"testsuite") {
2129 }
else if (xml_element ==
"testcase") {
2132 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2135 return std::vector<std::string>();
2140 for (
size_t i = 0;
i <
words.size(); ++
i) {
2141 if (
i > 0 &&
words.size() > 2) {
2144 if (
i ==
words.size() - 1) {
2145 word_list <<
"and ";
2147 word_list <<
"'" <<
words[
i] <<
"'";
2157 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
2183 return result.skipped();
2202 return result.fatally_failed();
2212 return result.nonfatally_failed();
2266 value_message <<
value;
2292 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
2298 const char*
const first_test_name = first_test_info->
name();
2301 const TestInfo*
const this_test_info = impl->current_test_info();
2303 const char*
const this_test_name = this_test_info->
name();
2305 if (this_fixture_id != first_fixture_id) {
2311 if (first_is_TEST || this_is_TEST) {
2318 const char*
const TEST_name =
2319 first_is_TEST ? first_test_name : this_test_name;
2320 const char*
const TEST_F_name =
2321 first_is_TEST ? this_test_name : first_test_name;
2324 <<
"All tests in the same test suite must use the same test fixture\n"
2325 <<
"class, so mixing TEST_F and TEST in the same test suite is\n"
2328 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n"
2329 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n"
2330 <<
"want to change the TEST to TEST_F or move it to another test\n"
2336 <<
"All tests in the same test suite must use the same test fixture\n"
2337 <<
"class. However, in test suite "
2339 <<
"you defined test " << first_test_name <<
" and test "
2340 << this_test_name <<
"\n"
2341 <<
"using two different test fixture classes. This can happen if\n"
2342 <<
"the two classes are from different namespaces or translation\n"
2343 <<
"units and have the same name. You should probably rename one\n"
2344 <<
"of the classes to put the tests into different test suites.";
2358 static std::string* FormatSehExceptionMessage(DWORD exception_code,
2361 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2362 exception_code << std::setbase(10) <<
" thrown in " <<
location <<
".";
2367 #endif // GTEST_HAS_SEH
2371 #if GTEST_HAS_EXCEPTIONS
2380 message <<
"Unknown C++ exception";
2388 const TestPartResult& test_part_result);
2390 GoogleTestFailureException::GoogleTestFailureException(
2391 const TestPartResult& failure)
2394 #endif // GTEST_HAS_EXCEPTIONS
2404 template <
class T,
typename Result>
2409 return (object->*
method)();
2410 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2411 GetExceptionCode())) {
2415 std::string* exception_message = FormatSehExceptionMessage(
2418 *exception_message);
2419 delete exception_message;
2420 return static_cast<Result
>(0);
2424 return (object->*
method)();
2425 #endif // GTEST_HAS_SEH
2431 template <
class T,
typename Result>
2457 if (internal::GetUnitTestImpl()->catch_exceptions()) {
2458 #if GTEST_HAS_EXCEPTIONS
2461 }
catch (
const AssertionException&) {
2463 }
catch (
const internal::GoogleTestFailureException&) {
2468 }
catch (
const std::exception& e) {
2470 TestPartResult::kFatalFailure,
2471 FormatCxxExceptionMessage(e.what(),
location));
2474 TestPartResult::kFatalFailure,
2475 FormatCxxExceptionMessage(
nullptr,
location));
2477 return static_cast<Result
>(0);
2480 #endif // GTEST_HAS_EXCEPTIONS
2482 return (object->*
method)();
2490 if (!HasSameFixtureClass())
return;
2492 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
2493 impl->os_stack_trace_getter()->UponLeavingGTest();
2497 if (!HasFatalFailure() && !IsSkipped()) {
2498 impl->os_stack_trace_getter()->UponLeavingGTest();
2500 this, &Test::TestBody,
"the test body");
2506 impl->os_stack_trace_getter()->UponLeavingGTest();
2508 this, &Test::TearDown,
"TearDown()");
2512 bool Test::HasFatalFailure() {
2513 return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();
2517 bool Test::HasNonfatalFailure() {
2518 return internal::GetUnitTestImpl()->current_test_result()->
2519 HasNonfatalFailure();
2523 bool Test::IsSkipped() {
2524 return internal::GetUnitTestImpl()->current_test_result()->Skipped();
2532 const std::string& a_name,
const char* a_type_param,
2533 const char* a_value_param,
2537 : test_suite_name_(a_test_suite_name),
2539 type_param_(a_type_param ? new
std::
string(a_type_param) : nullptr),
2540 value_param_(a_value_param ? new
std::
string(a_value_param) : nullptr),
2541 location_(a_code_location),
2542 fixture_class_id_(fixture_class_id),
2544 is_disabled_(
false),
2545 matches_filter_(
false),
2573 const char* test_suite_name,
const char*
name,
const char* type_param,
2578 new TestInfo(test_suite_name,
name, type_param, value_param,
2579 code_location, fixture_class_id, factory);
2580 GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);
2588 <<
"Attempted redefinition of test suite " << test_suite_name <<
".\n"
2589 <<
"All tests in the same test suite must use the same test fixture\n"
2590 <<
"class. However, in test suite " << test_suite_name <<
", you tried\n"
2591 <<
"to define a test using a fixture class different from the one\n"
2592 <<
"used earlier. This can happen if the two fixture classes are\n"
2593 <<
"from different namespaces and have the same name. You should\n"
2594 <<
"probably rename one of the classes to put the tests into different\n"
2599 <<
" " <<
errors.GetString();
2618 explicit TestNameIs(
const char*
name)
2622 bool operator()(
const TestInfo * test_info)
const {
2623 return test_info && test_info->name() ==
name_;
2637 void UnitTestImpl::RegisterParameterizedTests() {
2638 if (!parameterized_tests_registered_) {
2639 parameterized_test_registry_.RegisterTests();
2640 parameterized_tests_registered_ =
true;
2653 impl->set_current_test_info(
this);
2662 impl->os_stack_trace_getter()->UponLeavingGTest();
2667 "the test fixture's constructor");
2679 impl->os_stack_trace_getter()->UponLeavingGTest();
2690 impl->set_current_test_info(
nullptr);
2748 type_param_(a_type_param ? new
std::
string(a_type_param) : nullptr),
2749 set_up_tc_(set_up_tc),
2750 tear_down_tc_(tear_down_tc),
2786 impl->set_current_test_suite(
this);
2793 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
2795 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
2797 impl->os_stack_trace_getter()->UponLeavingGTest();
2807 impl->os_stack_trace_getter()->UponLeavingGTest();
2814 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
2816 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
2818 impl->set_current_test_suite(
nullptr);
2845 const char * singular_form,
2846 const char * plural_form) {
2848 (
count == 1 ? singular_form : plural_form);
2867 case TestPartResult::kSkip:
2869 case TestPartResult::kSuccess:
2872 case TestPartResult::kNonFatalFailure:
2873 case TestPartResult::kFatalFailure:
2880 return "Unknown result type";
2888 const TestPartResult& test_part_result) {
2891 test_part_result.line_number())
2893 << test_part_result.message()).GetString();
2900 printf(
"%s\n", result.c_str());
2906 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2910 ::OutputDebugStringA(result.c_str());
2911 ::OutputDebugStringA(
"\n");
2916 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
2917 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
2924 case COLOR_YELLOW:
return FOREGROUND_RED | FOREGROUND_GREEN;
2929 static int GetBitOffset(WORD color_mask) {
2930 if (color_mask == 0)
return 0;
2933 while ((color_mask & 1) == 0) {
2942 static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
2943 BACKGROUND_RED | BACKGROUND_INTENSITY;
2944 static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
2945 FOREGROUND_RED | FOREGROUND_INTENSITY;
2946 const WORD existing_bg = old_color_attrs & background_mask;
2949 GetColorAttribute(
color) | existing_bg | FOREGROUND_INTENSITY;
2950 static const int bg_bitOffset = GetBitOffset(background_mask);
2951 static const int fg_bitOffset = GetBitOffset(foreground_mask);
2953 if (((new_color & background_mask) >> bg_bitOffset) ==
2954 ((new_color & foreground_mask) >> fg_bitOffset)) {
2955 new_color ^= FOREGROUND_INTENSITY;
2974 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2981 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
2984 return stdout_is_tty;
2988 const bool term_supports_color =
3000 return stdout_is_tty && term_supports_color;
3001 #endif // GTEST_OS_WINDOWS
3021 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \
3022 GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
3025 static const bool in_color_mode =
3028 #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS
3036 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
3037 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
3038 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
3041 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
3042 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
3043 const WORD old_color_attrs = buffer_info.wAttributes;
3044 const WORD new_color = GetNewColor(
color, old_color_attrs);
3050 SetConsoleTextAttribute(stdout_handle, new_color);
3056 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
3061 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
3071 const char*
const type_param = test_info.
type_param();
3072 const char*
const value_param = test_info.
value_param();
3074 if (type_param !=
nullptr || value_param !=
nullptr) {
3076 if (type_param !=
nullptr) {
3078 if (value_param !=
nullptr) printf(
" and ");
3080 if (value_param !=
nullptr) {
3118 const UnitTest& unit_test,
int iteration) {
3120 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
3134 "Note: This is test shard %d of %s.\n",
3135 static_cast<int>(shard_index) + 1,
3141 "Note: Randomizing tests' orders with a seed of %d .\n",
3146 printf(
"Running %s from %s.\n",
3155 printf(
"Global test environment set-up.\n");
3163 printf(
"%s from %s", counts.c_str(),
test_suite.name());
3181 const TestPartResult& result) {
3182 switch (result.type()) {
3185 case TestPartResult::kSkip:
3186 case TestPartResult::kSuccess:
3223 printf(
"%s from %s (%s ms total)\n\n", counts.c_str(),
test_suite.name(),
3231 printf(
"Global test environment tear-down\n");
3238 if (failed_test_count == 0) {
3247 for (
int j = 0; j <
test_suite.total_test_count(); ++j) {
3263 if (skipped_test_count == 0) {
3272 for (
int j = 0; j <
test_suite.total_test_count(); ++j) {
3287 printf(
"%s from %s ran.",
3291 printf(
" (%s ms total)",
3299 if (skipped_test_count > 0) {
3301 printf(
"%s, listed below:\n",
FormatTestCount(skipped_test_count).c_str());
3306 if (!unit_test.
Passed()) {
3309 printf(
"%s, listed below:\n",
FormatTestCount(failed_test_count).c_str());
3311 printf(
"\n%2d FAILED %s\n", num_failures,
3312 num_failures == 1 ?
"TEST" :
"TESTS");
3316 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3317 if (!num_failures) {
3321 " YOU HAVE %d DISABLED %s\n\n",
3323 num_disabled == 1 ?
"TEST" :
"TESTS");
3351 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
3353 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
3359 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
3361 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
3379 ForEach(
listeners_, Delete<TestEventListener>);
3399 #define GTEST_REPEATER_METHOD_(Name, Type) \
3400 void TestEventRepeater::Name(const Type& parameter) { \
3401 if (forwarding_enabled_) { \
3402 for (size_t i = 0; i < listeners_.size(); i++) { \
3403 listeners_[i]->Name(parameter); \
3409 #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
3410 void TestEventRepeater::Name(const Type& parameter) { \
3411 if (forwarding_enabled_) { \
3412 for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \
3413 listeners_[i]->Name(parameter); \
3421 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3423 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3432 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3434 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3438 #undef GTEST_REPEATER_METHOD_
3439 #undef GTEST_REVERSE_REPEATER_METHOD_
3445 listeners_[
i]->OnTestIterationStart(unit_test, iteration);
3453 for (
int i =
static_cast<int>(
listeners_.size()) - 1;
i >= 0;
i--) {
3454 listeners_[
i]->OnTestIterationEnd(unit_test, iteration);
3471 const std::vector<TestSuite*>& test_suites);
3477 return c == 0x9 || c == 0xA || c == 0xD;
3516 const char* test_suite_name,
3546 : output_file_(output_file) {
3556 std::stringstream
stream;
3563 const std::vector<TestSuite*>& test_suites) {
3565 std::stringstream
stream;
3585 for (
size_t i = 0;
i <
str.size(); ++
i) {
3621 return m.GetString();
3631 for (std::string::const_iterator
it =
str.begin();
it !=
str.end(); ++
it)
3657 ::std::stringstream ss;
3658 ss << (static_cast<double>(ms) * 1e-3);
3663 #if defined(_MSC_VER)
3664 return localtime_s(out, &seconds) == 0;
3665 #elif defined(__MINGW32__) || defined(__MINGW64__)
3668 struct tm* tm_ptr = localtime(&seconds);
3669 if (tm_ptr ==
nullptr)
return false;
3680 struct tm time_struct;
3695 const char* segment =
data;
3698 const char*
const next_segment = strstr(segment,
"]]>");
3699 if (next_segment !=
nullptr) {
3701 segment,
static_cast<std::streamsize
>(next_segment - segment));
3702 *
stream <<
"]]>]]><![CDATA[";
3703 segment = next_segment + strlen(
"]]>");
3717 const std::vector<std::string>& allowed_names =
3720 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
3721 allowed_names.end())
3730 const char* test_suite_name,
3759 stream, kTestsuite,
"status",
3768 if (part.failed()) {
3769 if (++failures == 1) {
3774 part.line_number());
3776 *
stream <<
" <failure message=\""
3781 *
stream <<
"</failure>\n";
3788 if (failures == 0) {
3792 *
stream <<
" </testcase>\n";
3800 *
stream <<
" <" << kTestsuite;
3808 stream, kTestsuite,
"disabled",
3820 *
stream <<
" </" << kTestsuite <<
">\n";
3828 *
stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3829 *
stream <<
"<" << kTestsuites;
3836 stream, kTestsuites,
"disabled",
3840 stream, kTestsuites,
"timestamp",
3858 *
stream <<
"</" << kTestsuites <<
">\n";
3862 std::ostream*
stream,
const std::vector<TestSuite*>& test_suites) {
3865 *
stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3866 *
stream <<
"<" << kTestsuites;
3868 int total_tests = 0;
3870 total_tests +=
test_suite->total_test_count();
3880 *
stream <<
"</" << kTestsuites <<
">\n";
3890 attributes <<
" " <<
property.key() <<
"="
3905 *
stream <<
"<" << kProperties <<
">\n";
3908 *
stream <<
"<" << kProperty;
3913 *
stream <<
"</" << kProperties <<
">\n";
3927 const std::vector<TestSuite*>& test_suites);
3950 const char* test_suite_name,
3974 : output_file_(output_file) {
3983 std::stringstream
stream;
3993 for (
size_t i = 0;
i <
str.size(); ++
i) {
4026 return m.GetString();
4034 ::std::stringstream ss;
4035 ss << (static_cast<double>(ms) * 1e-3) <<
"s";
4042 struct tm time_struct;
4065 const std::vector<std::string>& allowed_names =
4068 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
4069 allowed_names.end())
4085 const std::vector<std::string>& allowed_names =
4088 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
4089 allowed_names.end())
4100 const char* test_suite_name,
4125 stream, kTestsuite,
"status",
4137 if (part.failed()) {
4139 if (++failures == 1) {
4140 *
stream << kIndent <<
"\"" <<
"failures" <<
"\": [\n";
4144 part.line_number());
4146 *
stream << kIndent <<
" {\n"
4147 << kIndent <<
" \"failure\": \"" <<
message <<
"\",\n"
4148 << kIndent <<
" \"type\": \"\"\n"
4154 *
stream <<
"\n" << kIndent <<
"]";
4172 test_suite.reportable_disabled_test_count(), kIndent);
4181 *
stream << kIndent <<
"\"" << kTestsuite <<
"\": [\n";
4194 *
stream <<
"\n" << kIndent <<
"]\n" <<
Indent(4) <<
"}";
4226 *
stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4240 *
stream <<
"\n" << kIndent <<
"]\n" <<
"}\n";
4244 std::ostream*
stream,
const std::vector<TestSuite*>& test_suites) {
4248 int total_tests = 0;
4250 total_tests +=
test_suite->total_test_count();
4255 *
stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4257 for (
size_t i = 0;
i < test_suites.size(); ++
i) {
4275 attributes <<
",\n" <<
indent <<
"\"" <<
property.key() <<
"\": "
4276 <<
"\"" <<
EscapeJson(property.value()) <<
"\"";
4283 #if GTEST_CAN_STREAM_RESULTS_
4292 result.reserve(strlen(
str) + 1);
4302 result.push_back(
ch);
4309 void StreamingListener::SocketWriter::MakeConnection() {
4311 <<
"MakeConnection() can't be called when there is already a connection.";
4314 memset(&hints, 0,
sizeof(hints));
4315 hints.ai_family = AF_UNSPEC;
4316 hints.ai_socktype = SOCK_STREAM;
4317 addrinfo* servinfo =
nullptr;
4321 const int error_num = getaddrinfo(
4322 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
4323 if (error_num != 0) {
4325 << gai_strerror(error_num);
4329 for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr !=
nullptr;
4330 cur_addr = cur_addr->ai_next) {
4332 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
4333 if (sockfd_ != -1) {
4335 if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
4342 freeaddrinfo(servinfo);
4344 if (sockfd_ == -1) {
4346 << host_name_ <<
":" << port_num_;
4351 #endif // GTEST_CAN_STREAM_RESULTS__
4355 const char*
const OsStackTraceGetterInterface::kElidedFramesMarker =
4358 std::string OsStackTraceGetter::CurrentStackTrace(
int max_depth,
int skip_count)
4363 if (max_depth <= 0) {
4367 max_depth = std::min(max_depth, kMaxStackTraceDepth);
4369 std::vector<void*> raw_stack(max_depth);
4371 const int raw_stack_size =
4374 void* caller_frame =
nullptr;
4377 caller_frame = caller_frame_;
4380 for (
int i = 0;
i < raw_stack_size; ++
i) {
4381 if (raw_stack[
i] == caller_frame &&
4389 const char* symbol =
"(unknown)";
4395 snprintf(line,
sizeof(line),
" %p: %s\n", raw_stack[
i], symbol);
4401 #else // !GTEST_HAS_ABSL
4402 static_cast<void>(max_depth);
4403 static_cast<void>(skip_count);
4405 #endif // GTEST_HAS_ABSL
4410 void* caller_frame =
nullptr;
4412 caller_frame =
nullptr;
4416 caller_frame_ = caller_frame;
4417 #endif // GTEST_HAS_ABSL
4426 premature_exit_filepath :
"") {
4432 FILE* pfile =
posix::FOpen(premature_exit_filepath,
"w");
4433 fwrite(
"0", 1, 1, pfile);
4460 : repeater_(new
internal::TestEventRepeater()),
4461 default_result_printer_(nullptr),
4462 default_xml_generator_(nullptr) {}
4500 if (listener !=
nullptr)
Append(listener);
4515 if (listener !=
nullptr)
Append(listener);
4543 #if defined(__BORLANDC__)
4549 #endif // defined(__BORLANDC__)
4554 return impl()->successful_test_suite_count();
4559 return impl()->failed_test_suite_count();
4564 return impl()->total_test_suite_count();
4570 return impl()->test_suite_to_run_count();
4574 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4576 return impl()->successful_test_suite_count();
4579 return impl()->failed_test_suite_count();
4582 return impl()->total_test_suite_count();
4585 return impl()->test_suite_to_run_count();
4587 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4591 return impl()->successful_test_count();
4596 return impl()->skipped_test_count();
4604 return impl()->reportable_disabled_test_count();
4609 return impl()->disabled_test_count();
4614 return impl()->reportable_test_count();
4626 return impl()->start_timestamp();
4631 return impl()->elapsed_time();
4644 return impl()->GetTestSuite(
i);
4648 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4650 return impl()->GetTestCase(
i);
4652 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4657 return *
impl()->ad_hoc_test_result();
4663 return impl()->GetMutableSuiteCase(
i);
4669 return *
impl()->listeners();
4683 if (env ==
nullptr) {
4687 impl_->environments().push_back(env);
4697 const char* file_name,
4705 if (impl_->gtest_trace_stack().size() > 0) {
4708 for (
int i =
static_cast<int>(impl_->gtest_trace_stack().size());
4710 const internal::TraceInfo& trace = impl_->gtest_trace_stack()[
i - 1];
4712 <<
" " << trace.message;
4716 if (os_stack_trace.c_str() !=
nullptr && !os_stack_trace.empty()) {
4720 const TestPartResult result = TestPartResult(
4722 impl_->GetTestPartResultReporterForCurrentThread()->
4723 ReportTestPartResult(result);
4733 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
4738 #elif (!defined(__native_client__)) && \
4739 ((defined(__clang__) || defined(__GNUC__)) && \
4740 (defined(__x86_64__) || defined(__i386__)))
4747 *
static_cast<volatile int*
>(
nullptr) = 1;
4748 #endif // GTEST_OS_WINDOWS
4750 #if GTEST_HAS_EXCEPTIONS
4751 throw internal::GoogleTestFailureException(result);
4777 const bool in_death_test_child_process =
4802 in_death_test_child_process
4810 #if GTEST_OS_WINDOWS
4815 if (
impl()->catch_exceptions() || in_death_test_child_process) {
4816 # if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
4818 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
4819 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
4820 # endif // !GTEST_OS_WINDOWS_MOBILE
4822 # if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
4826 _set_error_mode(_OUT_TO_STDERR);
4829 # if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
4836 _set_abort_behavior(
4838 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
4841 #endif // GTEST_OS_WINDOWS
4846 "auxiliary test code (environments or event listeners)") ? 0 : 1;
4852 return impl_->original_working_dir_.c_str();
4860 return impl_->current_test_suite();
4864 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4868 return impl_->current_test_suite();
4877 return impl_->current_test_info();
4887 return impl_->parameterized_test_registry();
4892 impl_ =
new internal::UnitTestImpl(
this);
4905 impl_->gtest_trace_stack().push_back(trace);
4912 impl_->gtest_trace_stack().pop_back();
4917 UnitTestImpl::UnitTestImpl(
UnitTest* parent)
4920 default_global_test_part_result_reporter_(this),
4921 default_per_thread_test_part_result_reporter_(this),
4923 &default_global_test_part_result_reporter_),
4924 per_thread_test_part_result_reporter_(
4925 &default_per_thread_test_part_result_reporter_),
4926 parameterized_test_registry_(),
4927 parameterized_tests_registered_(
false),
4928 last_death_test_suite_(-1),
4929 current_test_suite_(nullptr),
4930 current_test_info_(nullptr),
4931 ad_hoc_test_result_(),
4932 os_stack_trace_getter_(nullptr),
4933 post_flag_parse_init_performed_(
false),
4936 start_timestamp_(0),
4938 #
if GTEST_HAS_DEATH_TEST
4939 death_test_factory_(new DefaultDeathTestFactory),
4942 catch_exceptions_(
false) {
4946 UnitTestImpl::~UnitTestImpl() {
4948 ForEach(test_suites_, internal::Delete<TestSuite>);
4951 ForEach(environments_, internal::Delete<Environment>);
4953 delete os_stack_trace_getter_;
4961 void UnitTestImpl::RecordProperty(
const TestProperty& test_property) {
4963 TestResult* test_result;
4965 if (current_test_info_ !=
nullptr) {
4966 xml_element =
"testcase";
4967 test_result = &(current_test_info_->result_);
4968 }
else if (current_test_suite_ !=
nullptr) {
4969 xml_element =
"testsuite";
4970 test_result = &(current_test_suite_->ad_hoc_test_result_);
4972 xml_element =
"testsuites";
4973 test_result = &ad_hoc_test_result_;
4975 test_result->RecordProperty(xml_element, test_property);
4978 #if GTEST_HAS_DEATH_TEST
4981 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
4982 if (internal_run_death_test_flag_.get() !=
nullptr)
4983 listeners()->SuppressEventForwarding();
4985 #endif // GTEST_HAS_DEATH_TEST
4989 void UnitTestImpl::ConfigureXmlOutput() {
4990 const std::string& output_format = UnitTestOptions::GetOutputFormat();
4991 if (output_format ==
"xml") {
4992 listeners()->SetDefaultXmlGenerator(
new XmlUnitTestResultPrinter(
4993 UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
4994 }
else if (output_format ==
"json") {
4995 listeners()->SetDefaultXmlGenerator(
new JsonUnitTestResultPrinter(
4996 UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
4997 }
else if (output_format !=
"") {
4999 << output_format <<
"\" ignored.";
5003 #if GTEST_CAN_STREAM_RESULTS_
5006 void UnitTestImpl::ConfigureStreamingOutput() {
5009 const size_t pos =
target.find(
':');
5010 if (pos != std::string::npos) {
5011 listeners()->Append(
new StreamingListener(
target.substr(0, pos),
5019 #endif // GTEST_CAN_STREAM_RESULTS_
5026 void UnitTestImpl::PostFlagParsingInit() {
5028 if (!post_flag_parse_init_performed_) {
5029 post_flag_parse_init_performed_ =
true;
5031 #if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
5033 listeners()->Append(
new GTEST_CUSTOM_TEST_EVENT_LISTENER_());
5034 #endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
5036 #if GTEST_HAS_DEATH_TEST
5037 InitDeathTestSubprocessControlInfo();
5038 SuppressTestEventsIfInSubprocess();
5039 #endif // GTEST_HAS_DEATH_TEST
5044 RegisterParameterizedTests();
5048 ConfigureXmlOutput();
5050 #if GTEST_CAN_STREAM_RESULTS_
5052 ConfigureStreamingOutput();
5053 #endif // GTEST_CAN_STREAM_RESULTS_
5056 if (
GTEST_FLAG(install_failure_signal_handler)) {
5057 absl::FailureSignalHandlerOptions
options;
5060 #endif // GTEST_HAS_ABSL
5100 const char* test_suite_name,
const char* type_param,
5105 std::find_if(test_suites_.rbegin(), test_suites_.rend(),
5111 auto*
const new_test_suite =
5112 new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
5115 if (internal::UnitTestOptions::MatchesFilter(test_suite_name,
5121 ++last_death_test_suite_;
5122 test_suites_.insert(test_suites_.begin() + last_death_test_suite_,
5126 test_suites_.push_back(new_test_suite);
5129 test_suite_indices_.push_back(
static_cast<int>(test_suite_indices_.size()));
5130 return new_test_suite;
5157 PostFlagParsingInit();
5166 bool in_subprocess_for_death_test =
false;
5168 #if GTEST_HAS_DEATH_TEST
5169 in_subprocess_for_death_test =
5170 (internal_run_death_test_flag_.get() !=
nullptr);
5171 # if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
5172 if (in_subprocess_for_death_test) {
5173 GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
5175 # endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
5176 #endif // GTEST_HAS_DEATH_TEST
5179 in_subprocess_for_death_test);
5183 const bool has_tests_to_run = FilterTests(should_shard
5184 ? HONOR_SHARDING_PROTOCOL
5185 : IGNORE_SHARDING_PROTOCOL) > 0;
5190 ListTestsMatchingFilter();
5195 GetRandomSeedFromFlag(
GTEST_FLAG(random_seed)) : 0;
5198 bool failed =
false;
5200 TestEventListener* repeater = listeners()->repeater();
5203 repeater->OnTestProgramStart(*parent_);
5207 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG(repeat);
5209 const bool forever = repeat < 0;
5210 for (
int i = 0; forever ||
i != repeat;
i++) {
5213 ClearNonAdHocTestResult();
5218 if (has_tests_to_run &&
GTEST_FLAG(shuffle)) {
5219 random()->Reseed(random_seed_);
5227 repeater->OnTestIterationStart(*parent_,
i);
5230 if (has_tests_to_run) {
5232 repeater->OnEnvironmentsSetUpStart(*parent_);
5234 repeater->OnEnvironmentsSetUpEnd(*parent_);
5239 for (
int test_index = 0; test_index < total_test_suite_count();
5241 GetMutableSuiteCase(test_index)->Run();
5246 repeater->OnEnvironmentsTearDownStart(*parent_);
5247 std::for_each(environments_.rbegin(), environments_.rend(),
5249 repeater->OnEnvironmentsTearDownEnd(*parent_);
5255 repeater->OnTestIterationEnd(*parent_,
i);
5272 random_seed_ = GetNextRandomSeed(random_seed_);
5276 repeater->OnTestProgramEnd(*parent_);
5278 if (!gtest_is_initialized_before_run_all_tests) {
5281 "\nIMPORTANT NOTICE - DO NOT IGNORE:\n"
5283 "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_
5284 " will start to enforce the valid usage. "
5285 "Please fix it ASAP, or IT WILL START TO FAIL.\n");
5286 #if GTEST_FOR_GOOGLE_
5288 "For more details, see http://wiki/Main/ValidGUnitMain.\n");
5289 #endif // GTEST_FOR_GOOGLE_
5301 if (test_shard_file !=
nullptr) {
5303 if (file ==
nullptr) {
5305 "Could not write to the test shard status file \"%s\" "
5306 "specified by the %s environment variable.\n",
5322 const char* shard_index_env,
5323 bool in_subprocess_for_death_test) {
5324 if (in_subprocess_for_death_test) {
5331 if (total_shards == -1 && shard_index == -1) {
5333 }
else if (total_shards == -1 && shard_index != -1) {
5335 <<
"Invalid environment variables: you have "
5341 }
else if (total_shards != -1 && shard_index == -1) {
5343 <<
"Invalid environment variables: you have "
5349 }
else if (shard_index < 0 || shard_index >= total_shards) {
5351 <<
"Invalid environment variables: we require 0 <= "
5360 return total_shards > 1;
5368 if (str_val ==
nullptr) {
5374 str_val, &result)) {
5385 return (test_id % total_shards) == shard_index;
5395 int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
5396 const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
5398 const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
5405 int num_runnable_tests = 0;
5406 int num_selected_tests = 0;
5411 for (
size_t j = 0; j <
test_suite->test_info_list().
size(); j++) {
5416 const bool is_disabled = internal::UnitTestOptions::MatchesFilter(
5418 internal::UnitTestOptions::MatchesFilter(
5422 const bool matches_filter = internal::UnitTestOptions::FilterMatchesTest(
5423 test_suite_name, test_name);
5426 const bool is_runnable =
5427 (
GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
5430 const bool is_in_another_shard =
5431 shard_tests != IGNORE_SHARDING_PROTOCOL &&
5434 const bool is_selected = is_runnable && !is_in_another_shard;
5436 num_runnable_tests += is_runnable;
5437 num_selected_tests += is_selected;
5443 return num_selected_tests;
5451 if (
str !=
nullptr) {
5452 for (
int i = 0; *
str !=
'\0'; ++
str) {
5453 if (
i >= max_length) {
5469 void UnitTestImpl::ListTestsMatchingFilter() {
5471 const int kMaxParamLength = 250;
5474 bool printed_test_suite_name =
false;
5476 for (
size_t j = 0; j <
test_suite->test_info_list().
size(); j++) {
5479 if (!printed_test_suite_name) {
5480 printed_test_suite_name =
true;
5490 printf(
" %s", test_info->
name());
5502 const std::string& output_format = UnitTestOptions::GetOutputFormat();
5503 if (output_format ==
"xml" || output_format ==
"json") {
5505 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
5506 std::stringstream
stream;
5507 if (output_format ==
"xml") {
5508 XmlUnitTestResultPrinter(
5509 UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
5510 .PrintXmlTestsList(&
stream, test_suites_);
5511 }
else if (output_format ==
"json") {
5512 JsonUnitTestResultPrinter(
5513 UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
5514 .PrintJsonTestList(&
stream, test_suites_);
5526 void UnitTestImpl::set_os_stack_trace_getter(
5527 OsStackTraceGetterInterface* getter) {
5528 if (os_stack_trace_getter_ != getter) {
5529 delete os_stack_trace_getter_;
5530 os_stack_trace_getter_ = getter;
5537 OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
5538 if (os_stack_trace_getter_ ==
nullptr) {
5539 #ifdef GTEST_OS_STACK_TRACE_GETTER_
5540 os_stack_trace_getter_ =
new GTEST_OS_STACK_TRACE_GETTER_;
5542 os_stack_trace_getter_ =
new OsStackTraceGetter;
5543 #endif // GTEST_OS_STACK_TRACE_GETTER_
5546 return os_stack_trace_getter_;
5550 TestResult* UnitTestImpl::current_test_result() {
5551 if (current_test_info_ !=
nullptr) {
5552 return ¤t_test_info_->result_;
5554 if (current_test_suite_ !=
nullptr) {
5555 return ¤t_test_suite_->ad_hoc_test_result_;
5557 return &ad_hoc_test_result_;
5562 void UnitTestImpl::ShuffleTests() {
5564 ShuffleRange(random(), 0, last_death_test_suite_ + 1, &test_suite_indices_);
5567 ShuffleRange(random(), last_death_test_suite_ + 1,
5568 static_cast<int>(test_suites_.size()), &test_suite_indices_);
5577 void UnitTestImpl::UnshuffleTests() {
5578 for (
size_t i = 0;
i < test_suites_.size();
i++) {
5580 test_suites_[
i]->UnshuffleTests();
5582 test_suite_indices_[
i] =
static_cast<int>(
i);
5600 return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
5606 class ClassUniqueToAlwaysTrue {};
5609 bool IsTrue(
bool condition) {
return condition; }
5612 #if GTEST_HAS_EXCEPTIONS
5616 throw ClassUniqueToAlwaysTrue();
5617 #endif // GTEST_HAS_EXCEPTIONS
5625 const size_t prefix_len = strlen(
prefix);
5626 if (strncmp(*pstr,
prefix, prefix_len) == 0) {
5627 *pstr += prefix_len;
5639 bool def_optional) {
5641 if (
str ==
nullptr || flag ==
nullptr)
return nullptr;
5645 const size_t flag_len = flag_str.length();
5646 if (strncmp(
str, flag_str.c_str(), flag_len) != 0)
return nullptr;
5649 const char* flag_end =
str + flag_len;
5652 if (def_optional && (flag_end[0] ==
'\0')) {
5659 if (flag_end[0] !=
'=')
return nullptr;
5662 return flag_end + 1;
5680 if (value_str ==
nullptr)
return false;
5683 *
value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
5697 if (value_str ==
nullptr)
return false;
5709 template <
typename String>
5715 if (value_str ==
nullptr)
return false;
5754 const char*
p = strchr(
str,
'@');
5762 const char ch =
p[1];
5766 }
else if (
ch ==
'D') {
5768 }
else if (
ch ==
'R') {
5770 }
else if (
ch ==
'G') {
5772 }
else if (
ch ==
'Y') {
5781 "This program contains tests written using " GTEST_NAME_ ". You can use the\n"
5782 "following command line flags to control its behavior:\n"
5786 " List the names of all tests instead of running them. The name of\n"
5787 " TEST(Foo, Bar) is \"Foo.Bar\".\n"
5789 "[@G-@YNEGATIVE_PATTERNS]@D\n"
5790 " Run only the tests whose name matches one of the positive patterns but\n"
5791 " none of the negative patterns. '?' matches any single character; '*'\n"
5792 " matches any substring; ':' separates two patterns.\n"
5794 " Run all disabled tests too.\n"
5798 " Run the tests repeatedly; use a negative count to repeat forever.\n"
5800 " Randomize tests' orders on every iteration.\n"
5802 " Random number seed to use for shuffling test orders (between 1 and\n"
5803 " 99999, or 0 to use a seed based on the current time).\n"
5807 " Enable/disable colored output. The default is @Gauto@D.\n"
5809 " Don't print the elapsed time of each test.\n"
5812 " Generate a JSON or XML report in the given directory or with the given\n"
5813 " file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n"
5814 # if GTEST_CAN_STREAM_RESULTS_
5816 " Stream test results to the given server.\n"
5817 # endif // GTEST_CAN_STREAM_RESULTS_
5819 "Assertion Behavior:\n"
5820 # if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
5822 " Set the default death test style.\n"
5823 # endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
5825 " Turn assertion failures into debugger break-points.\n"
5827 " Turn assertion failures into C++ exceptions for use by an external\n"
5828 " test framework.\n"
5830 " Do not report exceptions as test failures. Instead, allow them\n"
5831 " to crash the program or throw a pop-up (on Windows).\n"
5834 "the corresponding\n"
5835 "environment variable of a flag (all letters in upper-case). For example, to\n"
5837 "color=no@D or set\n"
5840 "For more information, please read the " GTEST_NAME_ " documentation at\n"
5842 "(not one in your own code or tests), please report it to\n"
5875 #if GTEST_USE_OWN_FLAGFILE_FLAG_
5884 std::vector<std::string> lines;
5886 for (
size_t i = 0;
i < lines.size(); ++
i) {
5887 if (lines[
i].empty())
5893 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
5898 template <
typename CharType>
5900 for (
int i = 1;
i < *argc;
i++) {
5902 const char*
const arg = arg_string.c_str();
5908 bool remove_flag =
false;
5911 #if GTEST_USE_OWN_FLAGFILE_FLAG_
5915 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
5916 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
5917 arg_string ==
"-?" || arg_string ==
"/?" ||
5929 for (
int j =
i; j != *argc; j++) {
5930 argv[j] = argv[j + 1];
5959 #ifndef GTEST_OS_IOS
5960 if (*_NSGetArgv() == argv) {
5961 *_NSGetArgc() = *argc;
5974 template <
typename CharType>
5979 if (*argc <= 0)
return;
5982 for (
int i = 0;
i != *argc;
i++) {
5987 absl::InitializeSymbolizer(
g_argvs[0].c_str());
5988 #endif // GTEST_HAS_ABSL
5991 GetUnitTestImpl()->PostFlagParsingInit();
6006 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6007 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6008 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6010 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6016 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6017 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6018 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6020 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6028 const auto arg0 =
"dummy";
6029 char* argv0 =
const_cast<char*
>(arg0);
6030 char** argv = &argv0;
6032 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6033 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(&argc, argv);
6034 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6036 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6040 #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
6041 return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
6044 #if GTEST_OS_WINDOWS_MOBILE
6046 #elif GTEST_OS_WINDOWS
6048 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0')
6050 else if (temp_dir[strlen(temp_dir) - 1] ==
'\\')
6054 #elif GTEST_OS_LINUX_ANDROID
6058 #endif // GTEST_OS_WINDOWS_MOBILE
6066 internal::TraceInfo trace;
6071 UnitTest::GetInstance()->PushGTestTrace(trace);
6075 ScopedTrace::~ScopedTrace()
6077 UnitTest::GetInstance()->PopGTestTrace();