deps: update googletest to d72f9c8aea6817cdf1ca0ac10887f328de7f3da2 · nodejs/node@fa46c90
@@ -407,6 +407,18 @@ GTEST_DEFINE_bool_(
407407 "if exceptions are enabled or exit the program with a non-zero code "
408408 "otherwise. For use with an external test framework.");
409409410+GTEST_DEFINE_int32_(
411+ shard_index,
412+testing::internal::Int32FromEnvOrDie(testing::kTestShardIndex, -1),
413+ "The zero-based index of the shard to run. A value of -1 "
414+ "(the default) indicates that sharding is disabled.");
415+416+GTEST_DEFINE_int32_(
417+ total_shards,
418+testing::internal::Int32FromEnvOrDie(testing::kTestTotalShards, -1),
419+ "The total number of shards to use when running tests in parallel. "
420+ "A value of -1 (the default) indicates that sharding is disabled.");
421+410422#if GTEST_USE_OWN_FLAGFILE_FLAG_
411423GTEST_DEFINE_string_(
412424 flagfile, testing::internal::StringFromGTestEnv("flagfile", ""),
@@ -3475,11 +3487,11 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart(
34753487 filter);
34763488 }
347734893478-if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) {
3479-const int32_t shard_index = Int32FromEnvOrDie(kTestShardIndex, -1);
3480-ColoredPrintf(GTestColor::kYellow, "Note: This is test shard %d of %s.\n",
3490+if (internal::ShouldShard(false)) {
3491+const int32_t shard_index = GTEST_FLAG_GET(shard_index);
3492+ColoredPrintf(GTestColor::kYellow, "Note: This is test shard %d of %d.\n",
34813493static_cast<int>(shard_index) + 1,
3482-internal::posix::GetEnv(kTestTotalShards));
3494+GTEST_FLAG_GET(total_shards));
34833495 }
3484349634853497if (GTEST_FLAG_GET(shuffle)) {
@@ -5983,8 +5995,7 @@ bool UnitTestImpl::RunAllTests() {
59835995#endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
59845996#endif // GTEST_HAS_DEATH_TEST
598559975986-const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex,
5987- in_subprocess_for_death_test);
5998+const bool should_shard = ShouldShard(in_subprocess_for_death_test);
5988599959896000// Compares the full test names with the filter to decide which
59906001// tests to run.
@@ -6196,45 +6207,44 @@ void WriteToShardStatusFileIfNeeded() {
61966207}
61976208#endif // GTEST_HAS_FILE_SYSTEM
619862096199-// Checks whether sharding is enabled by examining the relevant
6200-// environment variable values. If the variables are present,
6201-// but inconsistent (i.e., shard_index >= total_shards), prints
6202-// an error and exits. If in_subprocess_for_death_test, sharding is
6203-// disabled because it must only be applied to the original test
6204-// process. Otherwise, we could filter out death tests we intended to execute.
6205-bool ShouldShard(const char* total_shards_env, const char* shard_index_env,
6206-bool in_subprocess_for_death_test) {
6210+// Checks whether sharding is enabled by examining the relevant command line
6211+// arguments. If the arguments are present, but inconsistent
6212+// (i.e., shard_index >= total_shards), prints an error and exits.
6213+// If in_subprocess_for_death_test, sharding is disabled because it must only
6214+// be applied to the original test process. Otherwise, we could filter out death
6215+// tests we intended to execute.
6216+bool ShouldShard(bool in_subprocess_for_death_test) {
62076217if (in_subprocess_for_death_test) {
62086218return false;
62096219 }
621062206211-const int32_t total_shards = Int32FromEnvOrDie(total_shards_env, -1);
6212-const int32_t shard_index = Int32FromEnvOrDie(shard_index_env, -1);
6221+const int32_t total_shards = GTEST_FLAG_GET(total_shards);
6222+const int32_t shard_index = GTEST_FLAG_GET(shard_index);
6213622362146224if (total_shards == -1 && shard_index == -1) {
62156225return false;
62166226 } else if (total_shards == -1 && shard_index != -1) {
6217-const Message msg = Message() << "Invalid environment variables: you have "
6218- << kTestShardIndex << " = " << shard_index
6219- << ", but have left " << kTestTotalShards
6220- << " unset.\n";
6227+const Message msg = Message()
6228+ << "Invalid sharding: you have " << kTestShardIndex
6229+<< " = " << shard_index << ", but have left "
6230+<< kTestTotalShards << " unset.\n";
62216231ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str());
62226232fflush(stdout);
62236233exit(EXIT_FAILURE);
62246234 } else if (total_shards != -1 && shard_index == -1) {
62256235const Message msg = Message()
6226- << "Invalid environment variables: you have "
6227- << kTestTotalShards << " = " << total_shards
6228- << ", but have left " << kTestShardIndex << " unset.\n";
6236+ << "Invalid sharding: you have " << kTestTotalShards
6237+ << " = " << total_shards << ", but have left "
6238+ << kTestShardIndex << " unset.\n";
62296239ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str());
62306240fflush(stdout);
62316241exit(EXIT_FAILURE);
62326242 } else if (shard_index < 0 || shard_index >= total_shards) {
62336243const Message msg =
6234-Message() << "Invalid environment variables: we require 0 <= "
6235- << kTestShardIndex << " < " << kTestTotalShards
6236- << ", but you have " << kTestShardIndex << "=" << shard_index
6237- << ", " << kTestTotalShards << "=" << total_shards << ".\n";
6244+Message() << "Invalid sharding: we require 0 <= " << kTestShardIndex
6245+ << " < " << kTestTotalShards << ", but you have "
6246+ << kTestShardIndex << "=" << shard_index << ", "
6247+ << kTestTotalShards << "=" << total_shards << ".\n";
62386248ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str());
62396249fflush(stdout);
62406250exit(EXIT_FAILURE);
@@ -6277,11 +6287,10 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) {
62776287// . Returns the number of tests that should run.
62786288int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
62796289const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL
6280- ? Int32FromEnvOrDie(kTestTotalShards, -1)
6290+ ? GTEST_FLAG_GET(total_shards)
62816291 : -1;
6282-const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL
6283- ? Int32FromEnvOrDie(kTestShardIndex, -1)
6284- : -1;
6292+const int32_t shard_index =
6293+ shard_tests == HONOR_SHARDING_PROTOCOL ? GTEST_FLAG_GET(shard_index) : -1;
6285629462866295const PositiveAndNegativeUnitTestFilter gtest_flag_filter(
62876296GTEST_FLAG_GET(filter));
@@ -6810,6 +6819,8 @@ static bool ParseGoogleTestFlag(const char* const arg) {
68106819GTEST_INTERNAL_PARSE_FLAG(print_utf8);
68116820GTEST_INTERNAL_PARSE_FLAG(random_seed);
68126821GTEST_INTERNAL_PARSE_FLAG(repeat);
6822+GTEST_INTERNAL_PARSE_FLAG(shard_index);
6823+GTEST_INTERNAL_PARSE_FLAG(total_shards);
68136824GTEST_INTERNAL_PARSE_FLAG(recreate_environments_when_repeating);
68146825GTEST_INTERNAL_PARSE_FLAG(shuffle);
68156826GTEST_INTERNAL_PARSE_FLAG(stack_trace_depth);