|
19 | 19 | #include "clang/Driver/Driver.h"
|
20 | 20 | #include "clang/Frontend/CompilerInstance.h"
|
21 | 21 | #include "llvm/ADT/ArrayRef.h"
|
| 22 | +#include "llvm/ADT/StringExtras.h" |
22 | 23 | #include "llvm/MC/TargetRegistry.h"
|
23 | 24 | #include "llvm/Support/TargetSelect.h"
|
24 | 25 | #include "llvm/Support/VirtualFileSystem.h"
|
25 | 26 | #include "llvm/Support/raw_ostream.h"
|
| 27 | +#include "gmock/gmock.h" |
26 | 28 | #include "gtest/gtest.h"
|
27 | 29 | #include <memory>
|
28 | 30 |
|
@@ -316,6 +318,52 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
|
316 | 318 | }
|
317 | 319 | }
|
318 | 320 |
|
| 321 | +MATCHER_P(jobHasArgs, Substr, "") { |
| 322 | + const driver::Command &C = arg; |
| 323 | + std::string Args = ""; |
| 324 | + llvm::ListSeparator Sep(" "); |
| 325 | + for (const char *Arg : C.getArguments()) { |
| 326 | + Args += Sep; |
| 327 | + Args += Arg; |
| 328 | + } |
| 329 | + if (is_style_windows(llvm::sys::path::Style::native)) |
| 330 | + std::replace(Args.begin(), Args.end(), '\\', '/'); |
| 331 | + if (llvm::StringRef(Args).contains(Substr)) |
| 332 | + return true; |
| 333 | + *result_listener << "whose args are '" << Args << "'"; |
| 334 | + return false; |
| 335 | +} |
| 336 | + |
| 337 | +TEST(ToolChainTest, VFSGnuLibcxxPathNoSysroot) { |
| 338 | + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); |
| 339 | + |
| 340 | + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); |
| 341 | + struct TestDiagnosticConsumer : public DiagnosticConsumer {}; |
| 342 | + IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( |
| 343 | + new llvm::vfs::InMemoryFileSystem); |
| 344 | + |
| 345 | + const char *EmptyFiles[] = { |
| 346 | + "foo.cpp", |
| 347 | + "/bin/clang", |
| 348 | + "/usr/include/c++/v1/cstdio", |
| 349 | + }; |
| 350 | + |
| 351 | + for (const char *Path : EmptyFiles) |
| 352 | + InMemoryFileSystem->addFile(Path, 0, |
| 353 | + llvm::MemoryBuffer::getMemBuffer("\n")); |
| 354 | + |
| 355 | + { |
| 356 | + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); |
| 357 | + Driver TheDriver("/bin/clang", "x86_64-unknown-linux-gnu", Diags, |
| 358 | + "clang LLVM compiler", InMemoryFileSystem); |
| 359 | + std::unique_ptr<Compilation> C(TheDriver.BuildCompilation( |
| 360 | + {"/bin/clang", "-fsyntax-only", "-stdlib=libc++", "foo.cpp"})); |
| 361 | + ASSERT_TRUE(C); |
| 362 | + EXPECT_THAT(C->getJobs(), testing::ElementsAre(jobHasArgs( |
| 363 | + "-internal-isystem /usr/include/c++/v1"))); |
| 364 | + } |
| 365 | +} |
| 366 | + |
319 | 367 | TEST(ToolChainTest, DefaultDriverMode) {
|
320 | 368 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
321 | 369 |
|
|
0 commit comments