Repository: kythe/kythe
Pull request #5410 (2022-10-26 17:59:33)

feat(tooling): mark conflicting /kythe/code facts as ok with ignore flag and add tests
Only flip the `is_ok` flag when not ignoring conflicting `/kythe/code` facts. Also add tests for the flag. 

shahms: /gcbrun

Patch:
diff --git a/kythe/cxx/verifier/verifier.cc b/kythe/cxx/verifier/verifier.cc
index 237f809ba..36f56f104 100644
--- a/kythe/cxx/verifier/verifier.cc
+++ b/kythe/cxx/verifier/verifier.cc
@@ -1293,6 +1293,7 @@ bool Verifier::PrepareDatabase() {
           print_decoded(ta->element(4));
           printer.Print("\n -----------------  versus  ----------------- \n\n");
           print_decoded(tb->element(4));
+          is_ok = false;
         }
       } else {
         printer.Print("Two facts about a node differed in value:\n  ");
@@ -1300,8 +1301,8 @@ bool Verifier::PrepareDatabase() {
         printer.Print("\n  ");
         fb->Dump(symbol_table_, &printer);
         printer.Print("\n");
+        is_ok = false;
       }
-      is_ok = false;
     }
   }
   if (is_ok) {


Test patch:
diff --git a/kythe/cxx/verifier/verifier_unit_test.cc b/kythe/cxx/verifier/verifier_unit_test.cc
index c5300081f..5fcd8c931 100644
--- a/kythe/cxx/verifier/verifier_unit_test.cc
+++ b/kythe/cxx/verifier/verifier_unit_test.cc
@@ -2934,6 +2934,69 @@ TEST(VerifierUnitTest, ConvertMarkedSourceDuplicateFactsWellFormed) {
   ASSERT_TRUE(v.VerifyAllGoals());
 }
 
+TEST(VerifierUnitTest, ConflictingCodeFactsNotWellFormed) {
+  Verifier v;
+  MarkedSource source;
+  google::protobuf::string source_string;
+  ASSERT_TRUE(source.SerializeToString(&source_string));
+  google::protobuf::TextFormat::FieldValuePrinter printer;
+  google::protobuf::string enc_source = printer.PrintBytes(source_string);
+
+  MarkedSource source_conflict;
+  source_conflict.set_pre_text("pre_text");
+  google::protobuf::string source_conflict_string;
+  ASSERT_TRUE(source_conflict.SerializeToString(&source_conflict_string));
+  google::protobuf::string enc_source_conflict =
+      printer.PrintBytes(source_conflict_string);
+  ASSERT_TRUE(v.LoadInlineProtoFile(R"(
+  entries {
+    source { signature:"test" }
+    fact_name: "/kythe/code"
+    fact_value: )" + enc_source + R"(
+  }
+  entries {
+    source { signature:"test" }
+    fact_name: "/kythe/code"
+    fact_value: )" + enc_source_conflict +
+                                    R"(
+  }
+  )"));
+  ASSERT_FALSE(v.PrepareDatabase());
+  ASSERT_FALSE(v.VerifyAllGoals());
+}
+
+TEST(VerifierUnitTest, ConflictingCodeFactsIgnoreWellFormed) {
+  Verifier v;
+  v.IgnoreCodeConflicts();
+  MarkedSource source;
+  google::protobuf::string source_string;
+  ASSERT_TRUE(source.SerializeToString(&source_string));
+  google::protobuf::TextFormat::FieldValuePrinter printer;
+  google::protobuf::string enc_source = printer.PrintBytes(source_string);
+
+  MarkedSource source_conflict;
+  source_conflict.set_pre_text("pre_text");
+  google::protobuf::string source_conflict_string;
+  ASSERT_TRUE(source_conflict.SerializeToString(&source_conflict_string));
+  google::protobuf::string enc_source_conflict =
+      printer.PrintBytes(source_conflict_string);
+  ASSERT_TRUE(v.LoadInlineProtoFile(R"(
+  entries {
+    source { signature:"test" }
+    fact_name: "/kythe/code"
+    fact_value: )" + enc_source + R"(
+  }
+  entries {
+    source { signature:"test" }
+    fact_name: "/kythe/code"
+    fact_value: )" + enc_source_conflict +
+                                    R"(
+  }
+  )"));
+  ASSERT_TRUE(v.PrepareDatabase());
+  ASSERT_TRUE(v.VerifyAllGoals());
+}
+
 }  // anonymous namespace
 }  // namespace verifier
 }  // namespace kythe