kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/testdata/modules_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/algorithm/container.h" 18 #include "absl/strings/match.h" 19 #include "absl/strings/str_cat.h" 20 #include "absl/strings/string_view.h" 21 #include "gmock/gmock.h" 22 #include "gtest/gtest.h" 23 #include "kythe/cxx/extractor/testlib.h" 24 #include "kythe/proto/analysis.pb.h" 25 #include "protobuf-matchers/protocol-buffer-matchers.h" 26 27 namespace kythe { 28 namespace { 29 using ::protobuf_matchers::EquivToProto; 30 31 proto::CompilationUnit ExpectedCompilation() { 32 return ParseTextCompilationUnitOrDie(R"pb( 33 v_name { language: "c++" } 34 required_input { 35 v_name { path: "kythe/cxx/extractor/testdata/modules.cc" } 36 info { 37 path: "kythe/cxx/extractor/testdata/modules.cc" 38 digest: "65f89e233c735e33c51ab2445b0586b102d03430d3ed177e021a33b1fffeac9f" 39 } 40 details { 41 [type.googleapis.com/kythe.proto.ContextDependentVersion] { 42 row { source_context: "hash0" always_process: true } 43 } 44 } 45 } 46 required_input { 47 v_name { path: "kythe/cxx/extractor/testdata/modfoo.h" } 48 info { 49 path: "kythe/cxx/extractor/testdata/modfoo.h" 50 digest: "cd8c82152d321ecfa60a7ab3ccec78ad7168abf22dd93150ccee7fea420ad432" 51 } 52 } 53 required_input { 54 v_name { path: "kythe/cxx/extractor/testdata/modfoo.modulemap" } 55 info { 56 path: "kythe/cxx/extractor/testdata/modfoo.modulemap" 57 digest: "94416d419ecab4bce80084ef89587c4ca31a3cabad12498bd98aa213b1dd5189" 58 } 59 } 60 argument: "/dummy/bin/g++" 61 argument: "-target" 62 argument: "dummy-target" 63 argument: "-DKYTHE_IS_RUNNING=1" 64 argument: "-resource-dir" 65 argument: "/kythe_builtins" 66 argument: "--driver-mode=g++" 67 argument: "-fmodules" 68 argument: "-fmodule-map-file=kythe/cxx/extractor/testdata/modfoo.modulemap" 69 argument: "-I./kythe/cxx/extractor" 70 argument: "./kythe/cxx/extractor/testdata/modules.cc" 71 argument: "-fsyntax-only" 72 source_file: "kythe/cxx/extractor/testdata/modules.cc" 73 working_directory: "/root" 74 entry_context: "hash0" 75 )pb"); 76 } 77 78 TEST(CxxExtractorTest, TestModulesExtraction) { 79 kythe::proto::CompilationUnit unit = ExtractSingleCompilationOrDie({{ 80 "--with_executable", 81 "/dummy/bin/g++", 82 "-fmodules", 83 "-fmodule-map-file=kythe/cxx/extractor/testdata/modfoo.modulemap", 84 absl::StrCat("-fmodules-cache-path=", testing::TempDir(), 85 "/module-cache"), 86 "-I./kythe/cxx/extractor", 87 "./kythe/cxx/extractor/testdata/modules.cc", 88 }}); 89 CanonicalizeHashes(&unit); 90 unit.set_argument(2, "dummy-target"); 91 unit.clear_details(); 92 unit.mutable_argument()->erase( 93 absl::c_find_if(unit.argument(), [](absl::string_view arg) { 94 return absl::StartsWith(arg, "-fmodules-cache-path="); 95 })); 96 97 EXPECT_THAT(unit, EquivToProto(ExpectedCompilation())); 98 } 99 100 } // namespace 101 } // namespace kythe