kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/testdata/header_only_module_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 ::kythe::proto::CompilationUnit;
    27  using ::protobuf_matchers::EquivToProto;
    28  
    29  proto::CompilationUnit ExpectedCompilation() {
    30    return ParseTextCompilationUnitOrDie(R"pb(
    31      v_name { language: "c++" }
    32      required_input {
    33        v_name { path: "kythe/cxx/extractor/testdata/header_only_module.h" }
    34        info {
    35          path: "kythe/cxx/extractor/testdata/header_only_module.h"
    36          digest: "1c1216acd9ba7e73f6e66b5174c9445b191ccefa3fc3a3df3c20cbd931755ca7"
    37        }
    38        details {
    39          [type.googleapis.com/kythe.proto.ContextDependentVersion] {
    40            row { source_context: "hash1" always_process: false }
    41          }
    42        }
    43      }
    44      argument: "/dummy/bin/clang"
    45      argument: "-target"
    46      argument: "dummy-target"
    47      argument: "-DKYTHE_IS_RUNNING=1"
    48      argument: "-resource-dir"
    49      argument: "/kythe_builtins"
    50      argument: "-I./kythe/cxx/extractor/testdata"
    51      argument: "-xc++"
    52      argument: "-Xclang=-emit-module"
    53      argument: "-Xclang=-fmodules-embed-all-files"
    54      argument: "-Xclang=-fmodules-local-submodule-visibility"
    55      argument: "-fmodules"
    56      argument: "-fmodule-file-deps"
    57      argument: "-fno-implicit-modules"
    58      argument: "-fno-implicit-module-maps"
    59      argument: "-fmodules-strict-decluse"
    60      argument: "-fmodule-name=//kythe/cxx/extractor/testdata:header_only_module"
    61      argument: "-fmodule-map-file=./kythe/cxx/extractor/testdata/header_only_module.cppmap"
    62      argument: "-Xclang=-fmodule-map-file-home-is-cwd"
    63      argument: "-fPIE"
    64      argument: "-fPIC"
    65      argument: "-fsyntax-only"
    66      argument: "./kythe/cxx/extractor/testdata/header_only_module.cppmap"
    67      argument: "-o"
    68      argument: "header_only_module.pic.pcm"
    69      source_file: "kythe/cxx/extractor/testdata/header_only_module.cppmap"
    70      working_directory: "/root"
    71      entry_context: "hash0"
    72      output_key: "header_only_module.pic.pcm"
    73    )pb");
    74  }
    75  
    76  TEST(CxxExtractorTest, TestHeaderOnlyModule) {
    77    CompilationUnit unit = ExtractSingleCompilationOrDie(
    78        {{"--with_executable",
    79          "/dummy/bin/clang",
    80          "-I./kythe/cxx/extractor/testdata",
    81          "-xc++",
    82          "-Xclang=-emit-module",
    83          "-Xclang=-fmodules-embed-all-files",
    84          "-Xclang=-fmodules-local-submodule-visibility",
    85          "-fmodules",
    86          "-fmodule-file-deps",
    87          "-fno-implicit-modules",
    88          "-fno-implicit-module-maps",
    89          "-fmodules-strict-decluse",
    90          "-fmodule-name=//kythe/cxx/extractor/testdata:header_only_module",
    91          "-fmodule-map-file=./kythe/cxx/extractor/testdata/"
    92          "header_only_module.cppmap",
    93          "-Xclang=-fmodule-map-file-home-is-cwd",
    94          "-fPIE",
    95          "-fPIC",
    96          "-c",
    97          "./kythe/cxx/extractor/testdata/header_only_module.cppmap",
    98          "-o",
    99          "header_only_module.pic.pcm"}});
   100  
   101    // Fix up things which may legitmately vary between runs.
   102    // TODO(shahms): use gMock protobuf matchers when available.
   103    CanonicalizeHashes(&unit);
   104    unit.set_argument(2, "dummy-target");
   105    unit.clear_details();
   106  
   107    EXPECT_THAT(unit, EquivToProto(ExpectedCompilation()));
   108  }
   109  
   110  }  // namespace
   111  }  // namespace kythe