kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/testdata/indirect_has_include_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/indirect_has_include.cc" }
    33        info {
    34          path: "kythe/cxx/extractor/testdata/indirect_has_include.cc"
    35          digest: "6b406c26560e435ba485a141440055fc21c55492b41653003e13715292b7d76d"
    36        }
    37        details {
    38          [type.googleapis.com/kythe.proto.ContextDependentVersion] {
    39            row {
    40              source_context: "hash0"
    41              always_process: true
    42              column { offset: 35 linked_context: "hash1" }
    43            }
    44          }
    45        }
    46      }
    47      required_input {
    48        v_name { path: "kythe/cxx/extractor/testdata/has_include.h" }
    49        info {
    50          path: "kythe/cxx/extractor/testdata/has_include.h"
    51          digest: "ebebe3a0bf6fb1d21593bcf52d899124ea175ac04eae16a366ed0b9220ae0d06"
    52        }
    53        details {
    54          [type.googleapis.com/kythe.proto.ContextDependentVersion] {
    55            row { source_context: "hash2" }
    56          }
    57        }
    58      }
    59      required_input {
    60        v_name { path: "kythe/cxx/extractor/testdata/indirect_has_include.h" }
    61        info {
    62          path: "kythe/cxx/extractor/testdata/indirect_has_include.h"
    63          digest: "e92d9e48bed6844a99ebc827f38300af75762c2c2516b98dc560e680568a677a"
    64        }
    65        details {
    66          [type.googleapis.com/kythe.proto.ContextDependentVersion] {
    67            row {
    68              source_context: "hash1"
    69              column { linked_context: "hash2" }
    70            }
    71          }
    72        }
    73      }
    74      argument: "/dummy/bin/clang++"
    75      argument: "-target"
    76      argument: "dummy-target"
    77      argument: "-DKYTHE_IS_RUNNING=1"
    78      argument: "-resource-dir"
    79      argument: "/kythe_builtins"
    80      argument: "--driver-mode=g++"
    81      argument: "-I./kythe/cxx/extractor"
    82      argument: "./kythe/cxx/extractor/testdata/indirect_has_include.cc"
    83      argument: "-fsyntax-only"
    84      source_file: "kythe/cxx/extractor/testdata/indirect_has_include.cc"
    85      working_directory: "/root"
    86      entry_context: "hash0"
    87    )pb");
    88  }
    89  
    90  TEST(CxxExtractorTest, TextHasIncludeExtraction) {
    91    kythe::proto::CompilationUnit unit = ExtractSingleCompilationOrDie({{
    92        "--with_executable",
    93        "/dummy/bin/clang++",
    94        "-I./kythe/cxx/extractor",
    95        "./kythe/cxx/extractor/testdata/indirect_has_include.cc",
    96    }});
    97    CanonicalizeHashes(&unit);
    98    unit.clear_details();
    99    unit.set_argument(2, "dummy-target");
   100  
   101    EXPECT_THAT(unit, EquivToProto(ExpectedCompilation()));
   102  }
   103  
   104  }  // namespace
   105  }  // namespace kythe