[clang-tools-extra] 6b11760 - [clangd] Try to fix CompileCommandsTests on windows. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 6 03:28:11 PST 2019


Author: Sam McCall
Date: 2019-12-06T12:28:01+01:00
New Revision: 6b11760128751455a73d9f00a5f935d1f49fbd0f

URL: https://github.com/llvm/llvm-project/commit/6b11760128751455a73d9f00a5f935d1f49fbd0f
DIFF: https://github.com/llvm/llvm-project/commit/6b11760128751455a73d9f00a5f935d1f49fbd0f.diff

LOG: [clangd] Try to fix CompileCommandsTests on windows. NFC

Added: 
    

Modified: 
    clang-tools-extra/clangd/CompileCommands.h
    clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/CompileCommands.h b/clang-tools-extra/clangd/CompileCommands.h
index b0c34b883644..02b1a76c5bff 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -5,6 +5,8 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILECOMMANDS_H
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -46,3 +48,5 @@ struct CommandMangler {
 
 } // namespace clangd
 } // namespace clang
+
+#endif

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index e16a8ac94df0..fc98b56de2d6 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CompileCommands.h"
+#include "TestFS.h"
 
 #include "llvm/ADT/StringExtras.h"
 
@@ -30,32 +31,34 @@ using ::testing::Not;
 // Other tests just verify presence/absence of certain args.
 TEST(CommandMangler, Everything) {
   auto Mangler = CommandMangler::forTests();
-  Mangler.ClangPath = "/fake/bin/clang";
-  Mangler.ResourceDir = "/fake/resources";
-  Mangler.Sysroot = "/fake/sysroot";
+  Mangler.ClangPath = testPath("fake/clang");
+  Mangler.ResourceDir = testPath("fake/resources");
+  Mangler.Sysroot = testPath("fake/sysroot");
   std::vector<std::string> Cmd = {"clang++", "-Xclang", "-load", "-Xclang",
                                   "plugin",  "-MF",     "dep",   "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, ElementsAre("/fake/bin/clang++", "foo.cc", "-fsyntax-only",
-                               "-resource-dir=/fake/resources", "-isysroot",
-                               "/fake/sysroot"));
+  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "foo.cc",
+                               "-fsyntax-only",
+                               "-resource-dir=" + testPath("fake/resources"),
+                               "-isysroot", testPath("fake/sysroot")));
 }
 
 TEST(CommandMangler, ResourceDir) {
   auto Mangler = CommandMangler::forTests();
-  Mangler.ResourceDir = "/fake/resources";
+  Mangler.ResourceDir = testPath("fake/resources");
   std::vector<std::string> Cmd = {"clang++", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, Contains("-resource-dir=/fake/resources"));
+  EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
 }
 
 TEST(CommandMangler, Sysroot) {
   auto Mangler = CommandMangler::forTests();
-  Mangler.Sysroot = "/fake/sysroot";
+  Mangler.Sysroot = testPath("fake/sysroot");
 
   std::vector<std::string> Cmd = {"clang++", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(llvm::join(Cmd, " "), HasSubstr("-isysroot /fake/sysroot"));
+  EXPECT_THAT(llvm::join(Cmd, " "),
+              HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
 
 TEST(CommandMangler, StripPlugins) {
@@ -78,19 +81,19 @@ TEST(CommandMangler, StripOutput) {
 
 TEST(CommandMangler, ClangPath) {
   auto Mangler = CommandMangler::forTests();
-  Mangler.ClangPath = "/fake/clang";
+  Mangler.ClangPath = testPath("fake/clang");
 
   std::vector<std::string> Cmd = {"clang++", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_EQ("/fake/clang++", Cmd.front());
+  EXPECT_EQ(testPath("fake/clang++"), Cmd.front());
 
   Cmd = {"unknown-binary", "foo.cc"};
   Mangler.adjust(Cmd);
   EXPECT_EQ("unknown-binary", Cmd.front());
 
-  Cmd = {"/path/clang++", "foo.cc"};
+  Cmd = {testPath("path/clang++"), "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_EQ("/path/clang++", Cmd.front());
+  EXPECT_EQ(testPath("path/clang++"), Cmd.front());
 }
 
 } // namespace


        


More information about the cfe-commits mailing list