summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/cpp11-migrate
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/unittests/cpp11-migrate')
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt31
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/FileOverridesTest.cpp187
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/IncludeDirectivesTest.cpp410
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp149
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/Makefile25
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/PerfSupportTest.cpp99
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp55
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/TransformTest.cpp326
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/UniqueHeaderNameTest.cpp58
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/Utility.h25
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/VirtualFileHelper.h81
11 files changed, 0 insertions, 1446 deletions
diff --git a/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt b/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt
deleted file mode 100644
index 8bcdf717f5c..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-set(LLVM_LINK_COMPONENTS
- support
- )
-
-get_filename_component(CPP11_MIGRATE_SOURCE_DIR
- ${CMAKE_CURRENT_SOURCE_DIR}/../../cpp11-migrate REALPATH)
-get_filename_component(ClangReplaceLocation
- "${CMAKE_CURRENT_SOURCE_DIR}/../../clang-apply-replacements/include" REALPATH)
-include_directories(
- ${CPP11_MIGRATE_SOURCE_DIR}
- ${ClangReplaceLocation}
- )
-
-add_extra_unittest(Cpp11MigrateTests
- FileOverridesTest.cpp
- ReformattingTest.cpp
- IncludeExcludeTest.cpp
- PerfSupportTest.cpp
- TransformTest.cpp
- UniqueHeaderNameTest.cpp
- IncludeDirectivesTest.cpp
- )
-
-target_link_libraries(Cpp11MigrateTests
- migrateCore
- clangFormat
- clangTooling
- clangBasic
- clangASTMatchers
- clangRewriteFrontend
- )
diff --git a/clang-tools-extra/unittests/cpp11-migrate/FileOverridesTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/FileOverridesTest.cpp
deleted file mode 100644
index 5404aeb579d..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/FileOverridesTest.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-//===- cpp11-migrate/FileOverridesTest.cpp - File overrides unit tests ----===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Core/FileOverrides.h"
-#include "Core/Refactoring.h"
-#include "gtest/gtest.h"
-#include "VirtualFileHelper.h"
-#include "clang/Rewrite/Core/Rewriter.h"
-
-using namespace clang;
-using namespace clang::tooling;
-
-static Replacement makeReplacement(unsigned Offset, unsigned Length,
- unsigned ReplacementLength,
- llvm::StringRef FilePath) {
- return Replacement(FilePath, Offset, Length,
- std::string(ReplacementLength, '~'));
-}
-
-// generate a set of replacements containing one element
-static ReplacementsVec makeReplacements(unsigned Offset, unsigned Length,
- unsigned ReplacementLength,
- llvm::StringRef FilePath = "~") {
- ReplacementsVec Replaces;
- Replaces.push_back(
- makeReplacement(Offset, Length, ReplacementLength, FilePath));
- return Replaces;
-}
-
-static bool equalRanges(Range A, Range B) {
- return A.getOffset() == B.getOffset() && A.getLength() == B.getLength();
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesShrink) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(0, 0, 4));
- EXPECT_NE(Changes.begin(), Changes.end());
- EXPECT_TRUE(equalRanges(Range(0, 4), *Changes.begin()));
- // create a replacement that cuts the end of the last insertion
- Changes.adjustChangedRanges(makeReplacements(2, 4, 0));
- Range ExpectedChanges[] = { Range(0, 2) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesExtend) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(1, 0, 4));
- // cut the old one by a bigger one
- Changes.adjustChangedRanges(makeReplacements(3, 4, 6));
- Range ExpectedChanges[] = { Range(1, 8) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesNoOverlap) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(0, 0, 4));
- Changes.adjustChangedRanges(makeReplacements(6, 0, 4));
- Range ExpectedChanges[] = { Range(0, 4), Range(6, 4) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesNullRange) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(0, 4, 0));
- Range ExpectedChanges[] = { Range(0, 0) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesExtendExisting) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(0, 0, 3));
- Changes.adjustChangedRanges(makeReplacements(2, 5, 8));
- Range ExpectedChanges[] = { Range(0, 10) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesSplit) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(0, 0, 3));
- Changes.adjustChangedRanges(makeReplacements(1, 1, 0));
- Range ExpectedChanges[] = { Range(0, 2) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesRangeContained) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(3, 0, 2));
- Changes.adjustChangedRanges(makeReplacements(1, 4, 5));
- Range ExpectedChanges[] = { Range(1, 5) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(ChangedRangesTest, adjustChangedRangesRangeResized) {
- ChangedRanges Changes;
- Changes.adjustChangedRanges(makeReplacements(2, 0, 5));
- // first make the range bigger
- Changes.adjustChangedRanges(makeReplacements(4, 1, 3));
- Range ExpectedChanges[] = { Range(2, 7) };
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
- // then smaller
- Changes.adjustChangedRanges(makeReplacements(3, 3, 1));
- ExpectedChanges[0] = Range(2, 5);
- EXPECT_TRUE(
- std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
-}
-
-TEST(FileOverridesTest, applyOverrides) {
-
- // Set up initial state
- VirtualFileHelper VFHelper;
-
- SmallString<128> fileAPath("fileA.cpp");
- ASSERT_FALSE(llvm::sys::fs::make_absolute(fileAPath));
- SmallString<128> fileBPath("fileB.cpp");
- ASSERT_FALSE(llvm::sys::fs::make_absolute(fileBPath));
- VFHelper.mapFile(fileAPath, "Content A");
- VFHelper.mapFile(fileBPath, "Content B");
- SourceManager &SM = VFHelper.getNewSourceManager();
-
- // Fill a Rewriter with changes
- Rewriter Rewrites(SM, LangOptions());
- ReplacementsVec R(1, Replacement(fileAPath, 0, 7, "Stuff"));
- ASSERT_TRUE(applyAllReplacements(R, Rewrites));
-
- FileOverrides Overrides;
- Overrides.updateState(Rewrites);
-
- const FileOverrides::FileStateMap &State = Overrides.getState();
-
- // Ensure state updated
- ASSERT_TRUE(State.end() == State.find(fileBPath));
- ASSERT_TRUE(State.begin() == State.find(fileAPath));
- ASSERT_EQ("Stuff A", State.begin()->getValue());
-
- Overrides.applyOverrides(SM);
-
- const FileEntry *EntryA = SM.getFileManager().getFile(fileAPath);
- FileID IdA = SM.translateFile(EntryA);
- ASSERT_FALSE(IdA.isInvalid());
-
- // Ensure the contents of the buffer matches what we'd expect.
- const llvm::MemoryBuffer *BufferA = SM.getBuffer(IdA);
- ASSERT_FALSE(0 == BufferA);
- ASSERT_EQ("Stuff A", BufferA->getBuffer());
-}
-
-TEST(FileOverridesTest, adjustChangedRanges) {
- SmallString<128> fileAPath("fileA.cpp");
- ASSERT_FALSE(llvm::sys::fs::make_absolute(fileAPath));
- SmallString<128> fileBPath("fileB.cpp");
- ASSERT_FALSE(llvm::sys::fs::make_absolute(fileBPath));
-
- replace::FileToReplacementsMap GroupedReplacements;
- GroupedReplacements[fileAPath] = makeReplacements(0, 5, 4, fileAPath);
- GroupedReplacements[fileBPath] = makeReplacements(10, 0, 6, fileBPath);
-
- FileOverrides Overrides;
-
- const FileOverrides::ChangeMap &Map = Overrides.getChangedRanges();
-
- ASSERT_TRUE(Map.empty());
-
- Overrides.adjustChangedRanges(GroupedReplacements);
-
- ASSERT_TRUE(Map.end() != Map.find(fileAPath));
- ASSERT_TRUE(Map.end() != Map.find(fileBPath));
- const Range &RA = *Map.find(fileAPath)->second.begin();
- EXPECT_EQ(0u, RA.getOffset());
- EXPECT_EQ(4u, RA.getLength());
- const Range &RB = *Map.find(fileBPath)->second.begin();
- EXPECT_EQ(10u, RB.getOffset());
- EXPECT_EQ(6u, RB.getLength());
-}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/IncludeDirectivesTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/IncludeDirectivesTest.cpp
deleted file mode 100644
index f56ee7fd3f1..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/IncludeDirectivesTest.cpp
+++ /dev/null
@@ -1,410 +0,0 @@
-//===- cpp11-migrate/IncludeDirectivesTest.cpp ----------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Core/IncludeDirectives.h"
-#include "gtest/gtest.h"
-#include "VirtualFileHelper.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendActions.h"
-#include "llvm/Support/Path.h"
-
-using namespace llvm;
-using namespace clang;
-
-/// \brief A convenience method around \c tooling::runToolOnCodeWithArgs() that
-/// adds the current directory to the include search paths.
-static void applyActionOnCode(FrontendAction *ToolAction, StringRef Code) {
- SmallString<128> CurrentDir;
- ASSERT_FALSE(llvm::sys::fs::current_path(CurrentDir));
-
- // Add the current directory to the header search paths so angled includes can
- // find them.
- std::vector<std::string> Args;
- Args.push_back("-I");
- Args.push_back(CurrentDir.str().str());
-
- // mapVirtualFile() needs absolute path for the input file as well.
- SmallString<128> InputFile(CurrentDir);
- sys::path::append(InputFile, "input.cc");
-
- ASSERT_TRUE(
- tooling::runToolOnCodeWithArgs(ToolAction, Code, Args, InputFile.str()));
-}
-
-namespace {
-class TestAddIncludeAction : public PreprocessOnlyAction {
-public:
- TestAddIncludeAction(StringRef Include, tooling::Replacements &Replaces,
- const char *HeaderToModify = 0)
- : Include(Include), Replaces(Replaces), HeaderToModify(HeaderToModify) {
- // some headers that the tests can include
- mapVirtualHeader("foo-inner.h", "#pragma once\n");
- mapVirtualHeader("foo.h", "#pragma once\n"
- "#include <foo-inner.h>\n");
- mapVirtualHeader("bar-inner.h", "#pragma once\n");
- mapVirtualHeader("bar.h", "#pragma once\n"
- "#include <bar-inner.h>\n");
- mapVirtualHeader("xmacro.def", "X(Val1)\n"
- "X(Val2)\n"
- "X(Val3)\n");
- }
-
- /// \brief Make \p FileName an absolute path.
- ///
- /// Header files are mapped in the current working directory. The current
- /// working directory is used because it's important to map files with
- /// absolute paths.
- ///
- /// When used in conjunction with \c applyActionOnCode() (which adds the
- /// current working directory to the header search paths) it is possible to
- /// refer to the headers by using '\<FileName\>'.
- std::string makeHeaderFileName(StringRef FileName) const {
- SmallString<128> Path;
- llvm::error_code EC = llvm::sys::fs::current_path(Path);
- assert(!EC);
- (void)EC;
-
- sys::path::append(Path, FileName);
- return Path.str().str();
- }
-
- /// \brief Map additional header files.
- ///
- /// \sa makeHeaderFileName()
- void mapVirtualHeader(StringRef FileName, StringRef Content) {
- VFHelper.mapFile(makeHeaderFileName(FileName), Content);
- }
-
-private:
- virtual bool BeginSourceFileAction(CompilerInstance &CI,
- StringRef FileName) LLVM_OVERRIDE {
- if (!PreprocessOnlyAction::BeginSourceFileAction(CI, FileName))
- return false;
- VFHelper.mapVirtualFiles(CI.getSourceManager());
-
- FileToModify =
- HeaderToModify ? makeHeaderFileName(HeaderToModify) : FileName.str();
-
- FileIncludes.reset(new IncludeDirectives(CI));
- return true;
- }
-
- virtual void EndSourceFileAction() LLVM_OVERRIDE {
- const tooling::Replacement &Replace =
- FileIncludes->addAngledInclude(FileToModify, Include);
- if (Replace.isApplicable())
- Replaces.insert(Replace);
- }
-
- StringRef Include;
- VirtualFileHelper VFHelper;
- tooling::Replacements &Replaces;
- OwningPtr<IncludeDirectives> FileIncludes;
- std::string FileToModify;
- // if non-null, add the include directives in this file instead of the main
- // file.
- const char *HeaderToModify;
-};
-
-std::string addIncludeInCode(StringRef Include, StringRef Code) {
- tooling::Replacements Replaces;
-
- applyActionOnCode(new TestAddIncludeAction(Include, Replaces), Code);
-
- if (::testing::Test::HasFailure())
- return "<<unexpected error from applyActionOnCode()>>";
-
- return tooling::applyAllReplacements(Code, Replaces);
-}
-} // end anonymous namespace
-
-TEST(IncludeDirectivesTest2, endOfLinesVariants) {
- EXPECT_EQ("#include <foo.h>\n"
- "#include <bar>\n",
- addIncludeInCode("bar", "#include <foo.h>\n"));
- EXPECT_EQ("#include <foo.h>\r\n"
- "#include <bar>\r\n",
- addIncludeInCode("bar", "#include <foo.h>\r\n"));
- EXPECT_EQ("#include <foo.h>\r"
- "#include <bar>\r",
- addIncludeInCode("bar", "#include <foo.h>\r"));
-}
-
-TEST(IncludeDirectivesTest, ppToken) {
- EXPECT_EQ("#define FOO <foo.h>\n"
- "#include FOO\n"
- "#include <bar>\n"
- "int i;\n",
- addIncludeInCode("bar", "#define FOO <foo.h>\n"
- "#include FOO\n"
- "int i;\n"));
-}
-
-TEST(IncludeDirectivesTest, noFileHeader) {
- EXPECT_EQ("#include <bar>\n"
- "\n"
- "int foo;\n",
- addIncludeInCode("bar", "int foo;\n"));
-}
-
-TEST(IncludeDirectivesTest, commentBeforeTopMostCode) {
- EXPECT_EQ("#include <bar>\n"
- "\n"
- "// Foo\n"
- "int foo;\n",
- addIncludeInCode("bar", "// Foo\n"
- "int foo;\n"));
-}
-
-TEST(IncludeDirectivesTest, multiLineComment) {
- EXPECT_EQ("#include <foo.h> /* \n */\n"
- "#include <bar>\n",
- addIncludeInCode("bar", "#include <foo.h> /* \n */\n"));
- EXPECT_EQ("#include <foo.h> /* \n */"
- "\n#include <bar>",
- addIncludeInCode("bar", "#include <foo.h> /* \n */"));
-}
-
-TEST(IncludeDirectivesTest, multilineCommentWithTrailingSpace) {
- EXPECT_EQ("#include <foo.h> /*\n*/ \n"
- "#include <bar>\n",
- addIncludeInCode("bar", "#include <foo.h> /*\n*/ \n"));
- EXPECT_EQ("#include <foo.h> /*\n*/ "
- "\n#include <bar>",
- addIncludeInCode("bar", "#include <foo.h> /*\n*/ "));
-}
-
-TEST(IncludeDirectivesTest, fileHeaders) {
- EXPECT_EQ("// this is a header\n"
- "// some license stuff here\n"
- "\n"
- "#include <bar>\n"
- "\n"
- "/// \\brief Foo\n"
- "int foo;\n",
- addIncludeInCode("bar", "// this is a header\n"
- "// some license stuff here\n"
- "\n"
- "/// \\brief Foo\n"
- "int foo;\n"));
-}
-
-TEST(IncludeDirectivesTest, preferablyAngledNextToAngled) {
- EXPECT_EQ("#include <foo.h>\n"
- "#include <bar>\n"
- "#include \"bar.h\"\n",
- addIncludeInCode("bar", "#include <foo.h>\n"
- "#include \"bar.h\"\n"));
- EXPECT_EQ("#include \"foo.h\"\n"
- "#include \"bar.h\"\n"
- "#include <bar>\n",
- addIncludeInCode("bar", "#include \"foo.h\"\n"
- "#include \"bar.h\"\n"));
-}
-
-TEST(IncludeDirectivesTest, avoidDuplicates) {
- EXPECT_EQ("#include <foo.h>\n",
- addIncludeInCode("foo.h", "#include <foo.h>\n"));
-}
-
-// Tests includes in the middle of the code are ignored.
-TEST(IncludeDirectivesTest, ignoreHeadersMeantForMultipleInclusion) {
- std::string Expected = "#include \"foo.h\"\n"
- "#include <bar>\n"
- "\n"
- "enum Kind {\n"
- "#define X(A) K_##A,\n"
- "#include \"xmacro.def\"\n"
- "#undef X\n"
- " K_NUM_KINDS\n"
- "};\n";
- std::string Result = addIncludeInCode("bar", "#include \"foo.h\"\n"
- "\n"
- "enum Kind {\n"
- "#define X(A) K_##A,\n"
- "#include \"xmacro.def\"\n"
- "#undef X\n"
- " K_NUM_KINDS\n"
- "};\n");
- EXPECT_EQ(Expected, Result);
-}
-
-namespace {
-TestAddIncludeAction *makeIndirectTestsAction(const char *HeaderToModify,
- tooling::Replacements &Replaces) {
- StringRef IncludeToAdd = "c.h";
- TestAddIncludeAction *TestAction =
- new TestAddIncludeAction(IncludeToAdd, Replaces, HeaderToModify);
- TestAction->mapVirtualHeader("c.h", "#pragma once\n");
- TestAction->mapVirtualHeader("a.h", "#pragma once\n"
- "#include <c.h>\n");
- TestAction->mapVirtualHeader("b.h", "#pragma once\n");
- return TestAction;
-}
-} // end anonymous namespace
-
-TEST(IncludeDirectivesTest, indirectIncludes) {
- // In TestAddIncludeAction 'foo.h' includes 'foo-inner.h'. Check that we
- // aren't including foo-inner.h again.
- EXPECT_EQ("#include <foo.h>\n",
- addIncludeInCode("foo-inner.h", "#include <foo.h>\n"));
-
- tooling::Replacements Replaces;
- StringRef Code = "#include <a.h>\n"
- "#include <b.h>\n";
-
- // a.h already includes c.h
- {
- FrontendAction *Action = makeIndirectTestsAction("a.h", Replaces);
- ASSERT_NO_FATAL_FAILURE(applyActionOnCode(Action, Code));
- EXPECT_EQ(unsigned(0), Replaces.size());
- }
-
- // c.h is included before b.h but b.h doesn't include c.h directly, so check
- // that it will be inserted.
- {
- FrontendAction *Action = makeIndirectTestsAction("b.h", Replaces);
- ASSERT_NO_FATAL_FAILURE(applyActionOnCode(Action, Code));
- EXPECT_EQ("#include <c.h>\n\n\n",
- tooling::applyAllReplacements("\n", Replaces));
- }
-}
-
-/// \brief Convenience method to test header guards detection implementation.
-static std::string addIncludeInGuardedHeader(StringRef IncludeToAdd,
- StringRef GuardedHeaderCode) {
- const char *GuardedHeaderName = "guarded.h";
- tooling::Replacements Replaces;
- TestAddIncludeAction *TestAction =
- new TestAddIncludeAction(IncludeToAdd, Replaces, GuardedHeaderName);
- TestAction->mapVirtualHeader(GuardedHeaderName, GuardedHeaderCode);
-
- applyActionOnCode(TestAction, "#include <guarded.h>\n");
- if (::testing::Test::HasFailure())
- return "<<unexpected error from applyActionOnCode()>>";
-
- return tooling::applyAllReplacements(GuardedHeaderCode, Replaces);
-}
-
-TEST(IncludeDirectivesTest, insertInsideIncludeGuard) {
- EXPECT_EQ("#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "#include <foo>\n"
- "\n"
- "struct foo {};\n"
- "\n"
- "#endif // GUARD_H\n",
- addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "struct foo {};\n"
- "\n"
- "#endif // GUARD_H\n"));
-}
-
-TEST(IncludeDirectivesTest, guardAndHeader) {
- EXPECT_EQ("// File header\n"
- "\n"
- "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "#include <foo>\n"
- "\n"
- "struct foo {};\n"
- "\n"
- "#endif // GUARD_H\n",
- addIncludeInGuardedHeader("foo", "// File header\n"
- "\n"
- "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "struct foo {};\n"
- "\n"
- "#endif // GUARD_H\n"));
-}
-
-TEST(IncludeDirectivesTest, fullHeaderFitsAsAPreamble) {
- EXPECT_EQ("#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "#include <foo>\n"
- "\n"
- "#define FOO 1\n"
- "\n"
- "#endif // GUARD_H\n",
- addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "#define FOO 1\n"
- "\n"
- "#endif // GUARD_H\n"));
-}
-
-TEST(IncludeDirectivesTest, codeBeforeIfndef) {
- EXPECT_EQ("#include <foo>\n"
- "\n"
- "int bar;\n"
- "\n"
- "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "struct foo;"
- "\n"
- "#endif // GUARD_H\n",
- addIncludeInGuardedHeader("foo", "int bar;\n"
- "\n"
- "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "struct foo;"
- "\n"
- "#endif // GUARD_H\n"));
-}
-
-TEST(IncludeDirectivesTest, codeAfterEndif) {
- EXPECT_EQ("#include <foo>\n"
- "\n"
- "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "struct foo;"
- "\n"
- "#endif // GUARD_H\n"
- "\n"
- "int bar;\n",
- addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "struct foo;"
- "\n"
- "#endif // GUARD_H\n"
- "\n"
- "int bar;\n"));
-}
-
-TEST(IncludeDirectivesTest, headerGuardWithInclude) {
- EXPECT_EQ("#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "#include <bar.h>\n"
- "#include <foo>\n"
- "\n"
- "struct foo;\n"
- "\n"
- "#endif // GUARD_H\n",
- addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"
- "#define GUARD_H\n"
- "\n"
- "#include <bar.h>\n"
- "\n"
- "struct foo;\n"
- "\n"
- "#endif // GUARD_H\n"));
-}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp
deleted file mode 100644
index 52a9d32d1f6..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-//===- cpp11-migrate/IncludeExcludeTest.cpp - IncludeExclude unit tests ---===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Utility.h"
-#include "Core/IncludeExcludeInfo.h"
-#include "gtest/gtest.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
-#include <fstream>
-
-TEST(IncludeExcludeTest, ParseString) {
- IncludeExcludeInfo IEManager;
- llvm::error_code Err = IEManager.readListFromString(
- /*include=*/ "a,b/b2,c/c2,d/../d2/../d3",
- /*exclude=*/ "a/af.cpp,a/a2,b/b2/b2f.cpp,c/c2");
-
- ASSERT_EQ(Err, llvm::error_code::success());
-
- // If the file does not appear on the include list then it is not safe to
- // transform. Files are not safe to transform by default.
- EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("b/dir/f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("d/f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("d2/f.cpp"));
-
- // If the file appears on only the include list then it is safe to transform.
- EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("a/dir/f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("b/b2/f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("d3/f.cpp"));
-
- // If the file appears on both the include or exclude list then it is not
- // safe to transform.
- EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("a/a2/f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("a/a2/dir/f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("b/b2/b2f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("c/c2/c3/f.cpp"));
-
-#ifdef LLVM_ON_WIN32
- // Check for cases when the path separators are different between the path
- // that was read and the path that we are checking for. This can happen on
- // windows where lit provides "\" and the test has "/".
- ASSERT_NO_ERROR(IEManager.readListFromString(
- /*include=*/ "C:\\foo,a\\b/c,a/../b\\c/..\\d",
- /*exclude=*/ "C:\\bar"
- ));
- EXPECT_TRUE(IEManager.isFileIncluded("C:/foo/code.h"));
- EXPECT_FALSE(IEManager.isFileIncluded("C:/bar/code.h"));
- EXPECT_TRUE(IEManager.isFileIncluded("a/b\\c/code.h"));
- EXPECT_FALSE(IEManager.isFileIncluded("b\\c/code.h"));
- EXPECT_TRUE(IEManager.isFileIncluded("b/d\\code.h"));
-#endif
-}
-
-TEST(IncludeExcludeTest, ParseStringCases) {
- IncludeExcludeInfo IEManager;
- llvm::error_code Err = IEManager.readListFromString(
- /*include=*/ "a/.,b/b2/,c/c2/c3/../../c4/,d/d2/./d3/,/e/e2/.",
- /*exclude=*/ "");
-
- ASSERT_EQ(Err, llvm::error_code::success());
-
- EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("b/b2/f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("c/c4/f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("d/d2/d3/f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("/e/e2/f.cpp"));
-
- EXPECT_FALSE(IEManager.isFileIncluded("c/c2/c3/f.cpp"));
-}
-
-// Utility for creating and filling files with data for IncludeExcludeFileTest
-// tests.
-struct InputFiles {
-
- // This function uses fatal assertions. The caller is responsible for making
- // sure fatal assertions propagate.
- void CreateFiles(bool UnixMode) {
- llvm::SmallString<128> Path;
- int FD;
-
- ASSERT_NO_ERROR(
- llvm::sys::fs::createTemporaryFile("include", "", FD, Path));
- IncludeDataPath = Path.str();
- {
- llvm::raw_fd_ostream IncludeDataFile(FD, true);
- for (unsigned i = 0; i < sizeof(IncludeData) / sizeof(char *); ++i) {
- IncludeDataFile << IncludeData[i] << (UnixMode ? "\n" : "\r\n");
- }
- }
-
- ASSERT_NO_ERROR(
- llvm::sys::fs::createTemporaryFile("exclude", "", FD, Path));
- ExcludeDataPath = Path.str();
- {
- llvm::raw_fd_ostream ExcludeDataFile(FD, true);
- for (unsigned i = 0; i < sizeof(ExcludeData) / sizeof(char *); ++i) {
- ExcludeDataFile << ExcludeData[i] << (UnixMode ? "\n" : "\r\n");
- }
- }
- }
-
- static const char *IncludeData[3];
- static const char *ExcludeData[4];
-
- std::string IncludeDataPath;
- std::string ExcludeDataPath;
-};
-
-const char *InputFiles::IncludeData[3] = { "a", "b/b2", "c/c2" };
-const char *InputFiles::ExcludeData[4] = { "a/af.cpp", "a/a2", "b/b2/b2f.cpp",
- "c/c2" };
-
-TEST(IncludeExcludeFileTest, UNIXFile) {
- InputFiles UnixFiles;
- ASSERT_NO_FATAL_FAILURE(UnixFiles.CreateFiles(/* UnixMode= */true));
-
- IncludeExcludeInfo IEManager;
- llvm::error_code Err = IEManager.readListFromFile(
- UnixFiles.IncludeDataPath.c_str(), UnixFiles.ExcludeDataPath.c_str());
-
- ASSERT_EQ(Err, llvm::error_code::success());
-
- EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));
-}
-
-TEST(IncludeExcludeFileTest, DOSFile) {
- InputFiles DOSFiles;
- ASSERT_NO_FATAL_FAILURE(DOSFiles.CreateFiles(/* UnixMode= */false));
-
- IncludeExcludeInfo IEManager;
- llvm::error_code Err = IEManager.readListFromFile(
- DOSFiles.IncludeDataPath.c_str(), DOSFiles.ExcludeDataPath.c_str());
-
- ASSERT_EQ(Err, llvm::error_code::success());
-
- EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));
- EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));
- EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));
-}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/Makefile b/clang-tools-extra/unittests/cpp11-migrate/Makefile
deleted file mode 100644
index 464bcd73033..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-##===- unittests/cpp11-migrate/Makefile --------------------*- Makefile -*-===##
-#
-# The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-CLANG_LEVEL = ../../../..
-include $(CLANG_LEVEL)/../../Makefile.config
-
-TESTNAME = Cpp11MigrateTests
-LINK_COMPONENTS := asmparser bitreader support MC MCParser option \
- TransformUtils
-USEDLIBS = migrateCore.a clangFormat.a clangApplyReplacements.a clangTooling.a clangFrontend.a \
- clangSerialization.a clangDriver.a clangRewriteFrontend.a \
- clangRewriteCore.a clangParse.a clangSema.a clangAnalysis.a \
- clangAST.a clangASTMatchers.a clangEdit.a clangLex.a \
- clangBasic.a
-
-include $(CLANG_LEVEL)/Makefile
-MAKEFILE_UNITTEST_NO_INCLUDE_COMMON := 1
-CPP.Flags += -I$(PROJ_SRC_DIR)/../../cpp11-migrate -I$(PROJ_SRC_DIR)/../../clang-apply-replacements/include
-include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
diff --git a/clang-tools-extra/unittests/cpp11-migrate/PerfSupportTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/PerfSupportTest.cpp
deleted file mode 100644
index 81235481bff..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/PerfSupportTest.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-//===- cpp11-migrate/PerfSupportTest.cpp - PerfSupport unit tests --------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-#include "Core/PerfSupport.h"
-
-using namespace llvm;
-using namespace clang;
-
-class TransformA : public Transform {
-public:
- TransformA(const TransformOptions &Options)
- : Transform("TransformA", Options) {}
-
- virtual int apply(const FileOverrides &,
- const tooling::CompilationDatabase &,
- const std::vector<std::string> &) {
- return 0;
- }
-
- void addTiming(StringRef Label, TimeRecord Duration) {
- Transform::addTiming(Label, Duration);
- }
-};
-
-class TransformB : public Transform {
-public:
- TransformB(const TransformOptions &Options)
- : Transform("TransformB", Options) {}
-
- virtual int apply(const FileOverrides &,
- const tooling::CompilationDatabase &,
- const std::vector<std::string> &) {
- return 0;
- }
-
- void addTiming(StringRef Label, TimeRecord Duration) {
- Transform::addTiming(Label, Duration);
- }
-};
-
-struct ExpectedResults {
- const char *SourceName;
- unsigned DataCount;
- struct Datum {
- const char *Label;
- float Duration;
- } Data[2];
-};
-
-TEST(PerfSupport, collectSourcePerfData) {
- TransformOptions Options;
- TransformA A(Options);
- TransformB B(Options);
-
- // The actual durations don't matter. Below only their relative ordering is
- // tested to ensure times, labels, and sources all stay together properly.
- A.addTiming("FileA.cpp", TimeRecord::getCurrentTime(/*Start=*/true));
- A.addTiming("FileC.cpp", TimeRecord::getCurrentTime(/*Start=*/true));
- B.addTiming("FileC.cpp", TimeRecord::getCurrentTime(/*Start=*/true));
- B.addTiming("FileB.cpp", TimeRecord::getCurrentTime(/*Start=*/true));
-
- SourcePerfData PerfData;
- collectSourcePerfData(A, PerfData);
-
- SourcePerfData::const_iterator FileAI = PerfData.find("FileA.cpp");
- EXPECT_NE(FileAI, PerfData.end());
- SourcePerfData::const_iterator FileCI = PerfData.find("FileC.cpp");
- EXPECT_NE(FileCI, PerfData.end());
- EXPECT_EQ(2u, PerfData.size());
-
- EXPECT_EQ(1u, FileAI->second.size());
- EXPECT_EQ("TransformA", FileAI->second[0].Label);
- EXPECT_EQ(1u, FileCI->second.size());
- EXPECT_EQ("TransformA", FileCI->second[0].Label);
- EXPECT_LE(FileAI->second[0].Duration, FileCI->second[0].Duration);
-
- collectSourcePerfData(B, PerfData);
-
- SourcePerfData::const_iterator FileBI = PerfData.find("FileB.cpp");
- EXPECT_NE(FileBI, PerfData.end());
- EXPECT_EQ(3u, PerfData.size());
-
- EXPECT_EQ(1u, FileAI->second.size());
- EXPECT_EQ("TransformA", FileAI->second[0].Label);
- EXPECT_EQ(2u, FileCI->second.size());
- EXPECT_EQ("TransformA", FileCI->second[0].Label);
- EXPECT_EQ("TransformB", FileCI->second[1].Label);
- EXPECT_LE(FileCI->second[0].Duration, FileCI->second[1].Duration);
- EXPECT_EQ(1u, FileBI->second.size());
- EXPECT_EQ("TransformB", FileBI->second[0].Label);
- EXPECT_LE(FileCI->second[1].Duration, FileBI->second[0].Duration);
-}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp
deleted file mode 100644
index b4b9a365478..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-//===- cpp11-migrate/ReformattingTest.cpp - Reformatting unit tests -------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Core/Reformatting.h"
-#include "Core/FileOverrides.h"
-#include "Core/Refactoring.h"
-#include "gtest/gtest.h"
-#include "VirtualFileHelper.h"
-
-using namespace clang;
-using namespace clang::tooling;
-
-namespace {
-// convenience function to create a ChangedRanges containing one Range
-ChangedRanges makeChangedRanges(unsigned Offset, unsigned Length) {
- ChangedRanges Changes;
- ReplacementsVec Replaces;
-
- Replaces.push_back(Replacement("", Offset, 0, std::string(Length, '~')));
- Changes.adjustChangedRanges(Replaces);
- return Changes;
-}
-} // end anonymous namespace
-
-TEST(Reformatter, SingleReformat) {
- VirtualFileHelper VFHelper;
- llvm::StringRef FileName = "<test>";
- VFHelper.mapFile(FileName, "int a;\n"
- "int b;\n");
-
- Reformatter ChangesReformatter(format::getLLVMStyle());
- ChangedRanges Changes = makeChangedRanges(0, 6);
- tooling::ReplacementsVec Replaces;
- ChangesReformatter.reformatSingleFile(
- FileName, Changes, VFHelper.getNewSourceManager(), Replaces);
-
- // We expect the code above to reformatted like so:
- //
- // int a;
- // int b;
- //
- // This test is slightly fragile since there's more than one Replacement that
- // results in the above change. However, testing the result of applying the
- // replacement is more trouble than it's worth in this context.
- ASSERT_EQ(1u, Replaces.size());
- EXPECT_EQ(3u, Replaces[0].getOffset());
- EXPECT_EQ(2u, Replaces[0].getLength());
- EXPECT_EQ(" ", Replaces[0].getReplacementText());
-}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/TransformTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/TransformTest.cpp
deleted file mode 100644
index 75397bf7760..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/TransformTest.cpp
+++ /dev/null
@@ -1,326 +0,0 @@
-//===- cpp11-migrate/TransformTest.cpp - Transform unit tests -------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-#include "Core/FileOverrides.h"
-#include "Core/Transform.h"
-#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/DeclGroup.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Process.h"
-#include "llvm/Support/Path.h"
-
-using namespace clang;
-using namespace ast_matchers;
-
-class DummyTransform : public Transform {
-public:
- DummyTransform(llvm::StringRef Name, const TransformOptions &Options)
- : Transform(Name, Options) {}
-
- virtual int apply(const FileOverrides &,
- const tooling::CompilationDatabase &,
- const std::vector<std::string> &) { return 0; }
-
- void setAcceptedChanges(unsigned Changes) {
- Transform::setAcceptedChanges(Changes);
- }
- void setRejectedChanges(unsigned Changes) {
- Transform::setRejectedChanges(Changes);
- }
- void setDeferredChanges(unsigned Changes) {
- Transform::setDeferredChanges(Changes);
- }
-
- void setOverrides(FileOverrides &Overrides) {
- Transform::setOverrides(Overrides);
- }
-
-};
-
-TEST(Transform, Interface) {
- TransformOptions Options;
- DummyTransform T("my_transform", Options);
-
- ASSERT_EQ("my_transform", T.getName());
- ASSERT_EQ(0u, T.getAcceptedChanges());
- ASSERT_EQ(0u, T.getRejectedChanges());
- ASSERT_EQ(0u, T.getDeferredChanges());
- ASSERT_FALSE(T.getChangesMade());
- ASSERT_FALSE(T.getChangesNotMade());
-
- T.setAcceptedChanges(1);
- ASSERT_TRUE(T.getChangesMade());
-
- T.setDeferredChanges(1);
- ASSERT_TRUE(T.getChangesNotMade());
-
- T.setRejectedChanges(1);
- ASSERT_TRUE(T.getChangesNotMade());
-
- T.Reset();
- ASSERT_EQ(0u, T.getAcceptedChanges());
- ASSERT_EQ(0u, T.getRejectedChanges());
- ASSERT_EQ(0u, T.getDeferredChanges());
-
- T.setRejectedChanges(1);
- ASSERT_TRUE(T.getChangesNotMade());
-}
-
-class TimePassingASTConsumer : public ASTConsumer {
-public:
- TimePassingASTConsumer(bool *Called) : Called(Called) {}
-
- virtual bool HandleTopLevelDecl(DeclGroupRef DeclGroup) {
- llvm::sys::TimeValue UserStart;
- llvm::sys::TimeValue SystemStart;
- llvm::sys::TimeValue UserNow;
- llvm::sys::TimeValue SystemNow;
- llvm::sys::TimeValue Wall;
-
- // Busy-wait until the user/system time combined is more than 1ms
- llvm::sys::TimeValue OneMS(0, 1000000);
- llvm::sys::Process::GetTimeUsage(Wall, UserStart, SystemStart);
- do {
- llvm::sys::Process::GetTimeUsage(Wall, UserNow, SystemNow);
- } while (UserNow - UserStart + SystemNow - SystemStart < OneMS);
- *Called = true;
- return true;
- }
- bool *Called;
-};
-
-struct ConsumerFactory {
- ASTConsumer *newASTConsumer() {
- return new TimePassingASTConsumer(&Called);
- }
- bool Called;
-};
-
-struct CallbackForwarder : public clang::tooling::SourceFileCallbacks {
- CallbackForwarder(Transform &Callee) : Callee(Callee) {}
-
- virtual bool handleBeginSource(CompilerInstance &CI, StringRef Filename) {
- return Callee.handleBeginSource(CI, Filename);
- }
-
- virtual void handleEndSource() {
- Callee.handleEndSource();
- }
-
- Transform &Callee;
-};
-
-TEST(Transform, Timings) {
- TransformOptions Options;
- Options.EnableTiming = true;
- DummyTransform T("timing_transform", Options);
-
- // All the path stuff is to make the test work independently of OS.
-
- // The directory used is not important since the path gets mapped to a virtual
- // file anyway. What is important is that we have an absolute path with which
- // to use with mapVirtualFile().
- SmallString<128> CurrentDir;
- llvm::error_code EC = llvm::sys::fs::current_path(CurrentDir);
- assert(!EC);
- (void)EC;
-
- SmallString<128> FileA = CurrentDir;
- llvm::sys::path::append(FileA, "a.cc");
-
- SmallString<128> FileB = CurrentDir;
- llvm::sys::path::append(FileB, "b.cc");
-
- tooling::FixedCompilationDatabase Compilations(CurrentDir.str(),
- std::vector<std::string>());
- std::vector<std::string> Sources;
- Sources.push_back(FileA.str());
- Sources.push_back(FileB.str());
- tooling::ClangTool Tool(Compilations, Sources);
-
- Tool.mapVirtualFile(FileA, "void a() {}");
- Tool.mapVirtualFile(FileB, "void b() {}");
-
- // Factory to create TimePassingASTConsumer for each source file the tool
- // runs on.
- ConsumerFactory Factory;
-
- // We don't care about any of Transform's functionality except to get it to
- // record timings. For that, we need to forward handleBeginSource() and
- // handleEndSource() calls to it.
- CallbackForwarder Callbacks(T);
-
- // Transform's handle* functions require FileOverrides to be set, even if
- // there aren't any.
- FileOverrides Overrides;
- T.setOverrides(Overrides);
-
- Tool.run(clang::tooling::newFrontendActionFactory(&Factory, &Callbacks));
-
- EXPECT_TRUE(Factory.Called);
- Transform::TimingVec::const_iterator I = T.timing_begin();
- EXPECT_GT(I->second.getProcessTime(), 0.0);
-
- // The success of the test shouldn't depend on the order of iteration through
- // timers.
- StringRef FirstFile = I->first;
- if (FileA == FirstFile) {
- ++I;
- EXPECT_EQ(FileB, I->first);
- EXPECT_GT(I->second.getProcessTime(), 0.0);
- } else if (FileB == FirstFile) {
- ++I;
- EXPECT_EQ(FileA, I->first);
- EXPECT_GT(I->second.getProcessTime(), 0.0);
- } else {
- FAIL() << "Unexpected file name " << I->first << " in timing data.";
- }
- ++I;
- EXPECT_EQ(T.timing_end(), I);
-}
-
-class ModifiableCallback
- : public clang::ast_matchers::MatchFinder::MatchCallback {
-public:
- ModifiableCallback(const Transform &Owner, bool HeadersModifiable)
- : Owner(Owner), HeadersModifiable(HeadersModifiable) {}
-
- virtual void
- run(const clang::ast_matchers::MatchFinder::MatchResult &Result) {
- const VarDecl *Decl = Result.Nodes.getNodeAs<VarDecl>("decl");
- ASSERT_TRUE(Decl != 0);
-
- const SourceManager &SM = *Result.SourceManager;
-
- // Decl 'a' comes from the main source file. This test should always pass.
- if (Decl->getName().equals("a"))
- EXPECT_TRUE(Owner.isFileModifiable(SM, Decl->getLocStart()));
-
- // Decl 'c' comes from an excluded header. This test should never pass.
- else if (Decl->getName().equals("c"))
- EXPECT_FALSE(Owner.isFileModifiable(SM, Decl->getLocStart()));
-
- // Decl 'b' comes from an included header. It should be modifiable only if
- // header modifications are allowed.
- else if (Decl->getName().equals("b"))
- EXPECT_EQ(HeadersModifiable,
- Owner.isFileModifiable(SM, Decl->getLocStart()));
-
- // Make sure edge cases are handled gracefully (they should never be
- // allowed).
- SourceLocation DummyLoc;
- EXPECT_FALSE(Owner.isFileModifiable(SM, DummyLoc));
- }
-
-private:
- const Transform &Owner;
- bool HeadersModifiable;
-};
-
-TEST(Transform, isFileModifiable) {
- TransformOptions Options;
-
- ///
- /// SETUP
- ///
- /// To test Transform::isFileModifiable() we need a SourceManager primed with
- /// actual files and SourceLocations to test. Easiest way to accomplish this
- /// is to use Tooling classes.
- ///
- /// 1) Simulate a source file that includes two headers, one that is allowed
- /// to be modified and the other that is not allowed. Each of the three
- /// files involved will declare a single variable with a different name.
- /// 2) A matcher is created to find VarDecls.
- /// 3) A MatchFinder callback calls Transform::isFileModifiable() with the
- /// SourceLocations of found VarDecls and thus tests the function.
- ///
-
- // All the path stuff is to make the test work independently of OS.
-
- // The directory used is not important since the path gets mapped to a virtual
- // file anyway. What is important is that we have an absolute path with which
- // to use with mapVirtualFile().
- SmallString<128> CurrentDir;
- llvm::error_code EC = llvm::sys::fs::current_path(CurrentDir);
- assert(!EC);
- (void)EC;
-
- SmallString<128> SourceFile = CurrentDir;
- llvm::sys::path::append(SourceFile, "a.cc");
-
- SmallString<128> HeaderFile = CurrentDir;
- llvm::sys::path::append(HeaderFile, "a.h");
-
- SmallString<128> HeaderBFile = CurrentDir;
- llvm::sys::path::append(HeaderBFile, "temp");
- llvm::sys::path::append(HeaderBFile, "b.h");
-
- StringRef ExcludeDir = llvm::sys::path::parent_path(HeaderBFile);
-
- IncludeExcludeInfo IncInfo;
- Options.ModifiableHeaders.readListFromString(CurrentDir, ExcludeDir);
-
- tooling::FixedCompilationDatabase Compilations(CurrentDir.str(),
- std::vector<std::string>());
- std::vector<std::string> Sources;
- Sources.push_back(SourceFile.str());
- tooling::ClangTool Tool(Compilations, Sources);
-
- Tool.mapVirtualFile(SourceFile,
- "#include \"a.h\"\n"
- "#include \"temp/b.h\"\n"
- "int a;");
- Tool.mapVirtualFile(HeaderFile, "int b;");
- Tool.mapVirtualFile(HeaderBFile, "int c;");
-
- // Run tests with header modifications turned off.
- {
- SCOPED_TRACE("Header Modifications are OFF");
- Options.EnableHeaderModifications = false;
- DummyTransform T("dummy", Options);
- MatchFinder Finder;
- Finder.addMatcher(varDecl().bind("decl"), new ModifiableCallback(T, false));
- Tool.run(tooling::newFrontendActionFactory(&Finder));
- }
-
- // Run again with header modifications turned on.
- {
- SCOPED_TRACE("Header Modifications are ON");
- Options.EnableHeaderModifications = true;
- DummyTransform T("dummy", Options);
- MatchFinder Finder;
- Finder.addMatcher(varDecl().bind("decl"), new ModifiableCallback(T, true));
- Tool.run(tooling::newFrontendActionFactory(&Finder));
- }
-}
-
-TEST(VersionTest, Interface) {
- Version V;
-
- ASSERT_TRUE(V.isNull());
- ASSERT_TRUE(Version(1) < Version(1, 1));
- ASSERT_TRUE(Version(1) < Version(2));
- ASSERT_TRUE(Version(1, 1) < Version(2));
- ASSERT_TRUE(Version(1, 1) == Version(1, 1));
- ASSERT_EQ(Version(1).getMajor(), unsigned(1));
- ASSERT_EQ(Version(1).getMinor(), unsigned(0));
- ASSERT_EQ(Version(1, 2).getMinor(), unsigned(2));
-}
-
-TEST(VersionTest, getFromString) {
- ASSERT_EQ(Version(1), Version::getFromString("1"));
- ASSERT_EQ(Version(1, 2), Version::getFromString("1.2"));
- ASSERT_TRUE(Version::getFromString("foo").isNull());
- ASSERT_TRUE(Version::getFromString("1bar").isNull());
- // elements after major.minor are ignored
- ASSERT_EQ(Version(1, 2), Version::getFromString("1.2.3"));
-}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/UniqueHeaderNameTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/UniqueHeaderNameTest.cpp
deleted file mode 100644
index a2d70e03baa..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/UniqueHeaderNameTest.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-//===- unittests/cpp11-migrate/UniqueHeaderNameTest.cpp -------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Test for the generateReplacementsFileName() in FileOverrides.h
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-#include "Core/FileOverrides.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/Regex.h"
-#include "llvm/Support/system_error.h"
-
-TEST(UniqueHeaderName, testUniqueHeaderName) {
- using namespace llvm::sys::path;
-
- llvm::SmallString<32> TmpDir;
- system_temp_directory(true, TmpDir);
-
- llvm::SmallString<128> SourceFile(TmpDir);
- append(SourceFile, "project/lib/feature.cpp");
- native(SourceFile.str().str(), SourceFile);
-
- llvm::SmallString<128> FullActualPath;
- llvm::SmallString<128> Error;
- bool Result =
- generateReplacementsFileName(SourceFile, FullActualPath, Error);
-
- ASSERT_TRUE(Result);
- EXPECT_TRUE(Error.empty());
-
- // We need to check the directory name and filename separately since on
- // Windows, the path separator is '\' which is a regex escape character.
- llvm::SmallString<128> ExpectedPath =
- llvm::sys::path::parent_path(SourceFile);
- llvm::SmallString<128> ActualPath =
- llvm::sys::path::parent_path(FullActualPath);
- llvm::SmallString<128> ActualName =
- llvm::sys::path::filename(FullActualPath);
-
- EXPECT_STREQ(ExpectedPath.c_str(), ActualPath.c_str());
-
- llvm::StringRef ExpectedName =
- "^feature.cpp_[0-9a-f]{2}_[0-9a-f]{2}_[0-9a-f]{2}_[0-9a-f]{2}_["
- "0-9a-f]{2}_[0-9a-f]{2}.yaml$";
- llvm::Regex R(ExpectedName);
- ASSERT_TRUE(R.match(ActualName))
- << "ExpectedName: " << ExpectedName.data()
- << "\nActualName: " << ActualName.c_str();
- ASSERT_TRUE(Error.empty()) << "Error: " << Error.c_str();
-}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/Utility.h b/clang-tools-extra/unittests/cpp11-migrate/Utility.h
deleted file mode 100644
index 54291d941a3..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/Utility.h
+++ /dev/null
@@ -1,25 +0,0 @@
-//=-- cpp11-migrate/Utility.h - Utility functions and macros-----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef CPP11_MIGRATE_UNITTESTS_UTILITY_H
-#define CPP11_MIGRATE_UNITTESTS_UTILITY_H
-
-// FIXME: copied from unittests/Support/Path.cpp
-#define ASSERT_NO_ERROR(x) \
- if (llvm::error_code ASSERT_NO_ERROR_ec = x) { \
- llvm::SmallString<128> MessageStorage; \
- llvm::raw_svector_ostream Message(MessageStorage); \
- Message << #x ": did not return errc::success.\n" \
- << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
- << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
- GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
- } else { \
- }
-
-#endif // CPP11_MIGRATE_UNITTESTS_UTILITY_H
diff --git a/clang-tools-extra/unittests/cpp11-migrate/VirtualFileHelper.h b/clang-tools-extra/unittests/cpp11-migrate/VirtualFileHelper.h
deleted file mode 100644
index 093ace1d0dc..00000000000
--- a/clang-tools-extra/unittests/cpp11-migrate/VirtualFileHelper.h
+++ /dev/null
@@ -1,81 +0,0 @@
-//===--- VirtualFileHelper.h ------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \brief This file defines an utility class for tests that needs a source
-/// manager for a virtual file with customizable content.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef CPP11_MIGRATE_VIRTUAL_FILE_HELPER_H
-#define CPP11_MIGRATE_VIRTUAL_FILE_HELPER_H
-
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/DiagnosticOptions.h"
-#include "clang/Basic/FileManager.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
-
-namespace clang {
-
-/// \brief Class that provides easy access to a SourceManager and that allows to
-/// map virtual files conveniently.
-class VirtualFileHelper {
- struct VirtualFile {
- std::string FileName;
- std::string Code;
- };
-
-public:
- VirtualFileHelper()
- : DiagOpts(new DiagnosticOptions()),
- Diagnostics(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
- &*DiagOpts),
- DiagnosticPrinter(llvm::outs(), &*DiagOpts),
- Files((FileSystemOptions())) {}
-
- /// \brief Create a virtual file \p FileName, with content \p Code.
- void mapFile(llvm::StringRef FileName, llvm::StringRef Code) {
- VirtualFile VF = { FileName, Code };
- VirtualFiles.push_back(VF);
- }
-
- /// \brief Create a new \c SourceManager with the virtual files and contents
- /// mapped to it.
- SourceManager &getNewSourceManager() {
- Sources.reset(new SourceManager(Diagnostics, Files));
- mapVirtualFiles(*Sources);
- return *Sources;
- }
-
- /// \brief Map the virtual file contents in the given \c SourceManager.
- void mapVirtualFiles(SourceManager &SM) const {
- for (llvm::SmallVectorImpl<VirtualFile>::const_iterator
- I = VirtualFiles.begin(),
- E = VirtualFiles.end();
- I != E; ++I) {
- llvm::MemoryBuffer *Buf = llvm::MemoryBuffer::getMemBuffer(I->Code);
- const FileEntry *Entry = SM.getFileManager().getVirtualFile(
- I->FileName, Buf->getBufferSize(), /*ModificationTime=*/0);
- SM.overrideFileContents(Entry, Buf);
- }
- }
-
-private:
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
- DiagnosticsEngine Diagnostics;
- TextDiagnosticPrinter DiagnosticPrinter;
- FileManager Files;
- // most tests don't need more than one file
- llvm::SmallVector<VirtualFile, 1> VirtualFiles;
- llvm::OwningPtr<SourceManager> Sources;
-};
-
-} // end namespace clang
-
-#endif // CPP11_MIGRATE_VIRTUAL_FILE_HELPER_H
OpenPOWER on IntegriCloud