From 33c8090a2f7f2e6d554f84a15a573a7ff7d3f59d Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Mon, 30 Jun 2014 20:04:14 +0000 Subject: Consider module depedencies when checking a preamble in libclang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. llvm-svn: 212060 --- clang/unittests/libclang/LibclangTest.cpp | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'clang/unittests/libclang/LibclangTest.cpp') diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp index f0bfb27..8f2694f 100644 --- a/clang/unittests/libclang/LibclangTest.cpp +++ b/clang/unittests/libclang/LibclangTest.cpp @@ -340,9 +340,9 @@ TEST(libclang, ModuleMapDescriptor) { } class LibclangReparseTest : public ::testing::Test { - std::string TestDir; std::set 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)); +} -- cgit v1.1