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.
| 8516 | // variable corresponding to the given flag; if it isn't set or |
| 8517 | // doesn't represent a valid 32-bit integer, returns default_value. |
| 8518 | Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { |
| 8519 | const String env_var = FlagToEnvVar(flag); |
| 8520 | const char* const string_value = posix::GetEnv(env_var.c_str()); |
| 8521 | if (string_value == NULL) { |
| 8522 | // The environment variable is not set. |
| 8523 | return default_value; |
| 8524 | } |
| 8525 | |
| 8526 | Int32 result = default_value; |
| 8527 | if (!ParseInt32(Message() << "Environment variable " << env_var, |
| 8528 | string_value, &result)) { |
| 8529 | printf("The default value %s is used.\n", |
| 8530 | (Message() << default_value).GetString().c_str()); |
| 8531 | fflush(stdout); |
| 8532 | return default_value; |
| 8533 | } |
| 8534 | |
| 8535 | return result; |
| 8536 | } |
| 8537 | |
| 8538 | // Reads and returns the string environment variable corresponding to |
| 8539 | // the given flag; if it's not set, returns default_value. |
no test coverage detected