martong updated this revision to Diff 149093.
martong added a comment.

- Moved the family of `testImport` functions under a test fixture class, so we 
can use parameterized test.
- Refactored `testImport` and `testImportSequence`, because for loops over the 
different compiler options is no longer needed, that is handeld by the test 
framework via parameters from now on.


Repository:
  rC Clang

https://reviews.llvm.org/D47367

Files:
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -50,111 +50,236 @@
                                    llvm::MemoryBuffer::getMemBuffer(Code));
 }
 
-template <typename NodeType>
-NodeType importNode(ASTUnit *From, ASTUnit *To, ASTImporter &Importer,
-                    NodeType Node) {
-  ASTContext &ToCtx = To->getASTContext();
+const StringRef DeclToImportID = "declToImport";
+const StringRef DeclToVerifyID = "declToVerify";
 
-  // Add 'From' file to virtual file system so importer can 'find' it
-  // while importing SourceLocations. It is safe to add same file multiple
-  // times - it just isn't replaced.
-  StringRef FromFileName = From->getMainFileName();
-  createVirtualFileIfNeeded(To, FromFileName,
-                            From->getBufferForFile(FromFileName));
+// Common base for the different families of ASTImporter tests that are
+// parameterized on the compiler options which may result a different AST. E.g.
+// -fms-compatibility or -fdelayed-template-parsing.
+struct ParameterizedTestsFixture : ::testing::TestWithParam<ArgVector> {
 
-  auto Imported = Importer.Import(Node);
+  // Returns the argument vector used for a specific language option, this set
+  // can be tweaked by the test parameters.
+  ArgVector getArgVectorForLanguage(Language Lang) const {
+    ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+    ArgVector ExtraArgs = GetParam();
+    for (const auto &Arg : ExtraArgs) {
+      Args.push_back(Arg);
+    }
+    return Args;
+  }
 
-  // This should dump source locations and assert if some source locations
-  // were not imported.
-  SmallString<1024> ImportChecker;
-  llvm::raw_svector_ostream ToNothing(ImportChecker);
-  ToCtx.getTranslationUnitDecl()->print(ToNothing);
+};
 
-  // This traverses the AST to catch certain bugs like poorly or not
-  // implemented subtrees.
-  Imported->dump(ToNothing);
+// Base class for those tests which use the family of `testImport` functions.
+class TestImportBase : public ParameterizedTestsFixture {
 
-  return Imported;
-}
+  template <typename NodeType>
+  NodeType importNode(ASTUnit *From, ASTUnit *To, ASTImporter &Importer,
+                      NodeType Node) {
+    ASTContext &ToCtx = To->getASTContext();
 
-const StringRef DeclToImportID = "declToImport";
-const StringRef DeclToVerifyID = "declToVerify";
+    // Add 'From' file to virtual file system so importer can 'find' it
+    // while importing SourceLocations. It is safe to add same file multiple
+    // times - it just isn't replaced.
+    StringRef FromFileName = From->getMainFileName();
+    createVirtualFileIfNeeded(To, FromFileName,
+                              From->getBufferForFile(FromFileName));
 
-template <typename NodeType>
-testing::AssertionResult
-testImport(const std::string &FromCode, const ArgVector &FromArgs,
-           const std::string &ToCode, const ArgVector &ToArgs,
-           MatchVerifier<NodeType> &Verifier,
-           const BindableMatcher<NodeType> &SearchMatcher,
-           const BindableMatcher<NodeType> &VerificationMatcher) {
-  const char *const InputFileName = "input.cc";
-  const char *const OutputFileName = "output.cc";
+    auto Imported = Importer.Import(Node);
 
-  std::unique_ptr<ASTUnit>
-      FromAST = tooling::buildASTFromCodeWithArgs(
-        FromCode, FromArgs, InputFileName),
-      ToAST = tooling::buildASTFromCodeWithArgs(ToCode, ToArgs, OutputFileName);
-
-  ASTContext &FromCtx = FromAST->getASTContext(),
-      &ToCtx = ToAST->getASTContext();
-
-  ASTImporter Importer(ToCtx, ToAST->getFileManager(),
-                       FromCtx, FromAST->getFileManager(), false);
-
-  auto FoundNodes = match(SearchMatcher, FromCtx);
-  if (FoundNodes.size() != 1)
-    return testing::AssertionFailure()
-           << "Multiple potential nodes were found!";
-
-  auto ToImport = selectFirst<NodeType>(DeclToImportID, FoundNodes);
-  if (!ToImport)
-    return testing::AssertionFailure() << "Node type mismatch!";
-
-  // Sanity check: the node being imported should match in the same way as
-  // the result node.
-  BindableMatcher<NodeType> WrapperMatcher(VerificationMatcher);
-  EXPECT_TRUE(Verifier.match(ToImport, WrapperMatcher));
-
-  auto Imported = importNode(FromAST.get(), ToAST.get(), Importer, ToImport);
-  if (!Imported)
-    return testing::AssertionFailure() << "Import failed, nullptr returned!";
-
-  return Verifier.match(Imported, WrapperMatcher);
-}
-
-template <typename NodeType>
-testing::AssertionResult
-testImport(const std::string &FromCode, const ArgVector &FromArgs,
-           const std::string &ToCode, const ArgVector &ToArgs,
-           MatchVerifier<NodeType> &Verifier,
-           const BindableMatcher<NodeType> &VerificationMatcher) {
-  return testImport(
-      FromCode, FromArgs, ToCode, ToArgs, Verifier,
-      translationUnitDecl(
-          has(namedDecl(hasName(DeclToImportID)).bind(DeclToImportID))),
-      VerificationMatcher);
-}
-
-/// Test how AST node named "declToImport" located in the translation unit
-/// of "FromCode" virtual file is imported to "ToCode" virtual file.
-/// The verification is done by running AMatcher over the imported node.
-template <typename NodeType, typename MatcherType>
-void testImport(const std::string &FromCode, Language FromLang,
-                const std::string &ToCode, Language ToLang,
-                MatchVerifier<NodeType> &Verifier,
-                const MatcherType &AMatcher) {
-  auto RunOptsFrom = getRunOptionsForLanguage(FromLang);
-  auto RunOptsTo = getRunOptionsForLanguage(ToLang);
-  for (const auto &FromArgs : RunOptsFrom)
-    for (const auto &ToArgs : RunOptsTo)
-      EXPECT_TRUE(testImport(FromCode, FromArgs, ToCode, ToArgs,
-                             Verifier, AMatcher));
-}
+    // This should dump source locations and assert if some source locations
+    // were not imported.
+    SmallString<1024> ImportChecker;
+    llvm::raw_svector_ostream ToNothing(ImportChecker);
+    ToCtx.getTranslationUnitDecl()->print(ToNothing);
+
+    // This traverses the AST to catch certain bugs like poorly or not
+    // implemented subtrees.
+    Imported->dump(ToNothing);
+
+    return Imported;
+  }
+
+  template <typename NodeType>
+  testing::AssertionResult
+  testImport(const std::string &FromCode, const ArgVector &FromArgs,
+             const std::string &ToCode, const ArgVector &ToArgs,
+             MatchVerifier<NodeType> &Verifier,
+             const BindableMatcher<NodeType> &SearchMatcher,
+             const BindableMatcher<NodeType> &VerificationMatcher) {
+    const char *const InputFileName = "input.cc";
+    const char *const OutputFileName = "output.cc";
+
+    std::unique_ptr<ASTUnit> FromAST = tooling::buildASTFromCodeWithArgs(
+                                 FromCode, FromArgs, InputFileName),
+                             ToAST = tooling::buildASTFromCodeWithArgs(
+                                 ToCode, ToArgs, OutputFileName);
+
+    ASTContext &FromCtx = FromAST->getASTContext(),
+               &ToCtx = ToAST->getASTContext();
+
+    ASTImporter Importer(ToCtx, ToAST->getFileManager(), FromCtx,
+                         FromAST->getFileManager(), false);
+
+    auto FoundNodes = match(SearchMatcher, FromCtx);
+    if (FoundNodes.size() != 1)
+      return testing::AssertionFailure()
+             << "Multiple potential nodes were found!";
+
+    auto ToImport = selectFirst<NodeType>(DeclToImportID, FoundNodes);
+    if (!ToImport)
+      return testing::AssertionFailure() << "Node type mismatch!";
+
+    // Sanity check: the node being imported should match in the same way as
+    // the result node.
+    BindableMatcher<NodeType> WrapperMatcher(VerificationMatcher);
+    EXPECT_TRUE(Verifier.match(ToImport, WrapperMatcher));
+
+    auto Imported = importNode(FromAST.get(), ToAST.get(), Importer, ToImport);
+    if (!Imported)
+      return testing::AssertionFailure() << "Import failed, nullptr returned!";
+
+    return Verifier.match(Imported, WrapperMatcher);
+  }
+
+  template <typename NodeType>
+  testing::AssertionResult
+  testImport(const std::string &FromCode, const ArgVector &FromArgs,
+             const std::string &ToCode, const ArgVector &ToArgs,
+             MatchVerifier<NodeType> &Verifier,
+             const BindableMatcher<NodeType> &VerificationMatcher) {
+    return testImport(
+        FromCode, FromArgs, ToCode, ToArgs, Verifier,
+        translationUnitDecl(
+            has(namedDecl(hasName(DeclToImportID)).bind(DeclToImportID))),
+        VerificationMatcher);
+  }
+
+public:
+
+  /// Test how AST node named "declToImport" located in the translation unit
+  /// of "FromCode" virtual file is imported to "ToCode" virtual file.
+  /// The verification is done by running AMatcher over the imported node.
+  template <typename NodeType, typename MatcherType>
+  void testImport(const std::string &FromCode, Language FromLang,
+                  const std::string &ToCode, Language ToLang,
+                  MatchVerifier<NodeType> &Verifier,
+                  const MatcherType &AMatcher) {
+    ArgVector FromArgs = getArgVectorForLanguage(FromLang),
+              ToArgs = getArgVectorForLanguage(ToLang);
+    EXPECT_TRUE(
+        testImport(FromCode, FromArgs, ToCode, ToArgs, Verifier, AMatcher));
+  }
+
+  struct ImportAction {
+    StringRef FromFilename;
+    StringRef ToFilename;
+    // FIXME: Generalize this to support other node kinds.
+    BindableMatcher<Decl> ImportPredicate;
+
+    ImportAction(StringRef FromFilename, StringRef ToFilename,
+                 DeclarationMatcher ImportPredicate)
+        : FromFilename(FromFilename), ToFilename(ToFilename),
+          ImportPredicate(ImportPredicate) {}
+
+    ImportAction(StringRef FromFilename, StringRef ToFilename,
+                 const std::string &DeclName)
+        : FromFilename(FromFilename), ToFilename(ToFilename),
+          ImportPredicate(namedDecl(hasName(DeclName))) {}
+  };
+
+  using SingleASTUnit = std::unique_ptr<ASTUnit>;
+  using AllASTUnits = StringMap<SingleASTUnit>;
+
+  struct CodeEntry {
+    std::string CodeSample;
+    Language Lang;
+  };
+
+  using CodeFiles = StringMap<CodeEntry>;
+
+  /// Builds an ASTUnit for one potential compile options set.
+  SingleASTUnit createASTUnit(StringRef FileName, const CodeEntry &CE) const {
+    ArgVector Args = getArgVectorForLanguage(CE.Lang);
+    auto AST = tooling::buildASTFromCodeWithArgs(CE.CodeSample, Args, FileName);
+    EXPECT_TRUE(AST.get());
+    return AST;
+  }
+
+  /// Test an arbitrary sequence of imports for a set of given in-memory files.
+  /// The verification is done by running VerificationMatcher against a
+  /// specified
+  /// AST node inside of one of given files.
+  /// \param CodeSamples Map whose key is the file name and the value is the
+  /// file
+  /// content.
+  /// \param ImportActions Sequence of imports. Each import in sequence
+  /// specifies "from file" and "to file" and a matcher that is used for
+  /// searching a declaration for import in "from file".
+  /// \param FileForFinalCheck Name of virtual file for which the final check is
+  /// applied.
+  /// \param FinalSelectPredicate Matcher that specifies the AST node in the
+  /// FileForFinalCheck for which the verification will be done.
+  /// \param VerificationMatcher Matcher that will be used for verification
+  /// after
+  /// all imports in sequence are done.
+  void testImportSequence(const CodeFiles &CodeSamples,
+                          const std::vector<ImportAction> &ImportActions,
+                          StringRef FileForFinalCheck,
+                          BindableMatcher<Decl> FinalSelectPredicate,
+                          BindableMatcher<Decl> VerificationMatcher) {
+    AllASTUnits AllASTs;
+    using ImporterKey = std::pair<const ASTUnit *, const ASTUnit *>;
+    llvm::DenseMap<ImporterKey, std::unique_ptr<ASTImporter>> Importers;
+
+    auto GenASTsIfNeeded = [this, &AllASTs, &CodeSamples](StringRef Filename) {
+      if (!AllASTs.count(Filename)) {
+        auto Found = CodeSamples.find(Filename);
+        assert(Found != CodeSamples.end() && "Wrong file for import!");
+        AllASTs[Filename] = createASTUnit(Filename, Found->getValue());
+      }
+    };
+
+    for (const ImportAction &Action : ImportActions) {
+      StringRef FromFile = Action.FromFilename, ToFile = Action.ToFilename;
+      GenASTsIfNeeded(FromFile);
+      GenASTsIfNeeded(ToFile);
+
+      ASTUnit *From = AllASTs[FromFile].get();
+      ASTUnit *To = AllASTs[ToFile].get();
+
+      // Create a new importer if needed.
+      std::unique_ptr<ASTImporter> &ImporterRef = Importers[{From, To}];
+      if (!ImporterRef)
+        ImporterRef.reset(new ASTImporter(
+            To->getASTContext(), To->getFileManager(), From->getASTContext(),
+            From->getFileManager(), false));
+
+      // Find the declaration and import it.
+      auto FoundDecl = match(Action.ImportPredicate.bind(DeclToImportID),
+                             From->getASTContext());
+      EXPECT_TRUE(FoundDecl.size() == 1);
+      const Decl *ToImport = selectFirst<Decl>(DeclToImportID, FoundDecl);
+      auto Imported = importNode(From, To, *ImporterRef, ToImport);
+      EXPECT_TRUE(Imported);
+    }
+
+    // Find the declaration and import it.
+    auto FoundDecl = match(FinalSelectPredicate.bind(DeclToVerifyID),
+                           AllASTs[FileForFinalCheck]->getASTContext());
+    EXPECT_TRUE(FoundDecl.size() == 1);
+    const Decl *ToVerify = selectFirst<Decl>(DeclToVerifyID, FoundDecl);
+    MatchVerifier<Decl> Verifier;
+    EXPECT_TRUE(
+        Verifier.match(ToVerify, BindableMatcher<Decl>(VerificationMatcher)));
+  }
+};
 
 // This class provides generic methods to write tests which can check internal
 // attributes of AST nodes like getPreviousDecl(), isVirtual(), etc.  Also,
 // this fixture makes it possible to import from several "From" contexts.
-class ASTImporterTestBase : public ::testing::TestWithParam<ArgVector> {
+class ASTImporterTestBase : public ParameterizedTestsFixture {
 
   const char *const InputFileName = "input.cc";
   const char *const OutputFileName = "output.cc";
@@ -188,17 +313,6 @@
   // We may have several From context but only one To context.
   std::unique_ptr<ASTUnit> ToAST;
 
-  // Returns the argument vector used for a specific language, this set
-  // can be tweaked by the test parameters.
-  ArgVector getArgVectorForLanguage(Language Lang) {
-    ArgVector Args = getBasicRunOptionsForLanguage(Lang);
-    ArgVector ExtraArgs = GetParam();
-    for (const auto& Arg : ExtraArgs) {
-      Args.push_back(Arg);
-    }
-    return Args;
-  }
-
   // Creates an AST both for the From and To source code and imports the Decl
   // of the identifier into the To context.
   // Must not be called more than once within the same test.
@@ -308,124 +422,11 @@
   }
 };
 
+struct ImportExpr : TestImportBase {};
+struct ImportType : TestImportBase {};
+struct ImportDecl: TestImportBase {};
 
-struct ImportAction {
-  StringRef FromFilename;
-  StringRef ToFilename;
-  // FIXME: Generalize this to support other node kinds.
-  BindableMatcher<Decl> ImportPredicate;
-
-  ImportAction(StringRef FromFilename, StringRef ToFilename,
-               DeclarationMatcher ImportPredicate)
-      : FromFilename(FromFilename), ToFilename(ToFilename),
-        ImportPredicate(ImportPredicate) {}
-
-  ImportAction(StringRef FromFilename, StringRef ToFilename,
-               const std::string &DeclName)
-      : FromFilename(FromFilename), ToFilename(ToFilename),
-        ImportPredicate(namedDecl(hasName(DeclName))) {}
-};
-
-using SingleASTUnitForAllOpts = std::vector<std::unique_ptr<ASTUnit>>;
-using AllASTUnitsForAllOpts = StringMap<SingleASTUnitForAllOpts>;
-
-struct CodeEntry {
-  std::string CodeSample;
-  Language Lang;
-
-  /// Builds N copies of ASTUnits for each potential compile options set
-  /// for further import actions. N is equal to size of this option set.
-  SingleASTUnitForAllOpts createASTUnits(StringRef FileName) const {
-    auto RunOpts = getRunOptionsForLanguage(Lang);
-    size_t NumOpts = RunOpts.size();
-    SingleASTUnitForAllOpts ResultASTs(NumOpts);
-    for (size_t CompileOpt = 0; CompileOpt < NumOpts; ++CompileOpt) {
-      auto AST = tooling::buildASTFromCodeWithArgs(
-          CodeSample, RunOpts[CompileOpt], FileName);
-      EXPECT_TRUE(AST.get());
-      ResultASTs[CompileOpt] = std::move(AST);
-    }
-    return ResultASTs;
-  }
-};
-
-using CodeFiles = StringMap<CodeEntry>;
-
-/// Test an arbitrary sequence of imports for a set of given in-memory files.
-/// The verification is done by running VerificationMatcher against a specified
-/// AST node inside of one of given files.
-/// \param CodeSamples Map whose key is the file name and the value is the file
-/// content.
-/// \param ImportActions Sequence of imports. Each import in sequence
-/// specifies "from file" and "to file" and a matcher that is used for
-/// searching a declaration for import in "from file".
-/// \param FileForFinalCheck Name of virtual file for which the final check is
-/// applied.
-/// \param FinalSelectPredicate Matcher that specifies the AST node in the
-/// FileForFinalCheck for which the verification will be done.
-/// \param VerificationMatcher Matcher that will be used for verification after
-/// all imports in sequence are done.
-void testImportSequence(const CodeFiles &CodeSamples,
-                        const std::vector<ImportAction> &ImportActions,
-                        StringRef FileForFinalCheck,
-                        BindableMatcher<Decl> FinalSelectPredicate,
-                        BindableMatcher<Decl> VerificationMatcher) {
-  AllASTUnitsForAllOpts AllASTUnits;
-  using ImporterKey = std::pair<const ASTUnit *, const ASTUnit *>;
-  llvm::DenseMap<ImporterKey, std::unique_ptr<ASTImporter>> Importers;
-
-  auto GenASTsIfNeeded = [&AllASTUnits, &CodeSamples](StringRef Filename) {
-    if (!AllASTUnits.count(Filename)) {
-      auto Found = CodeSamples.find(Filename);
-      assert(Found != CodeSamples.end() && "Wrong file for import!");
-      AllASTUnits[Filename] = Found->getValue().createASTUnits(Filename);
-    }
-  };
-
-  size_t NumCompileOpts = 0;
-  for (const ImportAction &Action : ImportActions) {
-    StringRef FromFile = Action.FromFilename, ToFile = Action.ToFilename;
-    GenASTsIfNeeded(FromFile);
-    GenASTsIfNeeded(ToFile);
-    NumCompileOpts = AllASTUnits[FromFile].size();
-
-    for (size_t CompileOpt = 0; CompileOpt < NumCompileOpts; ++CompileOpt) {
-      ASTUnit *From = AllASTUnits[FromFile][CompileOpt].get();
-      ASTUnit *To = AllASTUnits[ToFile][CompileOpt].get();
-
-      // Create a new importer if needed.
-      std::unique_ptr<ASTImporter> &ImporterRef = Importers[{From, To}];
-      if (!ImporterRef)
-        ImporterRef.reset(new ASTImporter(
-            To->getASTContext(), To->getFileManager(), From->getASTContext(),
-            From->getFileManager(), false));
-
-      // Find the declaration and import it.
-      auto FoundDecl = match(Action.ImportPredicate.bind(DeclToImportID),
-                             From->getASTContext());
-      EXPECT_TRUE(FoundDecl.size() == 1);
-      const Decl *ToImport = selectFirst<Decl>(DeclToImportID, FoundDecl);
-      auto Imported = importNode(From, To, *ImporterRef, ToImport);
-      EXPECT_TRUE(Imported);
-    }
-  }
-
-  // NOTE: We don't do cross-option import check here due to fast growth of
-  // potential option sets.
-  for (size_t CompileOpt = 0; CompileOpt < NumCompileOpts; ++CompileOpt) {
-    // Find the declaration and import it.
-    auto FoundDecl =
-        match(FinalSelectPredicate.bind(DeclToVerifyID),
-              AllASTUnits[FileForFinalCheck][CompileOpt]->getASTContext());
-    EXPECT_TRUE(FoundDecl.size() == 1);
-    const Decl *ToVerify = selectFirst<Decl>(DeclToVerifyID, FoundDecl);
-    MatchVerifier<Decl> Verifier;
-    EXPECT_TRUE(Verifier.match(ToVerify,
-                               BindableMatcher<Decl>(VerificationMatcher)));
-  }
-}
-
-TEST(ImportExpr, ImportStringLiteral) {
+TEST_P(ImportExpr, ImportStringLiteral) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { \"foo\"; }",
              Lang_CXX, "", Lang_CXX, Verifier,
@@ -456,7 +457,7 @@
                          asString("const char [7]"))))))));
 }
 
-TEST(ImportExpr, ImportGNUNullExpr) {
+TEST_P(ImportExpr, ImportGNUNullExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { __null; }",
              Lang_CXX, "", Lang_CXX, Verifier,
@@ -468,7 +469,7 @@
                        hasType(isInteger())))))));
 }
 
-TEST(ImportExpr, ImportCXXNullPtrLiteralExpr) {
+TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { nullptr; }",
              Lang_CXX11, "", Lang_CXX11, Verifier,
@@ -480,7 +481,7 @@
 }
 
 
-TEST(ImportExpr, ImportFloatinglLiteralExpr) {
+TEST_P(ImportExpr, ImportFloatinglLiteralExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { 1.0; }",
              Lang_C, "", Lang_C, Verifier,
@@ -502,7 +503,7 @@
                         hasType(asString("float"))))))));
 }
 
-TEST(ImportExpr, ImportCompoundLiteralExpr) {
+TEST_P(ImportExpr, ImportCompoundLiteralExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() {"
              "  struct s { int x; long y; unsigned z; }; "
@@ -526,7 +527,7 @@
                          ))))))));
 }
 
-TEST(ImportExpr, ImportCXXThisExpr) {
+TEST_P(ImportExpr, ImportCXXThisExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("class declToImport { void f() { this; } };",
              Lang_CXX, "", Lang_CXX, Verifier,
@@ -540,7 +541,7 @@
                            asString("class declToImport *")))))))));
 }
 
-TEST(ImportExpr, ImportAtomicExpr) {
+TEST_P(ImportExpr, ImportAtomicExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { int *ptr; __atomic_load_n(ptr, 1); }",
              Lang_C, "", Lang_C, Verifier,
@@ -551,7 +552,7 @@
                  has(integerLiteral(equals(1), hasType(asString("int"))))))))));
 }
 
-TEST(ImportExpr, ImportLabelDeclAndAddrLabelExpr) {
+TEST_P(ImportExpr, ImportLabelDeclAndAddrLabelExpr) {
   MatchVerifier<Decl> Verifier;
   testImport(
       "void declToImport() { loop: goto loop; &&loop; }", Lang_C, "", Lang_C,
@@ -567,7 +568,7 @@
   return Template && InnerMatcher.matches(*Template, Finder, Builder);
 }
 
-TEST(ImportExpr, ImportParenListExpr) {
+TEST_P(ImportExpr, ImportParenListExpr) {
   MatchVerifier<Decl> Verifier;
   testImport(
       "template<typename T> class dummy { void f() { dummy X(*this); } };"
@@ -584,15 +585,15 @@
                           hasUnaryOperand(cxxThisExpr())))))))))))))))))))))));
 }
 
-TEST(ImportExpr, ImportSwitch) {
+TEST_P(ImportExpr, ImportSwitch) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { int b; switch (b) { case 1: break; } }",
              Lang_C, "", Lang_C, Verifier,
              functionDecl(hasBody(compoundStmt(
                  has(switchStmt(has(compoundStmt(has(caseStmt())))))))));
 }
 
-TEST(ImportExpr, ImportStmtExpr) {
+TEST_P(ImportExpr, ImportStmtExpr) {
   MatchVerifier<Decl> Verifier;
   // NOTE: has() ignores implicit casts, using hasDescendant() to match it
   testImport(
@@ -622,7 +623,7 @@
                         )))))))))));
 }
 
-TEST(ImportExpr, ImportConditionalOperator) {
+TEST_P(ImportExpr, ImportConditionalOperator) {
   MatchVerifier<Decl> Verifier;
   testImport(
     "void declToImport() { true ? 1 : -5; }",
@@ -639,7 +640,7 @@
                 )))))));
 }
 
-TEST(ImportExpr, ImportBinaryConditionalOperator) {
+TEST_P(ImportExpr, ImportBinaryConditionalOperator) {
   MatchVerifier<Decl> Verifier;
   testImport(
     "void declToImport() { 1 ?: -5; }", Lang_CXX, "", Lang_CXX, Verifier,
@@ -663,7 +664,7 @@
                 ))))));
 }
 
-TEST(ImportExpr, ImportDesignatedInitExpr) {
+TEST_P(ImportExpr, ImportDesignatedInitExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() {"
              "  struct point { double x; double y; };"
@@ -706,7 +707,7 @@
 }
 
 
-TEST(ImportExpr, ImportPredefinedExpr) {
+TEST_P(ImportExpr, ImportPredefinedExpr) {
   MatchVerifier<Decl> Verifier;
   // __func__ expands as StringLiteral("declToImport")
   testImport("void declToImport() { __func__; }",
@@ -724,7 +725,7 @@
                              asString("const char [13]"))))))))));
 }
 
-TEST(ImportExpr, ImportInitListExpr) {
+TEST_P(ImportExpr, ImportInitListExpr) {
   MatchVerifier<Decl> Verifier;
   testImport(
     "void declToImport() {"
@@ -761,7 +762,7 @@
 
 const internal::VariadicDynCastAllOfMatcher<Expr, VAArgExpr> vaArgExpr;
 
-TEST(ImportExpr, ImportVAArgExpr) {
+TEST_P(ImportExpr, ImportVAArgExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport(__builtin_va_list list, ...) {"
              "  (void)__builtin_va_arg(list, int); }",
@@ -775,7 +776,7 @@
                          vaArgExpr())))))));
 }
 
-TEST(ImportExpr, CXXTemporaryObjectExpr) {
+TEST_P(ImportExpr, CXXTemporaryObjectExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("struct C {};"
              "void declToImport() { C c = C(); }",
@@ -786,7 +787,7 @@
                          has(cxxTemporaryObjectExpr())))))))))))))))));
 }
 
-TEST(ImportType, ImportAtomicType) {
+TEST_P(ImportType, ImportAtomicType) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { typedef _Atomic(int) a_int; }",
              Lang_CXX11, "", Lang_CXX11, Verifier,
@@ -800,16 +801,16 @@
                            has(atomicType())))))))));
 }
 
-TEST(ImportDecl, ImportFunctionTemplateDecl) {
+TEST_P(ImportDecl, ImportFunctionTemplateDecl) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename T> void declToImport() { };", Lang_CXX, "",
              Lang_CXX, Verifier, functionTemplateDecl());
 }
 
 const internal::VariadicDynCastAllOfMatcher<Expr, CXXDependentScopeMemberExpr>
     cxxDependentScopeMemberExpr;
 
-TEST(ImportExpr, ImportCXXDependentScopeMemberExpr) {
+TEST_P(ImportExpr, ImportCXXDependentScopeMemberExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename T> struct C { T t; };"
              "template <typename T> void declToImport() {"
@@ -831,7 +832,7 @@
                  has(compoundStmt(has(cxxDependentScopeMemberExpr())))))));
 }
 
-TEST(ImportType, ImportTypeAliasTemplate) {
+TEST_P(ImportType, ImportTypeAliasTemplate) {
   MatchVerifier<Decl> Verifier;
   testImport(
       "template <int K>"
@@ -848,7 +849,7 @@
 const internal::VariadicDynCastAllOfMatcher<Decl, VarTemplateSpecializationDecl>
     varTemplateSpecializationDecl;
 
-TEST(ImportDecl, ImportVarTemplate) {
+TEST_P(ImportDecl, ImportVarTemplate) {
   MatchVerifier<Decl> Verifier;
   testImport(
       "template <typename T>"
@@ -861,7 +862,7 @@
               hasName("pi"), unless(varTemplateSpecializationDecl()))))))));
 }
 
-TEST(ImportType, ImportPackExpansion) {
+TEST_P(ImportType, ImportPackExpansion) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename... Args>"
              "struct dummy {"
@@ -885,7 +886,7 @@
                                             DependentTemplateSpecializationType>
     dependentTemplateSpecializationType;
 
-TEST(ImportType, ImportDependentTemplateSpecialization) {
+TEST_P(ImportType, ImportDependentTemplateSpecialization) {
   MatchVerifier<Decl> Verifier;
   testImport("template<typename T>"
              "struct A;"
@@ -901,7 +902,7 @@
 const internal::VariadicDynCastAllOfMatcher<Stmt, SizeOfPackExpr>
     sizeOfPackExpr;
 
-TEST(ImportExpr, ImportSizeOfPackExpr) {
+TEST_P(ImportExpr, ImportSizeOfPackExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename... Ts>"
              "void declToImport() {"
@@ -934,7 +935,7 @@
 //  will generate TypeTraitExpr <...> 'int'
 const internal::VariadicDynCastAllOfMatcher<Stmt, TypeTraitExpr> typeTraitExpr;
 
-TEST(ImportExpr, ImportTypeTraitExpr) {
+TEST_P(ImportExpr, ImportTypeTraitExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { "
              "  __builtin_types_compatible_p(int, int);"
@@ -949,7 +950,7 @@
 
 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTypeidExpr> cxxTypeidExpr;
 
-TEST(ImportExpr, ImportCXXTypeidExpr) {
+TEST_P(ImportExpr, ImportCXXTypeidExpr) {
   MatchVerifier<Decl> Verifier;
   testImport(
       "namespace std { class type_info {}; }"
@@ -965,7 +966,7 @@
               hasName("b"), hasInitializer(hasDescendant(cxxTypeidExpr()))))));
 }
 
-TEST(ImportExpr, ImportTypeTraitExprValDep) {
+TEST_P(ImportExpr, ImportTypeTraitExprValDep) {
   MatchVerifier<Decl> Verifier;
   testImport("template<typename T> struct declToImport {"
              "  void m() { __is_pod(T); }"
@@ -988,7 +989,7 @@
 const internal::VariadicDynCastAllOfMatcher<Expr, CXXPseudoDestructorExpr>
     cxxPseudoDestructorExpr;
 
-TEST(ImportExpr, ImportCXXPseudoDestructorExpr) {
+TEST_P(ImportExpr, ImportCXXPseudoDestructorExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("typedef int T;"
              "void declToImport(int *p) {"
@@ -1000,7 +1001,7 @@
                  callExpr(has(cxxPseudoDestructorExpr())))))));
 }
 
-TEST(ImportDecl, ImportUsingDecl) {
+TEST_P(ImportDecl, ImportUsingDecl) {
   MatchVerifier<Decl> Verifier;
   testImport("namespace foo { int bar; }"
              "void declToImport() { using foo::bar; }",
@@ -1027,15 +1028,15 @@
 const internal::VariadicDynCastAllOfMatcher<Decl,
                                             UsingShadowDecl> usingShadowDecl;
 
-TEST(ImportDecl, ImportUsingShadowDecl) {
+TEST_P(ImportDecl, ImportUsingShadowDecl) {
   MatchVerifier<Decl> Verifier;
   testImport("namespace foo { int bar; }"
              "namespace declToImport { using foo::bar; }",
              Lang_CXX, "", Lang_CXX, Verifier,
              namespaceDecl(has(usingShadowDecl())));
 }
 
-TEST(ImportExpr, ImportUnresolvedLookupExpr) {
+TEST_P(ImportExpr, ImportUnresolvedLookupExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("template<typename T> int foo();"
              "template <typename T> void declToImport() {"
@@ -1048,7 +1049,7 @@
                  has(compoundStmt(has(unresolvedLookupExpr())))))));
 }
 
-TEST(ImportExpr, ImportCXXUnresolvedConstructExpr) {
+TEST_P(ImportExpr, ImportCXXUnresolvedConstructExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename T> struct C { T t; };"
              "template <typename T> void declToImport() {"
@@ -1073,7 +1074,7 @@
 /// Check that function "declToImport()" (which is the templated function
 /// for corresponding FunctionTemplateDecl) is not added into DeclContext.
 /// Same for class template declarations.
-TEST(ImportDecl, ImportTemplatedDeclForTemplate) {
+TEST_P(ImportDecl, ImportTemplatedDeclForTemplate) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename T> void declToImport() { T a = 1; }"
              "void instantiate() { declToImport<int>(); }",
@@ -1087,7 +1088,7 @@
                  unless(has(cxxRecordDecl(hasName("declToImport"))))))));
 }
 
-TEST(ImportExpr, CXXOperatorCallExpr) {
+TEST_P(ImportExpr, CXXOperatorCallExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("class declToImport {"
              "  void f() { *this = declToImport(); }"
@@ -1097,7 +1098,7 @@
                  has(exprWithCleanups(has(cxxOperatorCallExpr())))))))));
 }
 
-TEST(ImportExpr, DependentSizedArrayType) {
+TEST_P(ImportExpr, DependentSizedArrayType) {
   MatchVerifier<Decl> Verifier;
   testImport("template<typename T, int Size> class declToImport {"
              "  T data[Size];"
@@ -1607,10 +1608,6 @@
                     .match(ToTU, classTemplateSpecializationDecl()));
 }
 
-INSTANTIATE_TEST_CASE_P(
-    ParameterizedTests, ASTImporterTestBase,
-    ::testing::Values(ArgVector(), ArgVector{"-fdelayed-template-parsing"}),);
-
 struct ImportFunctions : ASTImporterTestBase {};
 
 TEST_P(ImportFunctions,
@@ -1835,18 +1832,14 @@
   EXPECT_TRUE(To->isVirtual());
 }
 
-INSTANTIATE_TEST_CASE_P(
-    ParameterizedTests, ImportFunctions,
-    ::testing::Values(ArgVector(), ArgVector{"-fdelayed-template-parsing"}),);
-
 AST_MATCHER_P(TagDecl, hasTypedefForAnonDecl, Matcher<TypedefNameDecl>,
               InnerMatcher) {
   if (auto *Typedef = Node.getTypedefNameForAnonDecl())
     return InnerMatcher.matches(*Typedef, Finder, Builder);
   return false;
 }
 
-TEST(ImportDecl, ImportEnumSequential) {
+TEST_P(ImportDecl, ImportEnumSequential) {
   CodeFiles Samples{{"main.c",
                      {"void foo();"
                       "void moo();"
@@ -1888,7 +1881,7 @@
 const internal::VariadicDynCastAllOfMatcher<Expr, DependentScopeDeclRefExpr>
     dependentScopeDeclRefExpr;
 
-TEST(ImportExpr, DependentScopeDeclRefExpr) {
+TEST_P(ImportExpr, DependentScopeDeclRefExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename T> struct S { static T foo; };"
              "template <typename T> void declToImport() {"
@@ -1914,7 +1907,7 @@
 const internal::VariadicDynCastAllOfMatcher<Type, DependentNameType>
     dependentNameType;
 
-TEST(ImportExpr, DependentNameType) {
+TEST_P(ImportExpr, DependentNameType) {
   MatchVerifier<Decl> Verifier;
   testImport("template <typename T> struct declToImport {"
              "  typedef typename T::type dependent_name;"
@@ -1927,7 +1920,7 @@
 const internal::VariadicDynCastAllOfMatcher<Expr, UnresolvedMemberExpr>
     unresolvedMemberExpr;
 
-TEST(ImportExpr, UnresolvedMemberExpr) {
+TEST_P(ImportExpr, UnresolvedMemberExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("struct S { template <typename T> void mem(); };"
              "template <typename U> void declToImport() {"
@@ -1969,9 +1962,23 @@
   EXPECT_FALSE(NS->containsDecl(Spec));
 }
 
-INSTANTIATE_TEST_CASE_P(
-    ParameterizedTests, DeclContextTest,
-    ::testing::Values(ArgVector(), ArgVector{"-fdelayed-template-parsing"}),);
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, DeclContextTest,
+                        ::testing::Values(ArgVector()), );
+
+auto DefaultTestValuesForRunOptions = ::testing::Values(
+    ArgVector(),
+    ArgVector{"-fdelayed-template-parsing"},
+    ArgVector{"-fms-compatibility"},
+    ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"});
+
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
+                        DefaultTestValuesForRunOptions, );
+
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterTestBase,
+                        DefaultTestValuesForRunOptions, );
+
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctions,
+                        DefaultTestValuesForRunOptions, );
 
 } // end namespace ast_matchers
 } // end namespace clang
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to