diff options
author | Jordan Rupprecht <[email protected]> | 2019-05-14 21:58:59 +0000 |
---|---|---|
committer | Jordan Rupprecht <[email protected]> | 2019-05-14 21:58:59 +0000 |
commit | b35a2aa71f76a334a9c98c0a3c3995b5d902d2b9 (patch) | |
tree | cdff4a5d1a715d4ad622fd8f190128b54bebe440 /unittests/Tooling/CompilationDatabaseTest.cpp | |
parent | 3748d41833787fcbf59cc5624e8d2b042a8991bc (diff) | |
parent | 741e05796da92b46d4f7bcbee00702ff37df6489 (diff) |
Creating branches/google/stable and tags/google/stable/2019-05-14 from r360103upstream/google/stable
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/google/stable@360714 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r-- | unittests/Tooling/CompilationDatabaseTest.cpp | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp index 949d6a3b73..4e27df71d8 100644 --- a/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/unittests/Tooling/CompilationDatabaseTest.cpp @@ -1,9 +1,8 @@ //===- unittest/Tooling/CompilationDatabaseTest.cpp -----------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -89,12 +88,17 @@ TEST(JSONCompilationDatabase, GetAllFiles) { expected_files.push_back(PathStorage.str()); llvm::sys::path::native("//net/dir/file2", PathStorage); expected_files.push_back(PathStorage.str()); + llvm::sys::path::native("//net/file1", PathStorage); + expected_files.push_back(PathStorage.str()); EXPECT_EQ(expected_files, getAllFiles("[{\"directory\":\"//net/dir\"," "\"command\":\"command\"," "\"file\":\"file1\"}," " {\"directory\":\"//net/dir\"," "\"command\":\"command\"," + "\"file\":\"../file1\"}," + " {\"directory\":\"//net/dir\"," + "\"command\":\"command\"," "\"file\":\"file2\"}]", ErrorMessage, JSONCommandLineSyntax::Gnu)) << ErrorMessage; @@ -669,6 +673,27 @@ protected: return llvm::join(Results[0].CommandLine, " "); } + // Parse the file whose command was used out of the Heuristic string. + std::string getProxy(llvm::StringRef F) { + auto Results = + inferMissingCompileCommands(llvm::make_unique<MemCDB>(Entries)) + ->getCompileCommands(path(F)); + if (Results.empty()) + return "none"; + StringRef Proxy = Results.front().Heuristic; + if (!Proxy.consume_front("inferred from ")) + return ""; + // We have a proxy file, convert back to a unix relative path. + // This is a bit messy, but we do need to test these strings somehow... + llvm::SmallString<32> TempDir; + llvm::sys::path::system_temp_directory(false, TempDir); + Proxy.consume_front(TempDir); + Proxy.consume_front(llvm::sys::path::get_separator()); + llvm::SmallString<32> Result = Proxy; + llvm::sys::path::native(Result, llvm::sys::path::Style::posix); + return Result.str(); + } + MemCDB::EntryMap Entries; }; @@ -678,18 +703,16 @@ TEST_F(InterpolateTest, Nearby) { add("an/other/foo.cpp"); // great: dir and name both match (prefix or full, case insensitive) - EXPECT_EQ(getCommand("dir/f.cpp"), "clang -D dir/foo.cpp"); - EXPECT_EQ(getCommand("dir/FOO.cpp"), "clang -D dir/foo.cpp"); + EXPECT_EQ(getProxy("dir/f.cpp"), "dir/foo.cpp"); + EXPECT_EQ(getProxy("dir/FOO.cpp"), "dir/foo.cpp"); // no name match. prefer matching dir, break ties by alpha - EXPECT_EQ(getCommand("dir/a.cpp"), "clang -D dir/bar.cpp"); + EXPECT_EQ(getProxy("dir/a.cpp"), "dir/bar.cpp"); // an exact name match beats one segment of directory match - EXPECT_EQ(getCommand("some/other/bar.h"), - "clang -D dir/bar.cpp -x c++-header"); + EXPECT_EQ(getProxy("some/other/bar.h"), "dir/bar.cpp"); // two segments of directory match beat a prefix name match - EXPECT_EQ(getCommand("an/other/b.cpp"), "clang -D an/other/foo.cpp"); + EXPECT_EQ(getProxy("an/other/b.cpp"), "an/other/foo.cpp"); // if nothing matches at all, we still get the closest alpha match - EXPECT_EQ(getCommand("below/some/obscure/path.cpp"), - "clang -D an/other/foo.cpp"); + EXPECT_EQ(getProxy("below/some/obscure/path.cpp"), "an/other/foo.cpp"); } TEST_F(InterpolateTest, Language) { @@ -723,7 +746,7 @@ TEST_F(InterpolateTest, Case) { add("FOO/BAR/BAZ/SHOUT.cc"); add("foo/bar/baz/quiet.cc"); // Case mismatches are completely ignored, so we choose the name match. - EXPECT_EQ(getCommand("foo/bar/baz/shout.C"), "clang -D FOO/BAR/BAZ/SHOUT.cc"); + EXPECT_EQ(getProxy("foo/bar/baz/shout.C"), "FOO/BAR/BAZ/SHOUT.cc"); } TEST_F(InterpolateTest, Aliasing) { |