kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/testdata/installed_dir_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/installed_dir.cc" }
    33        info {
    34          path: "kythe/cxx/extractor/testdata/installed_dir.cc"
    35          digest: "fb21e5e71e3b8f54ebf5a84fc2955fb4f893111fdfa0d7fe8be936b32add3f56"
    36        }
    37        details {
    38          [type.googleapis.com/kythe.proto.ContextDependentVersion] {
    39            row {
    40              source_context: "hash0"
    41              always_process: true
    42              column { linked_context: "hash1" }
    43            }
    44          }
    45        }
    46      }
    47      required_input {
    48        v_name { path: "kythe/cxx/extractor/testdata/include/c++/v1/dummy" }
    49        info {
    50          # TODO(b/278254885): Properly normalize file paths.
    51          path: "kythe/cxx/extractor/testdata/include/c++/v1/dummy"
    52          digest: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
    53        }
    54        details {
    55          [type.googleapis.com/kythe.proto.ContextDependentVersion] {
    56            row { source_context: "hash1" }
    57          }
    58        }
    59      }
    60      argument: "kythe/cxx/extractor/testdata/bin/clang++"
    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: "-stdlib=libc++"
    68      argument: "-v"
    69      argument: "./kythe/cxx/extractor/testdata/installed_dir.cc"
    70      argument: "-fsyntax-only"
    71      source_file: "kythe/cxx/extractor/testdata/installed_dir.cc"
    72      working_directory: "/root"
    73      entry_context: "hash0"
    74    )pb");
    75  }
    76  
    77  TEST(CxxExtractorTest, TestInstalledClangExtraction) {
    78    kythe::proto::CompilationUnit unit = ExtractSingleCompilationOrDie({{
    79        "--with_executable",
    80        "kythe/cxx/extractor/testdata/bin/clang++",
    81        "-stdlib=libc++",
    82        "-E",
    83        "-v",  // On failure, dump the search path.
    84        "./kythe/cxx/extractor/testdata/installed_dir.cc",
    85    }});
    86    CanonicalizeHashes(&unit);
    87    unit.set_argument(2, "dummy-target");
    88    unit.clear_details();
    89  
    90    EXPECT_THAT(unit, EquivToProto(ExpectedCompilation()));
    91  }
    92  
    93  }  // namespace
    94  }  // namespace kythe