Reads and returns a 32-bit integer stored in the environment variable corresponding to the given flag; if it isn't set or doesn't represent a valid 32-bit integer, returns default_value.
| 11050 | // variable corresponding to the given flag; if it isn't set or |
| 11051 | // doesn't represent a valid 32-bit integer, returns default_value. |
| 11052 | Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { |
| 11053 | #if defined(GTEST_GET_INT32_FROM_ENV_) |
| 11054 | return GTEST_GET_INT32_FROM_ENV_(flag, default_value); |
| 11055 | #else |
| 11056 | const std::string env_var = FlagToEnvVar(flag); |
| 11057 | const char* const string_value = posix::GetEnv(env_var.c_str()); |
| 11058 | if (string_value == nullptr) { |
| 11059 | // The environment variable is not set. |
| 11060 | return default_value; |
| 11061 | } |
| 11062 | |
| 11063 | Int32 result = default_value; |
| 11064 | if (!ParseInt32(Message() << "Environment variable " << env_var, |
| 11065 | string_value, &result)) { |
| 11066 | printf("The default value %s is used.\n", |
| 11067 | (Message() << default_value).GetString().c_str()); |
| 11068 | fflush(stdout); |
| 11069 | return default_value; |
| 11070 | } |
| 11071 | |
| 11072 | return result; |
| 11073 | #endif // defined(GTEST_GET_INT32_FROM_ENV_) |
| 11074 | } |
| 11075 | |
| 11076 | // As a special case for the 'output' flag, if GTEST_OUTPUT is not |
| 11077 | // set, we look for XML_OUTPUT_FILE, which is set by the Bazel build |
no test coverage detected