Use ParseTextProtoOrDie instead of ParseTestProto in suggested reproducer tests ParseTestProto potentially hides its failure to parse the proto, leading to bugs in test code. This CL replaces it with ParseTextProtoOrDie, which crashes loudly on invalid input. The generated reproducer tests always pass a string literal to proto parsing, so if it does not crash on presubmit, such a test is safe. The CL also fully qualifies the function name to help make sure that the result compiles. PiperOrigin-RevId: 625797971
diff --git a/fuzztest/internal/type_support.h b/fuzztest/internal/type_support.h index 8441acf..d068992 100644 --- a/fuzztest/internal/type_support.h +++ b/fuzztest/internal/type_support.h
@@ -254,12 +254,14 @@ // Deref if necessary. return PrintUserValue(*val, out, mode); } else { + static constexpr absl::string_view kProtoParser = "ParseTestProto"; switch (mode) { case domain_implementor::PrintMode::kHumanReadable: absl::Format(out, "(%s)", absl::StrCat(val)); break; case domain_implementor::PrintMode::kSourceCode: - absl::Format(out, "ParseTestProto(R\"pb(%s)pb\")", absl::StrCat(val)); + absl::Format(out, "%s(R\"pb(%s)pb\")", kProtoParser, + absl::StrCat(val)); break; } }
diff --git a/fuzztest/internal/type_support_test.cc b/fuzztest/internal/type_support_test.cc index d3af268..354c6a3 100644 --- a/fuzztest/internal/type_support_test.cc +++ b/fuzztest/internal/type_support_test.cc
@@ -228,10 +228,11 @@ internal::TestProtobuf proto; proto.set_b(true); proto.add_rep_subproto()->set_subproto_i32(17); - EXPECT_THAT( - TestPrintValue(proto), - ElementsAre(absl::StrCat("(", proto, ")"), - absl::StrCat("ParseTestProto(R\"pb(", proto, ")pb\")"))); + EXPECT_THAT(TestPrintValue(proto), + ElementsAre(absl::StrCat("(", proto, ")"), + MatchesRegex(absl::StrCat( + R"re(.*ParseTe[sx]tProto.*\(R"pb\()re", proto, + R"re(\)pb"\))re")))); } TEST(ProtobufEnumTest, Printer) {