diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-06-30 20:04:14 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-06-30 20:04:14 +0000 |
commit | f4f9e50a67171086e09ae051737e602e4f0171a9 (patch) | |
tree | 6c95fbbf0632efbe679ee05b2b7dcd95a937a258 /unittests/libclang | |
parent | 273bb34c380be738b1d003885d426c40e878ad5d (diff) |
Consider module depedencies when checking a preamble in libclang
Add module dependencies (header files, module map files) to the list of
files to check when deciding whether to rebuild a preamble. That fixes
using preambles with module imports so long as they are in
non-overridden files.
My intent is to use to unify the existing dependency collectors to the
new “DependencyCollectory” interface from this commit, starting with the
DependencyFileGenerator.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/libclang')
-rw-r--r-- | unittests/libclang/LibclangTest.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/unittests/libclang/LibclangTest.cpp b/unittests/libclang/LibclangTest.cpp index f0bfb27585..8f2694fb49 100644 --- a/unittests/libclang/LibclangTest.cpp +++ b/unittests/libclang/LibclangTest.cpp @@ -340,9 +340,9 @@ TEST(libclang, ModuleMapDescriptor) { } class LibclangReparseTest : public ::testing::Test { - std::string TestDir; std::set<std::string> Files; public: + std::string TestDir; CXIndex Index; CXTranslationUnit ClangTU; unsigned TUFlags; @@ -420,3 +420,36 @@ TEST_F(LibclangReparseTest, Reparse) { ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU)); } + +TEST_F(LibclangReparseTest, ReparseWithModule) { + const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;"; + const char *HeaderBottom = "\n};\n#endif\n"; + const char *MFile = "#include \"HeaderFile.h\"\nint main() {" + " struct Foo foo; foo.bar = 7; foo.baz = 8; }\n"; + const char *ModFile = "module A { header \"HeaderFile.h\" }\n"; + std::string HeaderName = "HeaderFile.h"; + std::string MName = "MFile.m"; + std::string ModName = "module.modulemap"; + WriteFile(MName, MFile); + WriteFile(HeaderName, std::string(HeaderTop) + HeaderBottom); + WriteFile(ModName, ModFile); + + const char *Args[] = { "-fmodules", "-I", TestDir.c_str() }; + int NumArgs = sizeof(Args) / sizeof(Args[0]); + ClangTU = clang_parseTranslationUnit(Index, MName.c_str(), Args, NumArgs, + nullptr, 0, TUFlags); + EXPECT_EQ(1U, clang_getNumDiagnostics(ClangTU)); + DisplayDiagnostics(); + + // Immedaitely reparse. + ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); + EXPECT_EQ(1U, clang_getNumDiagnostics(ClangTU)); + + std::string NewHeaderContents = + std::string(HeaderTop) + "int baz;" + HeaderBottom; + WriteFile(HeaderName, NewHeaderContents); + + // Reparse after fix. + ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); + EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU)); +} |