Commit 977cffc4 by Abseil Team Committed by Derek Mauro

Googletest export

Introduce GTEST_FLAG_GET and GTEST_FLAG_SET macros. PiperOrigin-RevId: 382808313
parent 4cfd1498
......@@ -440,7 +440,8 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
const std::string log = GetCapturedStdout();
std::string expected_trace =
(testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString();
(testing::Message() << GTEST_FLAG_GET(stack_trace_depth) << "::")
.GetString();
std::string expected_message =
"\nGMOCK WARNING:\n"
"Test log.\n"
......
......@@ -6328,7 +6328,7 @@ TEST_P(BipartiteRandomTest, LargerNets) {
int iters = GetParam().second;
MatchMatrix graph(static_cast<size_t>(nodes), static_cast<size_t>(nodes));
auto seed = static_cast<uint32_t>(GTEST_FLAG(random_seed));
auto seed = static_cast<uint32_t>(GTEST_FLAG_GET(random_seed));
if (seed == 0) {
seed = static_cast<uint32_t>(time(nullptr));
}
......
......@@ -40,8 +40,6 @@
#include "gtest/internal/gtest-death-test-internal.h"
namespace testing {
// This flag controls the style of death tests. Valid values are "threadsafe",
// meaning that the death test child process will re-execute the test binary
// from the start, running only a single death test, or "fast",
......@@ -49,6 +47,8 @@ namespace testing {
// after forking.
GTEST_DECLARE_string_(death_test_style);
namespace testing {
#if GTEST_HAS_DEATH_TEST
namespace internal {
......
......@@ -73,17 +73,6 @@
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)
namespace testing {
// Silence C4100 (unreferenced formal parameter) and 4805
// unsafe mix of type 'const int' and type 'const bool'
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4805)
# pragma warning(disable:4100)
#endif
// Declares the flags.
// This flag temporary enables the disabled tests.
......@@ -169,6 +158,16 @@ GTEST_DECLARE_string_(stream_result_to);
GTEST_DECLARE_string_(flagfile);
#endif // GTEST_USE_OWN_FLAGFILE_FLAG_
namespace testing {
// Silence C4100 (unreferenced formal parameter) and 4805
// unsafe mix of type 'const int' and type 'const bool'
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4805)
#pragma warning(disable : 4100)
#endif
// The upper limit for valid stack trace depths.
const int kMaxStackTraceDepth = 100;
......
......@@ -26,6 +26,8 @@ The following macros can be defined:
* `GTEST_DEFINE_bool_(name, default_val, doc)`
* `GTEST_DEFINE_int32_(name, default_val, doc)`
* `GTEST_DEFINE_string_(name, default_val, doc)`
* `GTEST_FLAG_GET(flag_name)`
* `GTEST_FLAG_SET(flag_name, value)`
### Logging:
......
......@@ -42,11 +42,11 @@
#include <stdio.h>
#include <memory>
GTEST_DECLARE_string_(internal_run_death_test);
namespace testing {
namespace internal {
GTEST_DECLARE_string_(internal_run_death_test);
// Names of the flags (needed for parsing Google Test flags).
const char kDeathTestStyleFlag[] = "death_test_style";
const char kDeathTestUseFork[] = "death_test_use_fork";
......
......@@ -2216,22 +2216,40 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver
// Macros for declaring flags.
# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
# define GTEST_DECLARE_int32_(name) \
GTEST_API_ extern std::int32_t GTEST_FLAG(name)
# define GTEST_DECLARE_string_(name) \
GTEST_API_ extern ::std::string GTEST_FLAG(name)
#define GTEST_DECLARE_bool_(name) \
namespace testing { \
GTEST_API_ extern bool GTEST_FLAG(name); \
}
#define GTEST_DECLARE_int32_(name) \
namespace testing { \
GTEST_API_ extern std::int32_t GTEST_FLAG(name); \
}
#define GTEST_DECLARE_string_(name) \
namespace testing { \
GTEST_API_ extern ::std::string GTEST_FLAG(name); \
}
// Macros for defining flags.
# define GTEST_DEFINE_bool_(name, default_val, doc) \
GTEST_API_ bool GTEST_FLAG(name) = (default_val)
# define GTEST_DEFINE_int32_(name, default_val, doc) \
GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val)
# define GTEST_DEFINE_string_(name, default_val, doc) \
GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
#define GTEST_DEFINE_bool_(name, default_val, doc) \
namespace testing { \
GTEST_API_ bool GTEST_FLAG(name) = (default_val); \
}
#define GTEST_DEFINE_int32_(name, default_val, doc) \
namespace testing { \
GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \
}
#define GTEST_DEFINE_string_(name, default_val, doc) \
namespace testing { \
GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \
}
#endif // !defined(GTEST_DECLARE_bool_)
#if !defined(GTEST_FLAG_GET)
#define GTEST_FLAG_GET(name) ::testing::GTEST_FLAG(name)
#define GTEST_FLAG_SET(name, value) (void)(::testing::GTEST_FLAG(name) = value)
#endif // !defined(GTEST_FLAG_GET)
// Thread annotations
#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
......
......@@ -96,9 +96,12 @@ namespace testing {
// used internally at Google, is "threadsafe".
static const char kDefaultDeathTestStyle[] = GTEST_DEFAULT_DEATH_TEST_STYLE;
} // namespace testing
GTEST_DEFINE_string_(
death_test_style,
internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle),
testing::internal::StringFromGTestEnv("death_test_style",
testing::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 "
......@@ -107,7 +110,7 @@ GTEST_DEFINE_string_(
GTEST_DEFINE_bool_(
death_test_use_fork,
internal::BoolFromGTestEnv("death_test_use_fork", false),
testing::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 "
......@@ -117,7 +120,6 @@ GTEST_DEFINE_bool_(
"work in 99% of the cases. Once valgrind is fixed, this flag will "
"most likely be removed.");
namespace internal {
GTEST_DEFINE_string_(
internal_run_death_test, "",
"Indicates the file, line number, temporal index of "
......@@ -126,7 +128,8 @@ GTEST_DEFINE_string_(
"the '|' characters. This flag is specified if and only if the "
"current process is a sub-process launched for running a thread-safe "
"death test. FOR INTERNAL USE ONLY.");
} // namespace internal
namespace testing {
#if GTEST_HAS_DEATH_TEST
......@@ -148,12 +151,12 @@ bool InDeathTestChild() {
// On Windows and Fuchsia, death tests are thread-safe regardless of the value
// of the death_test_style flag.
return !GTEST_FLAG(internal_run_death_test).empty();
return !GTEST_FLAG_GET(internal_run_death_test).empty();
# else
if (GTEST_FLAG(death_test_style) == "threadsafe")
return !GTEST_FLAG(internal_run_death_test).empty();
if (GTEST_FLAG_GET(death_test_style) == "threadsafe")
return !GTEST_FLAG_GET(internal_run_death_test).empty();
else
return g_in_fast_death_test_child;
#endif
......@@ -756,18 +759,18 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
nullptr)); // The even is unnamed.
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
kFilterFlag + "=" + info->test_suite_name() +
"." + info->name();
"filter=" + info->test_suite_name() + "." +
info->name();
const std::string internal_flag =
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
"=" + file_ + "|" + StreamableToString(line_) + "|" +
StreamableToString(death_test_index) + "|" +
std::string("--") + GTEST_FLAG_PREFIX_ +
"internal_run_death_test=" + file_ + "|" + StreamableToString(line_) +
"|" + StreamableToString(death_test_index) + "|" +
StreamableToString(static_cast<unsigned int>(::GetCurrentProcessId())) +
// size_t has the same width as pointers on both 32-bit and 64-bit
// Windows platforms.
// See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
"|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) +
"|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
"|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) + "|" +
StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
char executable_path[_MAX_PATH + 1]; // NOLINT
GTEST_DEATH_TEST_CHECK_(_MAX_PATH + 1 != ::GetModuleFileNameA(nullptr,
......@@ -987,8 +990,8 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
// Build the child process command line.
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
kFilterFlag + "=" + info->test_suite_name() +
"." + info->name();
"filter=" + info->test_suite_name() + "." +
info->name();
const std::string internal_flag =
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
+ file_ + "|"
......@@ -1351,7 +1354,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
# endif // GTEST_OS_LINUX
# if GTEST_HAS_CLONE
const bool use_fork = GTEST_FLAG(death_test_use_fork);
const bool use_fork = GTEST_FLAG_GET(death_test_use_fork);
if (!use_fork) {
static const bool stack_grows_down = StackGrowsDown();
......@@ -1420,13 +1423,13 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
kFilterFlag + "=" + info->test_suite_name() +
"." + info->name();
const std::string internal_flag =
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
+ file_ + "|" + StreamableToString(line_) + "|"
+ StreamableToString(death_test_index) + "|"
+ StreamableToString(pipe_fd[1]);
"filter=" + info->test_suite_name() + "." +
info->name();
const std::string internal_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
"internal_run_death_test=" + file_ + "|" +
StreamableToString(line_) + "|" +
StreamableToString(death_test_index) + "|" +
StreamableToString(pipe_fd[1]);
Arguments args;
args.AddArguments(GetArgvsForDeathTestChildProcess());
args.AddArgument(filter_flag.c_str());
......@@ -1482,32 +1485,32 @@ bool DefaultDeathTestFactory::Create(const char* statement,
# if GTEST_OS_WINDOWS
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
GTEST_FLAG(death_test_style) == "fast") {
if (GTEST_FLAG_GET(death_test_style) == "threadsafe" ||
GTEST_FLAG_GET(death_test_style) == "fast") {
*test = new WindowsDeathTest(statement, std::move(matcher), file, line);
}
# elif GTEST_OS_FUCHSIA
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
GTEST_FLAG(death_test_style) == "fast") {
if (GTEST_FLAG_GET(death_test_style) == "threadsafe" ||
GTEST_FLAG_GET(death_test_style) == "fast") {
*test = new FuchsiaDeathTest(statement, std::move(matcher), file, line);
}
# else
if (GTEST_FLAG(death_test_style) == "threadsafe") {
if (GTEST_FLAG_GET(death_test_style) == "threadsafe") {
*test = new ExecDeathTest(statement, std::move(matcher), file, line);
} else if (GTEST_FLAG(death_test_style) == "fast") {
} else if (GTEST_FLAG_GET(death_test_style) == "fast") {
*test = new NoExecDeathTest(statement, std::move(matcher));
}
# endif // GTEST_OS_WINDOWS
else { // NOLINT - this is more readable than unbalanced brackets inside #if.
DeathTest::set_last_death_test_message(
"Unknown death test style \"" + GTEST_FLAG(death_test_style)
+ "\" encountered");
DeathTest::set_last_death_test_message("Unknown death test style \"" +
GTEST_FLAG_GET(death_test_style) +
"\" encountered");
return false;
}
......@@ -1584,14 +1587,14 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
// initialized from the GTEST_FLAG(internal_run_death_test) flag if
// the flag is specified; otherwise returns NULL.
InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
if (GTEST_FLAG(internal_run_death_test) == "") return nullptr;
if (GTEST_FLAG_GET(internal_run_death_test) == "") return nullptr;
// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we
// can use it here.
int line = -1;
int index = -1;
::std::vector< ::std::string> fields;
SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields);
SplitString(GTEST_FLAG_GET(internal_run_death_test), '|', &fields);
int write_fd = -1;
# if GTEST_OS_WINDOWS
......@@ -1607,7 +1610,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|| !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
|| !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
DeathTestAbort("Bad --gtest_internal_run_death_test flag: " +
GTEST_FLAG(internal_run_death_test));
GTEST_FLAG_GET(internal_run_death_test));
}
write_fd = GetStatusFileDescriptor(parent_process_id,
write_handle_as_size_t,
......@@ -1618,8 +1621,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
if (fields.size() != 3
|| !ParseNaturalNumber(fields[1], &line)
|| !ParseNaturalNumber(fields[2], &index)) {
DeathTestAbort("Bad --gtest_internal_run_death_test flag: "
+ GTEST_FLAG(internal_run_death_test));
DeathTestAbort("Bad --gtest_internal_run_death_test flag: " +
GTEST_FLAG_GET(internal_run_death_test));
}
# else
......@@ -1628,8 +1631,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|| !ParseNaturalNumber(fields[1], &line)
|| !ParseNaturalNumber(fields[2], &index)
|| !ParseNaturalNumber(fields[3], &write_fd)) {
DeathTestAbort("Bad --gtest_internal_run_death_test flag: "
+ GTEST_FLAG(internal_run_death_test));
DeathTestAbort("Bad --gtest_internal_run_death_test flag: " +
GTEST_FLAG_GET(internal_run_death_test));
}
# endif // GTEST_OS_WINDOWS
......
......@@ -64,8 +64,6 @@
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)
namespace testing {
// Declares the flags.
//
// We don't want the users to modify this flag in the code, but want
......@@ -73,34 +71,13 @@ namespace testing {
// declare it here as opposed to in gtest.h.
GTEST_DECLARE_bool_(death_test_use_fork);
namespace testing {
namespace internal {
// The value of GetTestTypeId() as seen from within the Google Test
// library. This is solely for testing GetTestTypeId().
GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
// Names of the flags (needed for parsing Google Test flags).
const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
const char kBreakOnFailureFlag[] = "break_on_failure";
const char kCatchExceptionsFlag[] = "catch_exceptions";
const char kColorFlag[] = "color";
const char kFailFast[] = "fail_fast";
const char kFilterFlag[] = "filter";
const char kListTestsFlag[] = "list_tests";
const char kOutputFlag[] = "output";
const char kBriefFlag[] = "brief";
const char kPrintTimeFlag[] = "print_time";
const char kPrintUTF8Flag[] = "print_utf8";
const char kRandomSeedFlag[] = "random_seed";
const char kRepeatFlag[] = "repeat";
const char kRecreateEnvironmentsWhenRepeatingFlag[] =
"recreate_environments_when_repeating";
const char kShuffleFlag[] = "shuffle";
const char kStackTraceDepthFlag[] = "stack_trace_depth";
const char kStreamResultToFlag[] = "stream_result_to";
const char kThrowOnFailureFlag[] = "throw_on_failure";
const char kFlagfileFlag[] = "flagfile";
// A valid random seed must be in [1, kMaxRandomSeed].
const int kMaxRandomSeed = 99999;
......@@ -127,8 +104,7 @@ GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
GTEST_API_ bool ParseInt32Flag(
const char* str, const char* flag, int32_t* value);
GTEST_API_ bool ParseFlag(const char* str, const char* flag, int32_t* value);
// Returns a random seed in range [1, kMaxRandomSeed] based on the
// given --gtest_random_seed flag value.
......@@ -162,54 +138,54 @@ class GTestFlagSaver {
public:
// The c'tor.
GTestFlagSaver() {
also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
break_on_failure_ = GTEST_FLAG(break_on_failure);
catch_exceptions_ = GTEST_FLAG(catch_exceptions);
color_ = GTEST_FLAG(color);
death_test_style_ = GTEST_FLAG(death_test_style);
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
fail_fast_ = GTEST_FLAG(fail_fast);
filter_ = GTEST_FLAG(filter);
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
list_tests_ = GTEST_FLAG(list_tests);
output_ = GTEST_FLAG(output);
brief_ = GTEST_FLAG(brief);
print_time_ = GTEST_FLAG(print_time);
print_utf8_ = GTEST_FLAG(print_utf8);
random_seed_ = GTEST_FLAG(random_seed);
repeat_ = GTEST_FLAG(repeat);
also_run_disabled_tests_ = GTEST_FLAG_GET(also_run_disabled_tests);
break_on_failure_ = GTEST_FLAG_GET(break_on_failure);
catch_exceptions_ = GTEST_FLAG_GET(catch_exceptions);
color_ = GTEST_FLAG_GET(color);
death_test_style_ = GTEST_FLAG_GET(death_test_style);
death_test_use_fork_ = GTEST_FLAG_GET(death_test_use_fork);
fail_fast_ = GTEST_FLAG_GET(fail_fast);
filter_ = GTEST_FLAG_GET(filter);
internal_run_death_test_ = GTEST_FLAG_GET(internal_run_death_test);
list_tests_ = GTEST_FLAG_GET(list_tests);
output_ = GTEST_FLAG_GET(output);
brief_ = GTEST_FLAG_GET(brief);
print_time_ = GTEST_FLAG_GET(print_time);
print_utf8_ = GTEST_FLAG_GET(print_utf8);
random_seed_ = GTEST_FLAG_GET(random_seed);
repeat_ = GTEST_FLAG_GET(repeat);
recreate_environments_when_repeating_ =
GTEST_FLAG(recreate_environments_when_repeating);
shuffle_ = GTEST_FLAG(shuffle);
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
stream_result_to_ = GTEST_FLAG(stream_result_to);
throw_on_failure_ = GTEST_FLAG(throw_on_failure);
GTEST_FLAG_GET(recreate_environments_when_repeating);
shuffle_ = GTEST_FLAG_GET(shuffle);
stack_trace_depth_ = GTEST_FLAG_GET(stack_trace_depth);
stream_result_to_ = GTEST_FLAG_GET(stream_result_to);
throw_on_failure_ = GTEST_FLAG_GET(throw_on_failure);
}
// The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
~GTestFlagSaver() {
GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
GTEST_FLAG(break_on_failure) = break_on_failure_;
GTEST_FLAG(catch_exceptions) = catch_exceptions_;
GTEST_FLAG(color) = color_;
GTEST_FLAG(death_test_style) = death_test_style_;
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
GTEST_FLAG(filter) = filter_;
GTEST_FLAG(fail_fast) = fail_fast_;
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
GTEST_FLAG(list_tests) = list_tests_;
GTEST_FLAG(output) = output_;
GTEST_FLAG(brief) = brief_;
GTEST_FLAG(print_time) = print_time_;
GTEST_FLAG(print_utf8) = print_utf8_;
GTEST_FLAG(random_seed) = random_seed_;
GTEST_FLAG(repeat) = repeat_;
GTEST_FLAG(recreate_environments_when_repeating) =
recreate_environments_when_repeating_;
GTEST_FLAG(shuffle) = shuffle_;
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
GTEST_FLAG(stream_result_to) = stream_result_to_;
GTEST_FLAG(throw_on_failure) = throw_on_failure_;
GTEST_FLAG_SET(also_run_disabled_tests, also_run_disabled_tests_);
GTEST_FLAG_SET(break_on_failure, break_on_failure_);
GTEST_FLAG_SET(catch_exceptions, catch_exceptions_);
GTEST_FLAG_SET(color, color_);
GTEST_FLAG_SET(death_test_style, death_test_style_);
GTEST_FLAG_SET(death_test_use_fork, death_test_use_fork_);
GTEST_FLAG_SET(filter, filter_);
GTEST_FLAG_SET(fail_fast, fail_fast_);
GTEST_FLAG_SET(internal_run_death_test, internal_run_death_test_);
GTEST_FLAG_SET(list_tests, list_tests_);
GTEST_FLAG_SET(output, output_);
GTEST_FLAG_SET(brief, brief_);
GTEST_FLAG_SET(print_time, print_time_);
GTEST_FLAG_SET(print_utf8, print_utf8_);
GTEST_FLAG_SET(random_seed, random_seed_);
GTEST_FLAG_SET(repeat, repeat_);
GTEST_FLAG_SET(recreate_environments_when_repeating,
recreate_environments_when_repeating_);
GTEST_FLAG_SET(shuffle, shuffle_);
GTEST_FLAG_SET(stack_trace_depth, stack_trace_depth_);
GTEST_FLAG_SET(stream_result_to, stream_result_to_);
GTEST_FLAG_SET(throw_on_failure, throw_on_failure_);
}
private:
......
......@@ -502,7 +502,7 @@ void ConditionalPrintAsText(const char* str, size_t length, ostream* os) {
void PrintStringTo(const ::std::string& s, ostream* os) {
if (PrintCharsAsStringTo(s.data(), s.size(), os) == kHexEscape) {
if (GTEST_FLAG(print_utf8)) {
if (GTEST_FLAG_GET(print_utf8)) {
ConditionalPrintAsText(s.data(), s.size(), os);
}
}
......
......@@ -370,14 +370,14 @@ TEST_F(TestForDeathTest, SwitchStatement) {
// Tests that a static member function can be used in a "fast" style
// death test.
TEST_F(TestForDeathTest, StaticMemberFunctionFastStyle) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
ASSERT_DEATH(StaticMemberFunction(), "death.*StaticMember");
}
// Tests that a method of the test fixture can be used in a "fast"
// style death test.
TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
should_die_ = true;
EXPECT_DEATH(MemberFunction(), "inside.*MemberFunction");
}
......@@ -387,7 +387,7 @@ void ChangeToRootDir() { posix::ChDir(GTEST_PATH_SEP_); }
// Tests that death tests work even if the current directory has been
// changed.
TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
ChangeToRootDir();
EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), "");
......@@ -432,7 +432,7 @@ void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) {
// Tests that death tests work when SIGPROF handler and timer are set.
TEST_F(TestForDeathTest, FastSigprofActionSet) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
SetSigprofActionAndTimer();
EXPECT_DEATH(_exit(1), "");
struct sigaction old_signal_action;
......@@ -441,7 +441,7 @@ TEST_F(TestForDeathTest, FastSigprofActionSet) {
}
TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
SetSigprofActionAndTimer();
EXPECT_DEATH(_exit(1), "");
struct sigaction old_signal_action;
......@@ -453,25 +453,25 @@ TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) {
// Repeats a representative sample of death tests in the "threadsafe" style:
TEST_F(TestForDeathTest, StaticMemberFunctionThreadsafeStyle) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
ASSERT_DEATH(StaticMemberFunction(), "death.*StaticMember");
}
TEST_F(TestForDeathTest, MemberFunctionThreadsafeStyle) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
should_die_ = true;
EXPECT_DEATH(MemberFunction(), "inside.*MemberFunction");
}
TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
for (int i = 0; i < 3; ++i)
EXPECT_EXIT(_exit(i), testing::ExitedWithCode(i), "") << ": i = " << i;
}
TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
ChangeToRootDir();
EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), "");
......@@ -481,9 +481,9 @@ TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) {
}
TEST_F(TestForDeathTest, MixedStyles) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_DEATH(_exit(1), "");
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_DEATH(_exit(1), "");
}
......@@ -496,8 +496,8 @@ void SetPthreadFlag() {
}
TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
if (!testing::GTEST_FLAG(death_test_use_fork)) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
if (!GTEST_FLAG_GET(death_test_use_fork)) {
GTEST_FLAG_SET(death_test_style, "threadsafe");
pthread_flag = false;
ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, nullptr, nullptr));
ASSERT_DEATH(_exit(1), "");
......@@ -740,10 +740,12 @@ TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
"any pop-up dialogs.\n");
fflush(stdout);
EXPECT_DEATH({
testing::GTEST_FLAG(catch_exceptions) = false;
abort();
}, "");
EXPECT_DEATH(
{
GTEST_FLAG_SET(catch_exceptions, false);
abort();
},
"");
}
# endif // GTEST_OS_WINDOWS
......@@ -874,19 +876,19 @@ TEST_F(TestForDeathTest, ExitMacros) {
}
TEST_F(TestForDeathTest, ExitMacrosUsingFork) {
testing::GTEST_FLAG(death_test_use_fork) = true;
GTEST_FLAG_SET(death_test_use_fork, true);
TestExitMacros();
}
TEST_F(TestForDeathTest, InvalidStyle) {
testing::GTEST_FLAG(death_test_style) = "rococo";
GTEST_FLAG_SET(death_test_style, "rococo");
EXPECT_NONFATAL_FAILURE({ // NOLINT
EXPECT_DEATH(_exit(0), "") << "This failure is expected.";
}, "This failure is expected.");
}
TEST_F(TestForDeathTest, DeathTestFailedOutput) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_NONFATAL_FAILURE(
EXPECT_DEATH(DieWithMessage("death\n"),
"expected message"),
......@@ -895,7 +897,7 @@ TEST_F(TestForDeathTest, DeathTestFailedOutput) {
}
TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_NONFATAL_FAILURE(
EXPECT_DEATH({
fprintf(stderr, "returning\n");
......@@ -908,7 +910,7 @@ TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
}
TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_NONFATAL_FAILURE(
EXPECT_EXIT(DieWithMessage("exiting with rc 1\n"),
testing::ExitedWithCode(3),
......@@ -920,7 +922,7 @@ TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
}
TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_NONFATAL_FAILURE(
EXPECT_DEATH(DieWithMessage("line 1\nline 2\nline 3\n"),
"line 1\nxyz\nline 3\n"),
......@@ -931,7 +933,7 @@ TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
}
TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_DEATH(DieWithMessage("line 1\nline 2\nline 3\n"),
"line 1\nline 2\nline 3\n");
}
......@@ -1358,7 +1360,7 @@ TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
}
TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
testing::GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_FALSE(InDeathTestChild());
EXPECT_DEATH({
fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
......@@ -1368,7 +1370,7 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
}
TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_FALSE(InDeathTestChild());
EXPECT_DEATH({
fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
......
......@@ -53,7 +53,7 @@ TEST(CxxExceptionDeathTest, ExceptionIsFailure) {
} catch (...) { // NOLINT
FAIL() << "An exception escaped a death test macro invocation "
<< "with catch_exceptions "
<< (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled");
<< (GTEST_FLAG_GET(catch_exceptions) ? "enabled" : "disabled");
}
}
......@@ -79,7 +79,7 @@ TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) {
TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) {
EXPECT_DEATH(RaiseException(42, 0x0, 0, NULL), "")
<< "with catch_exceptions "
<< (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled");
<< (GTEST_FLAG_GET(catch_exceptions) ? "enabled" : "disabled");
}
# endif
......@@ -87,6 +87,6 @@ TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) {
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
testing::GTEST_FLAG(catch_exceptions) = GTEST_ENABLE_CATCH_EXCEPTIONS_ != 0;
GTEST_FLAG_SET(catch_exceptions, GTEST_ENABLE_CATCH_EXCEPTIONS_ != 0);
return RUN_ALL_TESTS();
}
......@@ -48,67 +48,67 @@ TEST(GTestEnvVarTest, Dummy) {
void PrintFlag(const char* flag) {
if (strcmp(flag, "break_on_failure") == 0) {
cout << GTEST_FLAG(break_on_failure);
cout << GTEST_FLAG_GET(break_on_failure);
return;
}
if (strcmp(flag, "catch_exceptions") == 0) {
cout << GTEST_FLAG(catch_exceptions);
cout << GTEST_FLAG_GET(catch_exceptions);
return;
}
if (strcmp(flag, "color") == 0) {
cout << GTEST_FLAG(color);
cout << GTEST_FLAG_GET(color);
return;
}
if (strcmp(flag, "death_test_style") == 0) {
cout << GTEST_FLAG(death_test_style);
cout << GTEST_FLAG_GET(death_test_style);
return;
}
if (strcmp(flag, "death_test_use_fork") == 0) {
cout << GTEST_FLAG(death_test_use_fork);
cout << GTEST_FLAG_GET(death_test_use_fork);
return;
}
if (strcmp(flag, "fail_fast") == 0) {
cout << GTEST_FLAG(fail_fast);
cout << GTEST_FLAG_GET(fail_fast);
return;
}
if (strcmp(flag, "filter") == 0) {
cout << GTEST_FLAG(filter);
cout << GTEST_FLAG_GET(filter);
return;
}
if (strcmp(flag, "output") == 0) {
cout << GTEST_FLAG(output);
cout << GTEST_FLAG_GET(output);
return;
}
if (strcmp(flag, "brief") == 0) {
cout << GTEST_FLAG(brief);
cout << GTEST_FLAG_GET(brief);
return;
}
if (strcmp(flag, "print_time") == 0) {
cout << GTEST_FLAG(print_time);
cout << GTEST_FLAG_GET(print_time);
return;
}
if (strcmp(flag, "repeat") == 0) {
cout << GTEST_FLAG(repeat);
cout << GTEST_FLAG_GET(repeat);
return;
}
if (strcmp(flag, "stack_trace_depth") == 0) {
cout << GTEST_FLAG(stack_trace_depth);
cout << GTEST_FLAG_GET(stack_trace_depth);
return;
}
if (strcmp(flag, "throw_on_failure") == 0) {
cout << GTEST_FLAG(throw_on_failure);
cout << GTEST_FLAG_GET(throw_on_failure);
return;
}
......
......@@ -284,7 +284,7 @@ int main(int argc, char **argv) {
GTEST_CHECK_(events.size() == 0)
<< "AddGlobalTestEnvironment should not generate any events itself.";
::testing::GTEST_FLAG(repeat) = 2;
GTEST_FLAG_SET(repeat, 2);
int ret_val = RUN_ALL_TESTS();
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
......
......@@ -61,29 +61,29 @@ FilePath GetAbsolutePathOf(const FilePath& relative_path) {
// Testing UnitTestOptions::GetOutputFormat/GetOutputFile.
TEST(XmlOutputTest, GetOutputFormatDefault) {
GTEST_FLAG(output) = "";
GTEST_FLAG_SET(output, "");
EXPECT_STREQ("", UnitTestOptions::GetOutputFormat().c_str());
}
TEST(XmlOutputTest, GetOutputFormat) {
GTEST_FLAG(output) = "xml:filename";
GTEST_FLAG_SET(output, "xml:filename");
EXPECT_STREQ("xml", UnitTestOptions::GetOutputFormat().c_str());
}
TEST(XmlOutputTest, GetOutputFileDefault) {
GTEST_FLAG(output) = "";
GTEST_FLAG_SET(output, "");
EXPECT_EQ(GetAbsolutePathOf(FilePath("test_detail.xml")).string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
}
TEST(XmlOutputTest, GetOutputFileSingleFile) {
GTEST_FLAG(output) = "xml:filename.abc";
GTEST_FLAG_SET(output, "xml:filename.abc");
EXPECT_EQ(GetAbsolutePathOf(FilePath("filename.abc")).string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
}
TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
GTEST_FLAG_SET(output, "xml:path" GTEST_PATH_SEP_);
const std::string expected_output_file =
GetAbsolutePathOf(
FilePath(std::string("path") + GTEST_PATH_SEP_ +
......@@ -144,28 +144,28 @@ class XmlOutputChangeDirTest : public Test {
};
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) {
GTEST_FLAG(output) = "";
GTEST_FLAG_SET(output, "");
EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_,
FilePath("test_detail.xml")).string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
}
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) {
GTEST_FLAG(output) = "xml";
GTEST_FLAG_SET(output, "xml");
EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_,
FilePath("test_detail.xml")).string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
}
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
GTEST_FLAG(output) = "xml:filename.abc";
GTEST_FLAG_SET(output, "xml:filename.abc");
EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_,
FilePath("filename.abc")).string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
}
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
GTEST_FLAG_SET(output, "xml:path" GTEST_PATH_SEP_);
const std::string expected_output_file =
FilePath::ConcatPaths(
original_working_dir_,
......@@ -182,11 +182,11 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
#if GTEST_OS_WINDOWS
GTEST_FLAG(output) = "xml:c:\\tmp\\filename.abc";
GTEST_FLAG_SET(output, "xml:c:\\tmp\\filename.abc");
EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
#else
GTEST_FLAG(output) ="xml:/tmp/filename.abc";
GTEST_FLAG_SET(output, "xml:/tmp/filename.abc");
EXPECT_EQ(FilePath("/tmp/filename.abc").string(),
UnitTestOptions::GetAbsolutePathToOutputFile());
#endif
......@@ -199,7 +199,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
const std::string path = "/tmp/";
#endif
GTEST_FLAG(output) = "xml:" + path;
GTEST_FLAG_SET(output, "xml:" + path);
const std::string expected_output_file =
path + GetCurrentExecutableName().string() + ".xml";
const std::string& output_file =
......
......@@ -1066,7 +1066,7 @@ class BarEnvironment : public testing::Environment {
// of them are intended to fail), and then compare the test results
// with the "golden" file.
int main(int argc, char **argv) {
testing::GTEST_FLAG(print_time) = false;
GTEST_FLAG_SET(print_time, false);
// We just run the tests, knowing some of them are intended to fail.
// We will use a separate Python script to compare the output of
......@@ -1081,7 +1081,7 @@ int main(int argc, char **argv) {
std::string("internal_skip_environment_and_ad_hoc_tests")) > 0;
#if GTEST_HAS_DEATH_TEST
if (testing::internal::GTEST_FLAG(internal_run_death_test) != "") {
if (GTEST_FLAG_GET(internal_run_death_test) != "") {
// Skip the usual output capturing if we're running as the child
// process of an threadsafe-style death test.
# if GTEST_OS_WINDOWS
......
......@@ -35,10 +35,6 @@
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h"
namespace testing {
GTEST_DECLARE_string_(filter);
}
namespace {
enum FailureType {
......@@ -174,7 +170,7 @@ int main(int argc, char **argv) {
// Verifies that RUN_ALL_TESTS() doesn't do global set-up or
// tear-down when there is no test to run.
testing::GTEST_FLAG(filter) = "-*";
GTEST_FLAG_SET(filter, "-*");
Check(RunAllTests(env, NO_FAILURE) == 0,
"RUN_ALL_TESTS() should return zero, as there is no test to run.");
Check(!env->set_up_was_run(),
......
......@@ -35,18 +35,6 @@
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h"
namespace testing {
GTEST_DECLARE_string_(death_test_style);
GTEST_DECLARE_string_(filter);
GTEST_DECLARE_int32_(repeat);
} // namespace testing
using testing::GTEST_FLAG(death_test_style);
using testing::GTEST_FLAG(filter);
using testing::GTEST_FLAG(repeat);
namespace {
// We need this when we are testing Google Test itself and therefore
......@@ -103,10 +91,10 @@ int g_death_test_count = 0;
TEST(BarDeathTest, ThreadSafeAndFast) {
g_death_test_count++;
GTEST_FLAG(death_test_style) = "threadsafe";
GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), "");
GTEST_FLAG(death_test_style) = "fast";
GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), "");
}
......@@ -153,7 +141,7 @@ void TestRepeatUnspecified() {
// Tests the behavior of Google Test when --gtest_repeat has the given value.
void TestRepeat(int repeat) {
GTEST_FLAG(repeat) = repeat;
GTEST_FLAG_SET(repeat, repeat);
ResetCounts();
GTEST_CHECK_INT_EQ_(repeat > 0 ? 1 : 0, RUN_ALL_TESTS());
......@@ -163,8 +151,8 @@ void TestRepeat(int repeat) {
// Tests using --gtest_repeat when --gtest_filter specifies an empty
// set of tests.
void TestRepeatWithEmptyFilter(int repeat) {
GTEST_FLAG(repeat) = repeat;
GTEST_FLAG(filter) = "None";
GTEST_FLAG_SET(repeat, repeat);
GTEST_FLAG_SET(filter, "None");
ResetCounts();
GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS());
......@@ -174,8 +162,8 @@ void TestRepeatWithEmptyFilter(int repeat) {
// Tests using --gtest_repeat when --gtest_filter specifies a set of
// successful tests.
void TestRepeatWithFilterForSuccessfulTests(int repeat) {
GTEST_FLAG(repeat) = repeat;
GTEST_FLAG(filter) = "*-*ShouldFail";
GTEST_FLAG_SET(repeat, repeat);
GTEST_FLAG_SET(filter, "*-*ShouldFail");
ResetCounts();
GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS());
......@@ -190,8 +178,8 @@ void TestRepeatWithFilterForSuccessfulTests(int repeat) {
// Tests using --gtest_repeat when --gtest_filter specifies a set of
// failed tests.
void TestRepeatWithFilterForFailedTests(int repeat) {
GTEST_FLAG(repeat) = repeat;
GTEST_FLAG(filter) = "*ShouldFail";
GTEST_FLAG_SET(repeat, repeat);
GTEST_FLAG_SET(filter, "*ShouldFail");
ResetCounts();
GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS());
......
......@@ -50,7 +50,7 @@ void Fail(const char* msg) {
// Tests that an assertion failure throws a subclass of
// std::runtime_error.
void TestFailureThrowsRuntimeError() {
testing::GTEST_FLAG(throw_on_failure) = true;
GTEST_FLAG_SET(throw_on_failure, true);
// A successful assertion shouldn't throw.
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment