kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/testdata/extract_transcript_test.cc (about) 1 /* 2 * Copyright 2019 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "absl/strings/string_view.h" 18 #include "gmock/gmock.h" 19 #include "gtest/gtest.h" 20 #include "kythe/cxx/extractor/testlib.h" 21 #include "kythe/proto/analysis.pb.h" 22 #include "protobuf-matchers/protocol-buffer-matchers.h" 23 24 namespace kythe { 25 namespace { 26 using ::protobuf_matchers::EquivToProto; 27 28 proto::CompilationUnit ExpectedCompilation() { 29 return ParseTextCompilationUnitOrDie(R"pb( 30 v_name { language: "c++" } 31 required_input { 32 v_name { path: "kythe/cxx/extractor/testdata/transcript_main.cc" } 33 info { 34 path: "kythe/cxx/extractor/testdata/transcript_main.cc" 35 digest: "a719ebca696362eb639992c5afd3b08ab6c1938bc5639fdfe1fde06fd86bd622" 36 } 37 details { 38 [type.googleapis.com/kythe.proto.ContextDependentVersion] { 39 row { 40 source_context: "hash0" 41 always_process: true 42 column { offset: 20 linked_context: "hash1" } 43 column { offset: 46 linked_context: "hash2" } 44 column { offset: 72 linked_context: "hash3" } 45 column { offset: 98 linked_context: "hash2" } 46 } 47 } 48 } 49 } 50 required_input { 51 v_name { path: "kythe/cxx/extractor/testdata/transcript_a.h" } 52 info { 53 path: "kythe/cxx/extractor/testdata/transcript_a.h" 54 digest: "15d3490610af31dff6f1be9948ef61e66db48a84fc8fd93a81a5433abab04309" 55 } 56 details { 57 [type.googleapis.com/kythe.proto.ContextDependentVersion] { 58 row { source_context: "hash3" } 59 row { source_context: "hash1" } 60 } 61 } 62 } 63 required_input { 64 v_name { path: "kythe/cxx/extractor/testdata/transcript_b.h" } 65 info { 66 path: "kythe/cxx/extractor/testdata/transcript_b.h" 67 digest: "6904079b7b9d5d0586a08dbbdac2b08d35f00c1dbb4cc63721f22a347f52e2f7" 68 } 69 details { 70 [type.googleapis.com/kythe.proto.ContextDependentVersion] { 71 row { source_context: "hash2" } 72 } 73 } 74 } 75 argument: "/dummy/bin/g++" 76 argument: "-target" 77 argument: "dummy-target" 78 argument: "-DKYTHE_IS_RUNNING=1" 79 argument: "-resource-dir" 80 argument: "/kythe_builtins" 81 argument: "--driver-mode=g++" 82 argument: "-I./kythe/cxx/extractor/testdata" 83 argument: "./kythe/cxx/extractor/testdata/transcript_main.cc" 84 argument: "-fsyntax-only" 85 source_file: "kythe/cxx/extractor/testdata/transcript_main.cc" 86 working_directory: "/root" 87 entry_context: "hash0" 88 )pb"); 89 } 90 91 TEST(CxxExtractorTest, TextExtractedTranscript) { 92 kythe::proto::CompilationUnit unit = ExtractSingleCompilationOrDie({{ 93 "--with_executable", 94 "/dummy/bin/g++", 95 "-I./kythe/cxx/extractor/testdata", 96 "./kythe/cxx/extractor/testdata/transcript_main.cc", 97 }}); 98 CanonicalizeHashes(&unit); 99 unit.clear_details(); 100 unit.set_argument(2, "dummy-target"); 101 102 EXPECT_THAT(unit, EquivToProto(ExpectedCompilation())); 103 } 104 105 } // namespace 106 } // namespace kythe