[PATCH] D76497: [Syntax] Test both the default and windows target platforms in unittests

Marcel Hlopko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 20 07:32:42 PDT 2020


hlopko created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This increases the coverage for things that differ between Linux and Windows, such as -fdelayed-template-parsing. This would have prevented the rollback of https://reviews.llvm.org/D76346.

While at it, update -std=c++11 to c++17 for the test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76497

Files:
  clang/unittests/Tooling/Syntax/TreeTest.cpp


Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -47,7 +47,8 @@
 class SyntaxTreeTest : public ::testing::Test {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+  syntax::TranslationUnit *buildTree(llvm::StringRef Code,
+                                     StringRef Target = "x86_64-pc-linux-gnu") {
     // FIXME: this code is almost the identical to the one in TokensTest. Share
     //        it.
     class BuildSyntaxTree : public ASTConsumer {
@@ -98,9 +99,10 @@
     if (!Diags->getClient())
       Diags->setClient(new IgnoringDiagConsumer);
     // Prepare to run a compiler.
-    std::vector<const char *> Args = {"syntax-test", "-std=c++11",
-                                      "-fno-delayed-template-parsing",
-                                      "-fsyntax-only", FileName};
+    std::vector<const char *> Args = {
+        "syntax-test", FileName,  "-fsyntax-only",
+        "-std=c++17",  "-target", Target.data(),
+    };
     Invocation = createInvocationFromCommandLine(Args, Diags, FS);
     assert(Invocation);
     Invocation->getFrontendOpts().DisableFree = false;
@@ -121,14 +123,30 @@
     return Root;
   }
 
-  void expectTreeDumpEqual(StringRef code, StringRef tree) {
-    SCOPED_TRACE(code);
-
-    auto *Root = buildTree(code);
-    std::string Expected = tree.trim().str();
-    std::string Actual =
-        std::string(llvm::StringRef(Root->dump(*Arena)).trim());
-    EXPECT_EQ(Expected, Actual) << "the resulting dump is:\n" << Actual;
+  void expectTreeDumpEqual(StringRef Code, StringRef Tree,
+                           bool RunWithDelayedTemplateParsing = true) {
+    SCOPED_TRACE(Code);
+
+    std::string Expected = Tree.trim().str();
+
+    // We want to run the test with -fdelayed-template-parsing enabled and
+    // disabled, therefore we use these representative targets that differ in
+    // the default value.
+    // We are not passing -fdelayed-template-parsing directly but we are using
+    // the `-target` to improve coverage and discover differences in behavior
+    // early.
+    for (const StringRef Target :
+         {"x86_64-pc-linux-gnu", "x86_64-pc-win32-msvc"}) {
+      if (!RunWithDelayedTemplateParsing &&
+          Target.equals("x86_64-pc-win32-msvc")) {
+        continue;
+      }
+      auto *Root = buildTree(Code, Target);
+      std::string Actual = std::string(StringRef(Root->dump(*Arena)).trim());
+      EXPECT_EQ(Expected, Actual)
+          << "for target " << Target << " the resulting dump is:\n"
+          << Actual;
+    }
   }
 
   // Adds a file to the test VFS.
@@ -794,7 +812,10 @@
     `-CompoundStatement
       |-{
       `-}
-)txt");
+)txt",
+      // FIXME: Make this test work on windows by generating the expected Syntax
+      // tree when -fdelayed-template-parsing is active.
+      /*RunWithDelayedTemplateParsing=*/false);
 }
 
 TEST_F(SyntaxTreeTest, NestedTemplates) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76497.251632.patch
Type: text/x-patch
Size: 3120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200320/19174e05/attachment-0001.bin>


More information about the cfe-commits mailing list