kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/testdata/metadata_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/metadata.cc" } 33 info { 34 path: "kythe/cxx/extractor/testdata/metadata.cc" 35 digest: "72269be69625ca9015a59bf7342dce1a30e96ddda51196c9f6ae6c4cbdefb7ea" 36 } 37 details { 38 [type.googleapis.com/kythe.proto.ContextDependentVersion] { 39 row { source_context: "hash0" always_process: true } 40 } 41 } 42 } 43 required_input { 44 v_name { path: "kythe/cxx/extractor/testdata/metadata.cc.meta" } 45 info { 46 path: "kythe/cxx/extractor/testdata/metadata.cc.meta" 47 digest: "1d6faa9e1a76d13f3ab8558a3640158b1f0a54f624a4e37ddc3ef41ed4191058" 48 } 49 } 50 argument: "/dummy/bin/g++" 51 argument: "-target" 52 argument: "dummy-target" 53 argument: "-DKYTHE_IS_RUNNING=1" 54 argument: "-resource-dir" 55 argument: "/kythe_builtins" 56 argument: "--driver-mode=g++" 57 argument: "-I./kythe/cxx/extractor" 58 argument: "./kythe/cxx/extractor/testdata/metadata.cc" 59 argument: "-fsyntax-only" 60 source_file: "kythe/cxx/extractor/testdata/metadata.cc" 61 working_directory: "/root" 62 entry_context: "hash0" 63 )pb"); 64 } 65 66 TEST(CxxExtractorTest, TextMetadataExtraction) { 67 kythe::proto::CompilationUnit unit = ExtractSingleCompilationOrDie({{ 68 "--with_executable", 69 "/dummy/bin/g++", 70 "-I./kythe/cxx/extractor", 71 "./kythe/cxx/extractor/testdata/metadata.cc", 72 }}); 73 CanonicalizeHashes(&unit); 74 unit.clear_details(); 75 unit.set_argument(2, "dummy-target"); 76 77 EXPECT_THAT(unit, EquivToProto(ExpectedCompilation())); 78 } 79 } // namespace 80 } // namespace kythe