summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ci/linux-presubmit.sh4
-rw-r--r--docs/advanced.md2
-rw-r--r--docs/primer.md22
-rw-r--r--docs/reference/matchers.md2
-rw-r--r--googlemock/include/gmock/internal/gmock-port.h4
-rw-r--r--googlemock/src/gmock-internal-utils.cc7
-rw-r--r--googlemock/src/gmock-spec-builders.cc2
-rw-r--r--googlemock/test/gmock-matchers-comparisons_test.cc3
-rw-r--r--googlemock/test/gmock-spec-builders_test.cc15
-rw-r--r--googlemock/test/gmock_output_test_golden.txt8
-rw-r--r--googletest/include/gtest/gtest.h2
-rw-r--r--googletest/include/gtest/internal/gtest-death-test-internal.h2
-rw-r--r--googletest/include/gtest/internal/gtest-internal.h2
-rw-r--r--googletest/include/gtest/internal/gtest-port.h25
-rw-r--r--googletest/src/gtest-death-test.cc94
-rw-r--r--googletest/src/gtest-port.cc42
-rw-r--r--googletest/src/gtest.cc7
-rw-r--r--googletest/test/googletest-death-test-test.cc21
-rw-r--r--googletest/test/googletest-json-outfiles-test.py10
-rw-r--r--googletest/test/gtest_dirs_test.cc4
-rw-r--r--googletest/test/gtest_unittest.cc18
-rw-r--r--googletest/test/gtest_xml_outfile2_test_.cc4
-rwxr-xr-xgoogletest/test/gtest_xml_outfiles_test.py10
23 files changed, 121 insertions, 189 deletions
diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh
index 9e15d9a4..626989d2 100644
--- a/ci/linux-presubmit.sh
+++ b/ci/linux-presubmit.sh
@@ -31,8 +31,8 @@
set -euox pipefail
-readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20220217"
-readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20220621"
+readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20230217"
+readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20230120"
if [[ -z ${GTEST_ROOT:-} ]]; then
GTEST_ROOT="$(realpath $(dirname ${0})/..)"
diff --git a/docs/advanced.md b/docs/advanced.md
index 7d15dfdd..6b4c3f0b 100644
--- a/docs/advanced.md
+++ b/docs/advanced.md
@@ -562,7 +562,7 @@ The automated testing framework does not set the style flag. You can choose a
particular style of death tests by setting the flag programmatically:
```c++
-GTEST_FLAG_SET(death_test_style, "threadsafe")
+GTEST_FLAG_SET(death_test_style, "threadsafe");
```
You can do this in `main()` to set the style for all death tests in the binary,
diff --git a/docs/primer.md b/docs/primer.md
index 2ffbf53b..80c2d0a6 100644
--- a/docs/primer.md
+++ b/docs/primer.md
@@ -45,23 +45,23 @@ minutes to learn the basics and get started. So let's go!
## Beware of the nomenclature
{: .callout .note}
-_Note:_ There might be some confusion arising from different definitions of the
-terms _Test_, _Test Case_ and _Test Suite_, so beware of misunderstanding these.
+*Note:* There might be some confusion arising from different definitions of the
+terms *Test*, *Test Case* and *Test Suite*, so beware of misunderstanding these.
-Historically, googletest started to use the term _Test Case_ for grouping
+Historically, googletest started to use the term *Test Case* for grouping
related tests, whereas current publications, including International Software
Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) materials and
various textbooks on software quality, use the term
-_[Test Suite][istqb test suite]_ for this.
+*[Test Suite][istqb test suite]* for this.
-The related term _Test_, as it is used in googletest, corresponds to the term
-_[Test Case][istqb test case]_ of ISTQB and others.
+The related term *Test*, as it is used in googletest, corresponds to the term
+*[Test Case][istqb test case]* of ISTQB and others.
-The term _Test_ is commonly of broad enough sense, including ISTQB's definition
-of _Test Case_, so it's not much of a problem here. But the term _Test Case_ as
+The term *Test* is commonly of broad enough sense, including ISTQB's definition
+of *Test Case*, so it's not much of a problem here. But the term *Test Case* as
was used in Google Test is of contradictory sense and thus confusing.
-googletest recently started replacing the term _Test Case_ with _Test Suite_.
+googletest recently started replacing the term *Test Case* with *Test Suite*.
The preferred API is *TestSuite*. The older TestCase API is being slowly
deprecated and refactored away.
@@ -381,7 +381,7 @@ If a fatal failure happens the subsequent steps will be skipped.
## Writing the main() Function
-Most users should _not_ need to write their own `main` function and instead link
+Most users should *not* need to write their own `main` function and instead link
with `gtest_main` (as opposed to with `gtest`), which defines a suitable entry
point. See the end of this section for details. The remainder of this section
should only apply when you need to do something custom before the tests run that
@@ -476,7 +476,7 @@ NOTE: `ParseGUnitFlags()` is deprecated in favor of `InitGoogleTest()`.
* Google Test is designed to be thread-safe. The implementation is thread-safe
on systems where the `pthreads` library is available. It is currently
- _unsafe_ to use Google Test assertions from two threads concurrently on
+ *unsafe* to use Google Test assertions from two threads concurrently on
other systems (e.g. Windows). In most tests this is not an issue as usually
the assertions are done in the main thread. If you want to help, you can
volunteer to implement the necessary synchronization primitives in
diff --git a/docs/reference/matchers.md b/docs/reference/matchers.md
index be962819..243e3f95 100644
--- a/docs/reference/matchers.md
+++ b/docs/reference/matchers.md
@@ -102,7 +102,7 @@ The `argument` can be either a C string or a C++ string object:
| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. |
| `StrEq(string)` | `argument` is equal to `string`. |
| `StrNe(string)` | `argument` is not equal to `string`. |
-| `WhenBase64Unescaped(m)` | `argument` is a base-64 escaped string whose unescaped string matches `m`. |
+| `WhenBase64Unescaped(m)` | `argument` is a base-64 escaped string whose unescaped string matches `m`. The web-safe format from [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648#section-5) is supported. |
`ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They
use the regular expression syntax defined
diff --git a/googlemock/include/gmock/internal/gmock-port.h b/googlemock/include/gmock/internal/gmock-port.h
index bc18a25f..55ddfb6c 100644
--- a/googlemock/include/gmock/internal/gmock-port.h
+++ b/googlemock/include/gmock/internal/gmock-port.h
@@ -56,7 +56,7 @@
#include "gmock/internal/custom/gmock-port.h"
#include "gtest/internal/gtest-port.h"
-#if GTEST_HAS_ABSL
+#ifdef GTEST_HAS_ABSL
#include "absl/flags/declare.h"
#include "absl/flags/flag.h"
#endif
@@ -73,7 +73,7 @@
#define GMOCK_FLAG(name) FLAGS_gmock_##name
// Pick a command line flags implementation.
-#if GTEST_HAS_ABSL
+#ifdef GTEST_HAS_ABSL
// Macros for defining flags.
#define GMOCK_DEFINE_bool_(name, default_val, doc) \
diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc
index 7bfff02a..31d55650 100644
--- a/googlemock/src/gmock-internal-utils.cc
+++ b/googlemock/src/gmock-internal-utils.cc
@@ -198,6 +198,10 @@ GTEST_API_ void IllegalDoDefault(const char* file, int line) {
"the variable in various places.");
}
+constexpr char UndoWebSafeEncoding(char c) {
+ return c == '-' ? '+' : c == '_' ? '/' : c;
+}
+
constexpr char UnBase64Impl(char c, const char* const base64, char carry) {
return *base64 == 0 ? static_cast<char>(65)
: *base64 == c
@@ -208,7 +212,8 @@ constexpr char UnBase64Impl(char c, const char* const base64, char carry) {
template <size_t... I>
constexpr std::array<char, 256> UnBase64Impl(IndexSequence<I...>,
const char* const base64) {
- return {{UnBase64Impl(static_cast<char>(I), base64, 0)...}};
+ return {
+ {UnBase64Impl(UndoWebSafeEncoding(static_cast<char>(I)), base64, 0)...}};
}
constexpr std::array<char, 256> UnBase64(const char* const base64) {
diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc
index 7d7c55ad..afd802c3 100644
--- a/googlemock/src/gmock-spec-builders.cc
+++ b/googlemock/src/gmock-spec-builders.cc
@@ -297,7 +297,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
"See "
"https://github.com/google/googletest/blob/main/docs/"
"gmock_cook_book.md#"
- "knowing-when-to-expect for details.\n",
+ "knowing-when-to-expect-useoncall for details.\n",
stack_frames_to_skip);
break;
default: // FAIL
diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc
index 3db9746f..0738aafb 100644
--- a/googlemock/test/gmock-matchers-comparisons_test.cc
+++ b/googlemock/test/gmock-matchers-comparisons_test.cc
@@ -1802,11 +1802,13 @@ TEST(WhenBase64UnescapedTest, MatchesUnescapedBase64Strings) {
EXPECT_FALSE(m1.Matches("invalid base64"));
EXPECT_FALSE(m1.Matches("aGVsbG8gd29ybGQ=")); // hello world
EXPECT_TRUE(m1.Matches("aGVsbG8gd29ybGQh")); // hello world!
+ EXPECT_TRUE(m1.Matches("+/-_IQ")); // \xfb\xff\xbf!
const Matcher<const std::string&> m2 = WhenBase64Unescaped(EndsWith("!"));
EXPECT_FALSE(m2.Matches("invalid base64"));
EXPECT_FALSE(m2.Matches("aGVsbG8gd29ybGQ=")); // hello world
EXPECT_TRUE(m2.Matches("aGVsbG8gd29ybGQh")); // hello world!
+ EXPECT_TRUE(m2.Matches("+/-_IQ")); // \xfb\xff\xbf!
#if GTEST_INTERNAL_HAS_STRING_VIEW
const Matcher<const internal::StringView&> m3 =
@@ -1814,6 +1816,7 @@ TEST(WhenBase64UnescapedTest, MatchesUnescapedBase64Strings) {
EXPECT_FALSE(m3.Matches("invalid base64"));
EXPECT_FALSE(m3.Matches("aGVsbG8gd29ybGQ=")); // hello world
EXPECT_TRUE(m3.Matches("aGVsbG8gd29ybGQh")); // hello world!
+ EXPECT_TRUE(m3.Matches("+/-_IQ")); // \xfb\xff\xbf!
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index 76c9ff74..ad56ead0 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -1088,16 +1088,7 @@ TEST(UnexpectedCallTest, UnsatisfiedPrerequisites) {
// Verifies that the failure message contains the two unsatisfied
// pre-requisites but not the satisfied one.
-#if GTEST_USES_PCRE
- EXPECT_THAT(
- r.message(),
- ContainsRegex(
- // PCRE has trouble using (.|\n) to match any character, but
- // supports the (?s) prefix for using . to match any character.
- "(?s)the following immediate pre-requisites are not satisfied:\n"
- ".*: pre-requisite #0\n"
- ".*: pre-requisite #1"));
-#elif GTEST_USES_POSIX_RE
+#if GTEST_USES_POSIX_RE
EXPECT_THAT(r.message(),
ContainsRegex(
// POSIX RE doesn't understand the (?s) prefix, but has no
@@ -1112,7 +1103,7 @@ TEST(UnexpectedCallTest, UnsatisfiedPrerequisites) {
"the following immediate pre-requisites are not satisfied:"));
EXPECT_THAT(r.message(), ContainsRegex(": pre-requisite #0"));
EXPECT_THAT(r.message(), ContainsRegex(": pre-requisite #1"));
-#endif // GTEST_USES_PCRE
+#endif // GTEST_USES_POSIX_RE
b.DoB(1);
b.DoB(3);
@@ -2059,7 +2050,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
"See "
"https://github.com/google/googletest/blob/main/docs/"
"gmock_cook_book.md#"
- "knowing-when-to-expect for details.";
+ "knowing-when-to-expect-useoncall for details.";
// A void-returning function.
CaptureStdout();
diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt
index ac2a5e21..d6c03338 100644
--- a/googlemock/test/gmock_output_test_golden.txt
+++ b/googlemock/test/gmock_output_test_golden.txt
@@ -75,14 +75,14 @@ GMOCK WARNING:
Uninteresting mock function call - returning default value.
Function call: Bar2(0, 1)
Returns: false
-NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
+NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details.
[ OK ] GMockOutputTest.UninterestingCall
[ RUN ] GMockOutputTest.UninterestingCallToVoidFunction
GMOCK WARNING:
Uninteresting mock function call - returning directly.
Function call: Bar3(0, 1)
-NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
+NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details.
[ OK ] GMockOutputTest.UninterestingCallToVoidFunction
[ RUN ] GMockOutputTest.RetiredExpectation
unknown file: Failure
@@ -266,14 +266,14 @@ Uninteresting mock function call - taking default action specified at:
FILE:#:
Function call: Bar2(2, 2)
Returns: true
-NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
+NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details.
GMOCK WARNING:
Uninteresting mock function call - taking default action specified at:
FILE:#:
Function call: Bar2(1, 1)
Returns: false
-NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
+NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details.
[ OK ] GMockOutputTest.UninterestingCallWithDefaultAction
[ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h
index 35c08026..6fdf5524 100644
--- a/googletest/include/gtest/gtest.h
+++ b/googletest/include/gtest/gtest.h
@@ -302,7 +302,7 @@ class GTEST_API_ Test {
template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value,
bool> = true>
static void RecordProperty(const std::string& key, const T& value) {
- RecordProperty(key, (Message() << static_cast<int64_t>(value)).GetString());
+ RecordProperty(key, (Message() << value).GetString());
}
protected:
diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h
index 4687dae2..21f3d29f 100644
--- a/googletest/include/gtest/internal/gtest-death-test-internal.h
+++ b/googletest/include/gtest/internal/gtest-death-test-internal.h
@@ -238,7 +238,7 @@ inline Matcher<const ::std::string&> MakeDeathTestMatcher(
} \
break; \
case ::testing::internal::DeathTest::EXECUTE_TEST: { \
- ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
+ const ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
gtest_dt); \
GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index e1eb2b51..73395048 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -900,8 +900,10 @@ class HasDebugStringAndShortDebugString {
HasDebugStringType::value && HasShortDebugStringType::value;
};
+#ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
template <typename T>
constexpr bool HasDebugStringAndShortDebugString<T>::value;
+#endif
// When the compiler sees expression IsContainerTest<C>(0), if C is an
// STL-style container class, the first overload of IsContainerTest
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index b4fa3f07..5cea3e02 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -923,7 +923,7 @@ class GTEST_API_ RE {
~RE();
// Returns the string representation of the regex.
- const char* pattern() const { return pattern_; }
+ const char* pattern() const { return pattern_.c_str(); }
// FullMatch(str, re) returns true if and only if regular expression re
// matches the entire str.
@@ -941,7 +941,7 @@ class GTEST_API_ RE {
private:
void Init(const char* regex);
- const char* pattern_;
+ std::string pattern_;
bool is_valid_;
#if GTEST_USES_POSIX_RE
@@ -951,7 +951,7 @@ class GTEST_API_ RE {
#else // GTEST_USES_SIMPLE_RE
- const char* full_pattern_; // For FullMatch();
+ std::string full_pattern_; // For FullMatch();
#endif
};
@@ -2032,7 +2032,6 @@ inline int DoIsATTY(int fd) { return isatty(fd); }
inline int StrCaseCmp(const char* s1, const char* s2) {
return stricmp(s1, s2);
}
-inline char* StrDup(const char* src) { return strdup(src); }
#else // !__BORLANDC__
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \
GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM)
@@ -2043,24 +2042,14 @@ inline int DoIsATTY(int fd) { return _isatty(fd); }
inline int StrCaseCmp(const char* s1, const char* s2) {
return _stricmp(s1, s2);
}
-inline char* StrDup(const char* src) { return _strdup(src); }
#endif // __BORLANDC__
-#elif GTEST_OS_ESP8266
-
-inline int DoIsATTY(int fd) { return isatty(fd); }
-inline int StrCaseCmp(const char* s1, const char* s2) {
- return strcasecmp(s1, s2);
-}
-inline char* StrDup(const char* src) { return strdup(src); }
-
#else
inline int DoIsATTY(int fd) { return isatty(fd); }
inline int StrCaseCmp(const char* s1, const char* s2) {
return strcasecmp(s1, s2);
}
-inline char* StrDup(const char* src) { return strdup(src); }
#endif // GTEST_OS_WINDOWS
@@ -2352,7 +2341,8 @@ using Any = ::absl::any;
} // namespace testing
#else
#ifdef __has_include
-#if __has_include(<any>) && __cplusplus >= 201703L
+#if __has_include(<any>) && __cplusplus >= 201703L && \
+ (!defined(_MSC_VER) || GTEST_HAS_RTTI)
// Otherwise for C++17 and higher use std::any for UniversalPrinter<>
// specializations.
#define GTEST_INTERNAL_HAS_ANY 1
@@ -2457,4 +2447,9 @@ using Variant = ::std::variant<T...>;
#endif // __has_include
#endif // GTEST_HAS_ABSL
+#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
+ GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L
+#define GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL 1
+#endif
+
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc
index b6968a9c..7fcf9bf5 100644
--- a/googletest/src/gtest-death-test.cc
+++ b/googletest/src/gtest-death-test.cc
@@ -33,7 +33,9 @@
#include "gtest/gtest-death-test.h"
#include <functional>
+#include <memory>
#include <utility>
+#include <vector>
#include "gtest/internal/custom/gtest.h"
#include "gtest/internal/gtest-port.h"
@@ -621,6 +623,17 @@ bool DeathTestImpl::Passed(bool status_ok) {
return success;
}
+// Note: The return value points into args, so the return value's lifetime is
+// bound to that of args.
+std::unique_ptr<char*[]> CreateArgvFromArgs(std::vector<std::string>& args) {
+ auto result = std::make_unique<char*[]>(args.size() + 1);
+ for (size_t i = 0; i < args.size(); ++i) {
+ result[i] = &args[i][0];
+ }
+ result[args.size()] = nullptr; // extra null terminator
+ return result;
+}
+
#if GTEST_OS_WINDOWS
// WindowsDeathTest implements death tests on Windows. Due to the
// specifics of starting new processes on Windows, death tests there are
@@ -836,36 +849,6 @@ class FuchsiaDeathTest : public DeathTestImpl {
zx::socket stderr_socket_;
};
-// Utility class for accumulating command-line arguments.
-class Arguments {
- public:
- Arguments() { args_.push_back(nullptr); }
-
- ~Arguments() {
- for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
- ++i) {
- free(*i);
- }
- }
- void AddArgument(const char* argument) {
- args_.insert(args_.end() - 1, posix::StrDup(argument));
- }
-
- template <typename Str>
- void AddArguments(const ::std::vector<Str>& arguments) {
- for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
- i != arguments.end(); ++i) {
- args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
- }
- }
- char* const* Argv() { return &args_[0]; }
-
- int size() { return static_cast<int>(args_.size()) - 1; }
-
- private:
- std::vector<char*> args_;
-};
-
// Waits for the child in a death test to exit, returning its exit
// status, or 0 if no child process exists. As a side effect, sets the
// outcome data member.
@@ -986,10 +969,10 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
kInternalRunDeathTestFlag + "=" + file_ +
"|" + StreamableToString(line_) + "|" +
StreamableToString(death_test_index);
- Arguments args;
- args.AddArguments(GetInjectableArgvs());
- args.AddArgument(filter_flag.c_str());
- args.AddArgument(internal_flag.c_str());
+
+ std::vector<std::string> args = GetInjectableArgvs();
+ args.push_back(filter_flag);
+ args.push_back(internal_flag);
// Build the pipe for communication with the child.
zx_status_t status;
@@ -1041,8 +1024,9 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
// Spawn the child process.
- status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, args.Argv()[0],
- args.Argv(), nullptr, 2, spawn_actions,
+ std::unique_ptr<char*[]> argv = CreateArgvFromArgs(args);
+ status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.get(),
+ nullptr, 2, spawn_actions,
child_process_.reset_and_get_address(), nullptr);
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
@@ -1173,34 +1157,6 @@ class ExecDeathTest : public ForkingDeathTest {
const int line_;
};
-// Utility class for accumulating command-line arguments.
-class Arguments {
- public:
- Arguments() { args_.push_back(nullptr); }
-
- ~Arguments() {
- for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
- ++i) {
- free(*i);
- }
- }
- void AddArgument(const char* argument) {
- args_.insert(args_.end() - 1, posix::StrDup(argument));
- }
-
- template <typename Str>
- void AddArguments(const ::std::vector<Str>& arguments) {
- for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
- i != arguments.end(); ++i) {
- args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
- }
- }
- char* const* Argv() { return &args_[0]; }
-
- private:
- std::vector<char*> args_;
-};
-
// A struct that encompasses the arguments to the child process of a
// threadsafe-style death test process.
struct ExecDeathTestArgs {
@@ -1410,10 +1366,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
StreamableToString(line_) + "|" +
StreamableToString(death_test_index) + "|" +
StreamableToString(pipe_fd[1]);
- Arguments args;
- args.AddArguments(GetArgvsForDeathTestChildProcess());
- args.AddArgument(filter_flag.c_str());
- args.AddArgument(internal_flag.c_str());
+ std::vector<std::string> args = GetArgvsForDeathTestChildProcess();
+ args.push_back(filter_flag);
+ args.push_back(internal_flag);
DeathTest::set_last_death_test_message("");
@@ -1422,7 +1377,8 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
// is necessary.
FlushInfoLog();
- const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]);
+ std::unique_ptr<char*[]> argv = CreateArgvFromArgs(args);
+ const pid_t child_pid = ExecDeathTestSpawnChild(argv.get(), pipe_fd[0]);
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
set_child_pid(child_pid);
set_read_fd(pipe_fd[0]);
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc
index d797fe4d..105a3ec8 100644
--- a/googletest/src/gtest-port.cc
+++ b/googletest/src/gtest-port.cc
@@ -668,7 +668,6 @@ RE::~RE() {
regfree(&partial_regex_);
regfree(&full_regex_);
}
- free(const_cast<char*>(pattern_));
}
// Returns true if and only if regular expression re matches the entire str.
@@ -690,7 +689,7 @@ bool RE::PartialMatch(const char* str, const RE& re) {
// Initializes an RE from its string representation.
void RE::Init(const char* regex) {
- pattern_ = posix::StrDup(regex);
+ pattern_ = regex;
// Reserves enough bytes to hold the regular expression used for a
// full match.
@@ -920,27 +919,26 @@ bool MatchRegexAnywhere(const char* regex, const char* str) {
// Implements the RE class.
-RE::~RE() {
- free(const_cast<char*>(pattern_));
- free(const_cast<char*>(full_pattern_));
-}
+RE::~RE() = default;
// Returns true if and only if regular expression re matches the entire str.
bool RE::FullMatch(const char* str, const RE& re) {
- return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str);
+ return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_.c_str(), str);
}
// Returns true if and only if regular expression re matches a substring of
// str (including str itself).
bool RE::PartialMatch(const char* str, const RE& re) {
- return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str);
+ return re.is_valid_ && MatchRegexAnywhere(re.pattern_.c_str(), str);
}
// Initializes an RE from its string representation.
void RE::Init(const char* regex) {
- pattern_ = full_pattern_ = nullptr;
+ full_pattern_.clear();
+ pattern_.clear();
+
if (regex != nullptr) {
- pattern_ = posix::StrDup(regex);
+ pattern_ = regex;
}
is_valid_ = ValidateRegex(regex);
@@ -949,25 +947,19 @@ void RE::Init(const char* regex) {
return;
}
- const size_t len = strlen(regex);
// Reserves enough bytes to hold the regular expression used for a
- // full match: we need space to prepend a '^', append a '$', and
- // terminate the string with '\0'.
- char* buffer = static_cast<char*>(malloc(len + 3));
- full_pattern_ = buffer;
+ // full match: we need space to prepend a '^' and append a '$'.
+ full_pattern_.reserve(pattern_.size() + 2);
- if (*regex != '^')
- *buffer++ = '^'; // Makes sure full_pattern_ starts with '^'.
-
- // We don't use snprintf or strncpy, as they trigger a warning when
- // compiled with VC++ 8.0.
- memcpy(buffer, regex, len);
- buffer += len;
+ if (pattern_.empty() || pattern_.front() != '^') {
+ full_pattern_.push_back('^'); // Makes sure full_pattern_ starts with '^'.
+ }
- if (len == 0 || regex[len - 1] != '$')
- *buffer++ = '$'; // Makes sure full_pattern_ ends with '$'.
+ full_pattern_.append(pattern_);
- *buffer = '\0';
+ if (pattern_.empty() || pattern_.back() != '$') {
+ full_pattern_.push_back('$'); // Makes sure full_pattern_ ends with '$'.
+ }
}
#endif // GTEST_USES_POSIX_RE
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index f79f915f..a60a042c 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -2325,7 +2325,9 @@ static std::vector<std::string> GetReservedAttributesForElement(
return std::vector<std::string>();
}
+#if GTEST_HAS_FILE_SYSTEM
// TODO(jdesprez): Merge the two getReserved attributes once skip is improved
+// This function is only used when file systems are enabled.
static std::vector<std::string> GetReservedOutputAttributesForElement(
const std::string& xml_element) {
if (xml_element == "testsuites") {
@@ -2340,6 +2342,7 @@ static std::vector<std::string> GetReservedOutputAttributesForElement(
// This code is unreachable but some compilers may not realizes that.
return std::vector<std::string>();
}
+#endif
static std::string FormatWordList(const std::vector<std::string>& words) {
Message word_list;
@@ -6802,7 +6805,7 @@ std::string TempDir() {
#endif
}
-#if !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_)
+#if GTEST_HAS_FILE_SYSTEM && !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_)
// Returns the directory path (including terminating separator) of the current
// executable as derived from argv[0].
static std::string GetCurrentExecutableDirectory() {
@@ -6811,6 +6814,7 @@ static std::string GetCurrentExecutableDirectory() {
}
#endif
+#if GTEST_HAS_FILE_SYSTEM
std::string SrcDir() {
#if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_)
return GTEST_CUSTOM_SRCDIR_FUNCTION_();
@@ -6825,6 +6829,7 @@ std::string SrcDir() {
'/');
#endif
}
+#endif
// Class ScopedTrace
diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc
index 4737ff9b..515b5998 100644
--- a/googletest/test/googletest-death-test-test.cc
+++ b/googletest/test/googletest-death-test-test.cc
@@ -327,23 +327,6 @@ TEST_F(TestForDeathTest, SingleStatement) {
#pragma GCC diagnostic pop
#endif
-#if GTEST_USES_PCRE
-
-void DieWithEmbeddedNul() {
- fprintf(stderr, "Hello%cmy null world.\n", '\0');
- fflush(stderr);
- _exit(1);
-}
-
-// Tests that EXPECT_DEATH and ASSERT_DEATH work when the error
-// message has a NUL character in it.
-TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
- EXPECT_DEATH(DieWithEmbeddedNul(), "my null world");
- ASSERT_DEATH(DieWithEmbeddedNul(), "my null world");
-}
-
-#endif // GTEST_USES_PCRE
-
// Tests that death test macros expand to code which interacts well with switch
// statements.
TEST_F(TestForDeathTest, SwitchStatement) {
@@ -521,16 +504,12 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
const testing::internal::RE regex(regex_c_str);
EXPECT_DEATH(GlobalFunction(), regex);
-#if !GTEST_USES_PCRE
-
const ::std::string regex_std_str(regex_c_str);
EXPECT_DEATH(GlobalFunction(), regex_std_str);
// This one is tricky; a temporary pointer into another temporary. Reference
// lifetime extension of the pointer is not sufficient.
EXPECT_DEATH(GlobalFunction(), ::std::string(regex_c_str).c_str());
-
-#endif // !GTEST_USES_PCRE
}
// Tests that a non-void function can be used in a death test.
diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py
index 83a56de1..ff157223 100644
--- a/googletest/test/googletest-json-outfiles-test.py
+++ b/googletest/test/googletest-json-outfiles-test.py
@@ -88,7 +88,7 @@ EXPECTED_2 = {
'time': '*',
'timestamp': '*',
'testsuite': [{
- 'name': 'TestInt64Properties',
+ 'name': 'TestInt64ConvertibleProperties',
'file': 'gtest_xml_outfile2_test_.cc',
'line': 41,
'status': 'RUN',
@@ -97,11 +97,11 @@ EXPECTED_2 = {
'time': '*',
'classname': 'PropertyTwo',
'SetUpProp': '2',
- 'TestFloatProperty': '3',
- 'TestDoubleProperty': '4',
+ 'TestFloatProperty': '3.25',
+ 'TestDoubleProperty': '4.75',
'TestSizetProperty': '5',
- 'TestBoolProperty': '1',
- 'TestCharProperty': '65',
+ 'TestBoolProperty': 'true',
+ 'TestCharProperty': 'A',
'TestInt16Property': '6',
'TestInt32Property': '7',
'TestInt64Property': '8',
diff --git a/googletest/test/gtest_dirs_test.cc b/googletest/test/gtest_dirs_test.cc
index c0da9ac4..1a5b63d3 100644
--- a/googletest/test/gtest_dirs_test.cc
+++ b/googletest/test/gtest_dirs_test.cc
@@ -7,6 +7,8 @@
#include "gtest/gtest.h"
#include "gtest/internal/gtest-port.h"
+#if GTEST_HAS_FILE_SYSTEM
+
namespace {
class SetEnv {
@@ -94,4 +96,6 @@ TEST(SrcDirTest, NotInEnvironment) {
EXPECT_NE(testing::SrcDir(), "");
}
+#endif // GTEST_HAS_FILE_SYSTEM
+
} // namespace
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 2199073d..580ce837 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -60,6 +60,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
#include <cstdint>
#include <map>
+#include <memory>
#include <ostream>
#include <set>
#include <string>
@@ -424,10 +425,12 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
private:
void SetUp() override {
- saved_tz_ = nullptr;
+ saved_tz_.reset();
- GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */)
- if (getenv("TZ")) saved_tz_ = strdup(getenv("TZ"));
+ GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv: deprecated */)
+ if (const char* tz = getenv("TZ")) {
+ saved_tz_ = std::make_unique<std::string>(tz);
+ }
GTEST_DISABLE_MSC_DEPRECATED_POP_()
// Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We
@@ -437,16 +440,15 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
}
void TearDown() override {
- SetTimeZone(saved_tz_);
- free(const_cast<char*>(saved_tz_));
- saved_tz_ = nullptr;
+ SetTimeZone(saved_tz_ != nullptr ? saved_tz_->c_str() : nullptr);
+ saved_tz_.reset();
}
static void SetTimeZone(const char* time_zone) {
// tzset() distinguishes between the TZ variable being present and empty
// and not being present, so we have to consider the case of time_zone
// being NULL.
-#if _MSC_VER || GTEST_OS_WINDOWS_MINGW
+#if defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW
// ...Unless it's MSVC, whose standard library's _putenv doesn't
// distinguish between an empty and a missing variable.
const std::string env_var =
@@ -471,7 +473,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
#endif
}
- const char* saved_tz_;
+ std::unique_ptr<std::string> saved_tz_; // Empty and null are different here
};
const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc
index 5ee216df..ed58dc8d 100644
--- a/googletest/test/gtest_xml_outfile2_test_.cc
+++ b/googletest/test/gtest_xml_outfile2_test_.cc
@@ -38,9 +38,7 @@ class PropertyTwo : public testing::Test {
void TearDown() override { RecordProperty("TearDownProp", 2); }
};
-TEST_F(PropertyTwo, TestInt64Properties) {
- // Floats and doubles are written as int64_t, so we test that the values
- // written are truncated to int64_t.
+TEST_F(PropertyTwo, TestInt64ConvertibleProperties) {
float float_prop = 3.25;
RecordProperty("TestFloatProperty", float_prop);
diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py
index 7ee0f3c8..50291b0a 100755
--- a/googletest/test/gtest_xml_outfiles_test.py
+++ b/googletest/test/gtest_xml_outfiles_test.py
@@ -57,14 +57,14 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyTwo" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
- <testcase name="TestInt64Properties" file="gtest_xml_outfile2_test_.cc" line="41" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
+ <testcase name="TestInt64ConvertibleProperties" file="gtest_xml_outfile2_test_.cc" line="41" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
<properties>
<property name="SetUpProp" value="2"/>
- <property name="TestFloatProperty" value="3"/>
- <property name="TestDoubleProperty" value="4"/>
+ <property name="TestFloatProperty" value="3.25"/>
+ <property name="TestDoubleProperty" value="4.75"/>
<property name="TestSizetProperty" value="5"/>
- <property name="TestBoolProperty" value="1"/>
- <property name="TestCharProperty" value="65"/>
+ <property name="TestBoolProperty" value="true"/>
+ <property name="TestCharProperty" value="A"/>
<property name="TestInt16Property" value="6"/>
<property name="TestInt32Property" value="7"/>
<property name="TestInt64Property" value="8"/>