[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
//===-- CompileCommandsTests.cpp ------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CompileCommands.h"
|
2019-12-06 19:27:15 +08:00
|
|
|
#include "TestFS.h"
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ::testing::Contains;
|
|
|
|
using ::testing::ElementsAre;
|
|
|
|
using ::testing::HasSubstr;
|
|
|
|
using ::testing::Not;
|
|
|
|
|
|
|
|
// Sadly, CommandMangler::detect(), which contains much of the logic, is
|
|
|
|
// a bunch of untested integration glue. We test the string manipulation here
|
|
|
|
// assuming its results are correct.
|
|
|
|
|
|
|
|
// Make use of all features and assert the exact command we get out.
|
|
|
|
// Other tests just verify presence/absence of certain args.
|
|
|
|
TEST(CommandMangler, Everything) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
2019-12-06 19:27:15 +08:00
|
|
|
Mangler.ClangPath = testPath("fake/clang");
|
|
|
|
Mangler.ResourceDir = testPath("fake/resources");
|
|
|
|
Mangler.Sysroot = testPath("fake/sysroot");
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
std::vector<std::string> Cmd = {"clang++", "-Xclang", "-load", "-Xclang",
|
|
|
|
"plugin", "-MF", "dep", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
2019-12-06 19:27:15 +08:00
|
|
|
EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "foo.cc",
|
|
|
|
"-fsyntax-only",
|
|
|
|
"-resource-dir=" + testPath("fake/resources"),
|
|
|
|
"-isysroot", testPath("fake/sysroot")));
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CommandMangler, ResourceDir) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
2019-12-06 19:27:15 +08:00
|
|
|
Mangler.ResourceDir = testPath("fake/resources");
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
std::vector<std::string> Cmd = {"clang++", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
2019-12-06 19:27:15 +08:00
|
|
|
EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CommandMangler, Sysroot) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
2019-12-06 19:27:15 +08:00
|
|
|
Mangler.Sysroot = testPath("fake/sysroot");
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
|
|
|
|
std::vector<std::string> Cmd = {"clang++", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
2019-12-06 19:27:15 +08:00
|
|
|
EXPECT_THAT(llvm::join(Cmd, " "),
|
|
|
|
HasSubstr("-isysroot " + testPath("fake/sysroot")));
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CommandMangler, StripPlugins) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
|
|
|
std::vector<std::string> Cmd = {"clang++", "-Xclang", "-load",
|
|
|
|
"-Xclang", "plugin", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
|
|
|
for (const char* Stripped : {"-Xclang", "-load", "plugin"})
|
|
|
|
EXPECT_THAT(Cmd, Not(Contains(Stripped)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CommandMangler, StripOutput) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
|
|
|
std::vector<std::string> Cmd = {"clang++", "-MF", "dependency", "-c",
|
|
|
|
"foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
|
|
|
for (const char* Stripped : {"-MF", "dependency"})
|
|
|
|
EXPECT_THAT(Cmd, Not(Contains(Stripped)));
|
|
|
|
}
|
|
|
|
|
2020-04-25 07:08:36 +08:00
|
|
|
TEST(CommandMangler, StripShowIncludes) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
|
|
|
std::vector<std::string> Cmd = {"clang-cl", "/showIncludes", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
|
|
|
EXPECT_THAT(Cmd, Not(Contains("/showIncludes")));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CommandMangler, StripShowIncludesUser) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
|
|
|
std::vector<std::string> Cmd = {"clang-cl", "/showIncludes:user", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
|
|
|
EXPECT_THAT(Cmd, Not(Contains("/showIncludes:user")));
|
|
|
|
}
|
|
|
|
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
TEST(CommandMangler, ClangPath) {
|
|
|
|
auto Mangler = CommandMangler::forTests();
|
2019-12-06 19:27:15 +08:00
|
|
|
Mangler.ClangPath = testPath("fake/clang");
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
|
|
|
|
std::vector<std::string> Cmd = {"clang++", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
2019-12-06 19:27:15 +08:00
|
|
|
EXPECT_EQ(testPath("fake/clang++"), Cmd.front());
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
|
|
|
|
Cmd = {"unknown-binary", "foo.cc"};
|
|
|
|
Mangler.adjust(Cmd);
|
|
|
|
EXPECT_EQ("unknown-binary", Cmd.front());
|
|
|
|
|
2019-12-06 19:27:15 +08:00
|
|
|
Cmd = {testPath("path/clang++"), "foo.cc"};
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
Mangler.adjust(Cmd);
|
2019-12-06 19:27:15 +08:00
|
|
|
EXPECT_EQ(testPath("path/clang++"), Cmd.front());
|
[clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8fa169481fa367debf5ec615640635a1,
and reverted in 93f77617abba512d2861e2fc50ce385883f587b6.
This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178
Reviewers: kbobyrev, ilya-biryukov
Subscribers: mgorny, ormris, cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71029
2019-11-30 02:37:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|