diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-09 19:22:32 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-09 19:22:32 +0000 |
commit | ae2de79ce245a2bac0c19e905a78ba7fa923820c (patch) | |
tree | c4843a9f27eba7cb915b356ae60f67eb8f4d8aff /unittests | |
parent | ce2bd42c852d229fa07ff64b85d0715cc7a24d33 (diff) |
Add #pragma clang module build/endbuild pragmas for performing a module build
as part of a compilation.
This is intended for two purposes:
1) Writing self-contained test cases for modules: we can now write a single
source file test that builds some number of module files on the side and
imports them.
2) Debugging / test case reduction. A single-source testcase is much more
amenable to reduction, compared to a VFS tarball or .pcm files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305101 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Basic/SourceManagerTest.cpp | 24 | ||||
-rw-r--r-- | unittests/Lex/LexerTest.cpp | 20 | ||||
-rw-r--r-- | unittests/Lex/PPCallbacksTest.cpp | 23 | ||||
-rw-r--r-- | unittests/Lex/PPConditionalDirectiveRecordTest.cpp | 20 |
4 files changed, 7 insertions, 80 deletions
diff --git a/unittests/Basic/SourceManagerTest.cpp b/unittests/Basic/SourceManagerTest.cpp index aa15e16b85..8457d3b639 100644 --- a/unittests/Basic/SourceManagerTest.cpp +++ b/unittests/Basic/SourceManagerTest.cpp @@ -51,24 +51,6 @@ protected: IntrusiveRefCntPtr<TargetInfo> Target; }; -class VoidModuleLoader : public ModuleLoader { - ModuleLoadResult loadModule(SourceLocation ImportLoc, - ModuleIdPath Path, - Module::NameVisibilityKind Visibility, - bool IsInclusionDirective) override { - return ModuleLoadResult(); - } - - void makeModuleVisible(Module *Mod, - Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc) override { } - - GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override - { return nullptr; } - bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override - { return 0; } -}; - TEST_F(SourceManagerTest, isBeforeInTranslationUnit) { const char *source = "#define M(x) [x]\n" @@ -78,7 +60,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) { FileID mainFileID = SourceMgr.createFileID(std::move(Buf)); SourceMgr.setMainFileID(mainFileID); - VoidModuleLoader ModLoader; + TrivialModuleLoader ModLoader; MemoryBufferCache PCMCache; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, Diags, LangOpts, &*Target); @@ -199,7 +181,7 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) { HeaderBuf->getBufferSize(), 0); SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf)); - VoidModuleLoader ModLoader; + TrivialModuleLoader ModLoader; MemoryBufferCache PCMCache; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, Diags, LangOpts, &*Target); @@ -318,7 +300,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) { HeaderBuf->getBufferSize(), 0); SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf)); - VoidModuleLoader ModLoader; + TrivialModuleLoader ModLoader; MemoryBufferCache PCMCache; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, Diags, LangOpts, &*Target); diff --git a/unittests/Lex/LexerTest.cpp b/unittests/Lex/LexerTest.cpp index b5a6fd90d0..e2507d3580 100644 --- a/unittests/Lex/LexerTest.cpp +++ b/unittests/Lex/LexerTest.cpp @@ -27,24 +27,6 @@ using namespace clang; namespace { -class VoidModuleLoader : public ModuleLoader { - ModuleLoadResult loadModule(SourceLocation ImportLoc, - ModuleIdPath Path, - Module::NameVisibilityKind Visibility, - bool IsInclusionDirective) override { - return ModuleLoadResult(); - } - - void makeModuleVisible(Module *Mod, - Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc) override { } - - GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override - { return nullptr; } - bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override - { return 0; } -}; - // The test fixture. class LexerTest : public ::testing::Test { protected: @@ -64,7 +46,7 @@ protected: llvm::MemoryBuffer::getMemBuffer(Source); SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf))); - VoidModuleLoader ModLoader; + TrivialModuleLoader ModLoader; MemoryBufferCache PCMCache; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, Diags, LangOpts, Target.get()); diff --git a/unittests/Lex/PPCallbacksTest.cpp b/unittests/Lex/PPCallbacksTest.cpp index 0841791e08..67b56a601c 100644 --- a/unittests/Lex/PPCallbacksTest.cpp +++ b/unittests/Lex/PPCallbacksTest.cpp @@ -32,25 +32,6 @@ using namespace clang; namespace { -// Stub out module loading. -class VoidModuleLoader : public ModuleLoader { - ModuleLoadResult loadModule(SourceLocation ImportLoc, - ModuleIdPath Path, - Module::NameVisibilityKind Visibility, - bool IsInclusionDirective) override { - return ModuleLoadResult(); - } - - void makeModuleVisible(Module *Mod, - Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc) override { } - - GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override - { return nullptr; } - bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override - { return 0; } -}; - // Stub to collect data from InclusionDirective callbacks. class InclusionDirectiveCallbacks : public PPCallbacks { public: @@ -161,7 +142,7 @@ protected: llvm::MemoryBuffer::getMemBuffer(SourceText); SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf))); - VoidModuleLoader ModLoader; + TrivialModuleLoader ModLoader; MemoryBufferCache PCMCache; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, @@ -199,7 +180,7 @@ protected: llvm::MemoryBuffer::getMemBuffer(SourceText, "test.cl"); SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(SourceBuf))); - VoidModuleLoader ModLoader; + TrivialModuleLoader ModLoader; MemoryBufferCache PCMCache; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, Diags, OpenCLLangOpts, Target.get()); diff --git a/unittests/Lex/PPConditionalDirectiveRecordTest.cpp b/unittests/Lex/PPConditionalDirectiveRecordTest.cpp index b635604e09..f7b6f717a1 100644 --- a/unittests/Lex/PPConditionalDirectiveRecordTest.cpp +++ b/unittests/Lex/PPConditionalDirectiveRecordTest.cpp @@ -51,24 +51,6 @@ protected: IntrusiveRefCntPtr<TargetInfo> Target; }; -class VoidModuleLoader : public ModuleLoader { - ModuleLoadResult loadModule(SourceLocation ImportLoc, - ModuleIdPath Path, - Module::NameVisibilityKind Visibility, - bool IsInclusionDirective) override { - return ModuleLoadResult(); - } - - void makeModuleVisible(Module *Mod, - Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc) override { } - - GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override - { return nullptr; } - bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override - { return 0; } -}; - TEST_F(PPConditionalDirectiveRecordTest, PPRecAPI) { const char *source = "0 1\n" @@ -93,7 +75,7 @@ TEST_F(PPConditionalDirectiveRecordTest, PPRecAPI) { llvm::MemoryBuffer::getMemBuffer(source); SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf))); - VoidModuleLoader ModLoader; + TrivialModuleLoader ModLoader; MemoryBufferCache PCMCache; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, Diags, LangOpts, Target.get()); |