Skip to content

Commit

Permalink
Revert Optimize Google Test process startup
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 612878184
Change-Id: Ia8e23da1ad09c2e0ce635a855f0c250f368f6878
  • Loading branch information
Abseil Team authored and copybara-github committed Mar 5, 2024
1 parent b9059aa commit 31993df
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 160 deletions.
6 changes: 3 additions & 3 deletions googletest/include/gtest/gtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ class GTEST_API_ TestInfo {
friend class internal::UnitTestImpl;
friend class internal::StreamingListenerTest;
friend TestInfo* internal::MakeAndRegisterTestInfo(
std::string test_suite_name, const char* name, const char* type_param,
const char* test_suite_name, const char* name, const char* type_param,
const char* value_param, internal::CodeLocation code_location,
internal::TypeId fixture_class_id, internal::SetUpTestSuiteFunc set_up_tc,
internal::TearDownTestSuiteFunc tear_down_tc,
internal::TestFactoryBase* factory);

// Constructs a TestInfo object. The newly constructed instance assumes
// ownership of the factory object.
TestInfo(std::string test_suite_name, std::string name,
TestInfo(const std::string& test_suite_name, const std::string& name,
const char* a_type_param, // NULL if not a type-parameterized test
const char* a_value_param, // NULL if not a value-parameterized test
internal::CodeLocation a_code_location,
Expand Down Expand Up @@ -683,7 +683,7 @@ class GTEST_API_ TestSuite {
// this is not a type-parameterized test.
// set_up_tc: pointer to the function that sets up the test suite
// tear_down_tc: pointer to the function that tears down the test suite
TestSuite(const std::string& name, const char* a_type_param,
TestSuite(const char* name, const char* a_type_param,
internal::SetUpTestSuiteFunc set_up_tc,
internal::TearDownTestSuiteFunc tear_down_tc);

Expand Down
8 changes: 1 addition & 7 deletions googletest/include/gtest/internal/gtest-filepath.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_

#include <string>
#include <utility>

#include "gtest/internal/gtest-port.h"
#include "gtest/internal/gtest-string.h"
Expand Down Expand Up @@ -71,20 +70,15 @@ class GTEST_API_ FilePath {
public:
FilePath() : pathname_("") {}
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) {}
FilePath(FilePath&& rhs) : pathname_(std::move(rhs.pathname_)) {}

explicit FilePath(std::string pathname) : pathname_(std::move(pathname)) {
explicit FilePath(const std::string& pathname) : pathname_(pathname) {
Normalize();
}

FilePath& operator=(const FilePath& rhs) {
Set(rhs);
return *this;
}
FilePath& operator=(FilePath&& rhs) {
pathname_ = std::move(rhs.pathname_);
return *this;
}

void Set(const FilePath& rhs) { pathname_ = rhs.pathname_; }

Expand Down
29 changes: 17 additions & 12 deletions googletest/include/gtest/internal/gtest-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ using SetUpTestSuiteFunc = void (*)();
using TearDownTestSuiteFunc = void (*)();

struct CodeLocation {
CodeLocation(std::string a_file, int a_line)
: file(std::move(a_file)), line(a_line) {}
CodeLocation(const std::string& a_file, int a_line)
: file(a_file), line(a_line) {}

std::string file;
int line;
Expand Down Expand Up @@ -564,7 +564,7 @@ struct SuiteApiResolver : T {
// The newly created TestInfo instance will assume
// ownership of the factory object.
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
std::string test_suite_name, const char* name, const char* type_param,
const char* test_suite_name, const char* name, const char* type_param,
const char* value_param, CodeLocation code_location,
TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc,
TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory);
Expand Down Expand Up @@ -595,7 +595,8 @@ class GTEST_API_ TypedTestSuitePState {
fflush(stderr);
posix::Abort();
}
registered_tests_.emplace(test_name, CodeLocation(file, line));
registered_tests_.insert(
::std::make_pair(test_name, CodeLocation(file, line)));
return true;
}

Expand Down Expand Up @@ -699,7 +700,7 @@ class TypeParameterizedTest {
// specified in INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, TestSuite,
// Types). Valid values for 'index' are [0, N - 1] where N is the
// length of Types.
static bool Register(const char* prefix, CodeLocation code_location,
static bool Register(const char* prefix, const CodeLocation& code_location,
const char* case_name, const char* test_names, int index,
const std::vector<std::string>& type_names =
GenerateNames<DefaultNameGenerator, Types>()) {
Expand All @@ -711,7 +712,8 @@ class TypeParameterizedTest {
// list.
MakeAndRegisterTestInfo(
(std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name +
"/" + type_names[static_cast<size_t>(index)]),
"/" + type_names[static_cast<size_t>(index)])
.c_str(),
StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
GetTypeName<Type>().c_str(),
nullptr, // No value parameter.
Expand All @@ -723,17 +725,21 @@ class TypeParameterizedTest {
new TestFactoryImpl<TestClass>);

// Next, recurses (at compile time) with the tail of the type list.
return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>::
Register(prefix, std::move(code_location), case_name, test_names,
index + 1, type_names);
return TypeParameterizedTest<Fixture, TestSel,
typename Types::Tail>::Register(prefix,
code_location,
case_name,
test_names,
index + 1,
type_names);
}
};

// The base case for the compile time recursion.
template <GTEST_TEMPLATE_ Fixture, class TestSel>
class TypeParameterizedTest<Fixture, TestSel, internal::None> {
public:
static bool Register(const char* /*prefix*/, CodeLocation,
static bool Register(const char* /*prefix*/, const CodeLocation&,
const char* /*case_name*/, const char* /*test_names*/,
int /*index*/,
const std::vector<std::string>& =
Expand Down Expand Up @@ -780,8 +786,7 @@ class TypeParameterizedTestSuite {

// Next, recurses (at compile time) with the tail of the test list.
return TypeParameterizedTestSuite<Fixture, typename Tests::Tail,
Types>::Register(prefix,
std::move(code_location),
Types>::Register(prefix, code_location,
state, case_name,
SkipComma(test_names),
type_names);
Expand Down
Loading

0 comments on commit 31993df

Please sign in to comment.