|
10 | 10 | #include "clang/CodeGen/BackendUtil.h"
|
11 | 11 | #include "clang/CodeGen/CodeGenAction.h"
|
12 | 12 | #include "clang/Frontend/CompilerInstance.h"
|
| 13 | +#include "clang/Frontend/TextDiagnosticPrinter.h" |
13 | 14 | #include "clang/FrontendTool/Utils.h"
|
14 | 15 | #include "clang/Lex/PreprocessorOptions.h"
|
15 | 16 | #include "gtest/gtest.h"
|
@@ -43,4 +44,58 @@ TEST(FrontendOutputTests, TestOutputStream) {
|
43 | 44 | EXPECT_TRUE(!IRBuffer.empty());
|
44 | 45 | EXPECT_TRUE(StringRef(IRBuffer.data()).startswith("BC"));
|
45 | 46 | }
|
| 47 | + |
| 48 | +TEST(FrontendOutputTests, TestVerboseOutputStreamShared) { |
| 49 | + auto Invocation = std::make_shared<CompilerInvocation>(); |
| 50 | + Invocation->getPreprocessorOpts().addRemappedFile( |
| 51 | + "test.cc", MemoryBuffer::getMemBuffer("invalid").release()); |
| 52 | + Invocation->getFrontendOpts().Inputs.push_back( |
| 53 | + FrontendInputFile("test.cc", Language::CXX)); |
| 54 | + Invocation->getFrontendOpts().ProgramAction = EmitBC; |
| 55 | + Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; |
| 56 | + CompilerInstance Compiler; |
| 57 | + |
| 58 | + std::string VerboseBuffer; |
| 59 | + raw_string_ostream VerboseStream(VerboseBuffer); |
| 60 | + |
| 61 | + Compiler.setInvocation(std::move(Invocation)); |
| 62 | + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); |
| 63 | + Compiler.createDiagnostics( |
| 64 | + new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true); |
| 65 | + Compiler.setVerboseOutputStream(VerboseStream); |
| 66 | + |
| 67 | + bool Success = ExecuteCompilerInvocation(&Compiler); |
| 68 | + EXPECT_FALSE(Success); |
| 69 | + EXPECT_TRUE(!VerboseStream.str().empty()); |
| 70 | + EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated")); |
| 71 | +} |
| 72 | + |
| 73 | +TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) { |
| 74 | + std::string VerboseBuffer; |
| 75 | + bool Success; |
| 76 | + { |
| 77 | + auto Invocation = std::make_shared<CompilerInvocation>(); |
| 78 | + Invocation->getPreprocessorOpts().addRemappedFile( |
| 79 | + "test.cc", MemoryBuffer::getMemBuffer("invalid").release()); |
| 80 | + Invocation->getFrontendOpts().Inputs.push_back( |
| 81 | + FrontendInputFile("test.cc", Language::CXX)); |
| 82 | + Invocation->getFrontendOpts().ProgramAction = EmitBC; |
| 83 | + Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; |
| 84 | + CompilerInstance Compiler; |
| 85 | + |
| 86 | + std::unique_ptr<raw_ostream> VerboseStream = |
| 87 | + std::make_unique<raw_string_ostream>(VerboseBuffer); |
| 88 | + |
| 89 | + Compiler.setInvocation(std::move(Invocation)); |
| 90 | + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); |
| 91 | + Compiler.createDiagnostics( |
| 92 | + new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true); |
| 93 | + Compiler.setVerboseOutputStream(std::move(VerboseStream)); |
| 94 | + |
| 95 | + Success = ExecuteCompilerInvocation(&Compiler); |
| 96 | + } |
| 97 | + EXPECT_FALSE(Success); |
| 98 | + EXPECT_TRUE(!VerboseBuffer.empty()); |
| 99 | + EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated")); |
| 100 | +} |
46 | 101 | }
|
0 commit comments