[llvm-branch-commits] [lldb] 64f0462 - [lldb][NFC] Modernize and cleanup TestClassTemplateParameterPack

Raphael Isemann via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 1 06:58:04 PST 2020


Author: Raphael Isemann
Date: 2020-12-01T15:53:40+01:00
New Revision: 64f04629aa7a4cf9d2deb725683959faa4a857fe

URL: https://github.com/llvm/llvm-project/commit/64f04629aa7a4cf9d2deb725683959faa4a857fe
DIFF: https://github.com/llvm/llvm-project/commit/64f04629aa7a4cf9d2deb725683959faa4a857fe.diff

LOG: [lldb][NFC] Modernize and cleanup TestClassTemplateParameterPack

* Un-inline the test.
* Use expect_expr everywhere and also check all involved types.
* Clang-format the test sources.
* Explain what we're actually testing with the 'C' and 'D' templates.
* Split out the non-template-parameter-pack part of the test into its own small test.

Added: 
    lldb/test/API/lang/cpp/class-template-parameter-pack/Makefile
    lldb/test/API/lang/cpp/non-type-template-param/Makefile
    lldb/test/API/lang/cpp/non-type-template-param/TestAlignAsBaseClass.py
    lldb/test/API/lang/cpp/non-type-template-param/main.cpp

Modified: 
    lldb/test/API/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py
    lldb/test/API/lang/cpp/class-template-parameter-pack/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/lang/cpp/class-template-parameter-pack/Makefile b/lldb/test/API/lang/cpp/class-template-parameter-pack/Makefile
new file mode 100644
index 000000000000..99998b20bcb0
--- /dev/null
+++ b/lldb/test/API/lang/cpp/class-template-parameter-pack/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules

diff  --git a/lldb/test/API/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py b/lldb/test/API/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py
index 7e67f73b7092..e0497b62f55c 100644
--- a/lldb/test/API/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py
+++ b/lldb/test/API/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py
@@ -1,7 +1,38 @@
-from lldbsuite.test import lldbinline
-from lldbsuite.test import decorators
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
 
-lldbinline.MakeInlineTest(
-    __file__, globals(), [
-        decorators.expectedFailureAll(
-            compiler="gcc")])
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @expectedFailureAll(compiler="gcc")
+    def test(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
+
+        # Test non-type template parameter packs.
+        self.expect_expr("myC", result_type="C<int, 16, 32>", result_children=[
+            ValueCheck(name="C<int, 16>", children=[
+                ValueCheck(name="member", value="64")
+            ])
+        ])
+        self.expect_expr("myLesserC.argsAre_16_32()", result_value="false")
+        self.expect_expr("myC.argsAre_16_32()", result_value="true")
+
+        # Test type template parameter packs.
+        self.expect_expr("myD", result_type="D<int, int, bool>", result_children=[
+            ValueCheck(name="D<int, int>", children=[
+                ValueCheck(name="member", value="64")
+            ])
+        ])
+        self.expect_expr("myLesserD.argsAre_Int_bool()", result_value="false")
+        self.expect_expr("myD.argsAre_Int_bool()", result_value="true")
+
+        # Disabling until we do template lookup correctly: http://lists.llvm.org/pipermail/lldb-commits/Week-of-Mon-20180507/040689.html
+        # FIXME: Rewrite this with expect_expr
+        # self.expect("expression -- C<int, 16>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
+        # self.expect("expression -- C<int, 16, 32>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
+        # self.expect("expression -- D<int, int>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
+        # self.expect("expression -- D<int, int, bool>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])

diff  --git a/lldb/test/API/lang/cpp/class-template-parameter-pack/main.cpp b/lldb/test/API/lang/cpp/class-template-parameter-pack/main.cpp
index 82f09a1f268c..8bb0a42b58a3 100644
--- a/lldb/test/API/lang/cpp/class-template-parameter-pack/main.cpp
+++ b/lldb/test/API/lang/cpp/class-template-parameter-pack/main.cpp
@@ -1,64 +1,43 @@
 template <class T, int... Args> struct C {
   T member;
-  bool isSixteenThirtyTwo() { return false; }
+  bool argsAre_16_32() { return false; }
 };
 
 template <> struct C<int, 16> {
   int member;
-  bool isSixteenThirtyTwo() { return false; }
+  bool argsAre_16_32() { return false; }
 };
 
 template <> struct C<int, 16, 32> : C<int, 16> {
-  bool isSixteenThirtyTwo() { return true; }
+  bool argsAre_16_32() { return true; }
 };
 
 template <class T, typename... Args> struct D {
   T member;
-  bool isIntBool() { return false; }
+  bool argsAre_Int_bool() { return false; }
 };
 
 template <> struct D<int, int> {
   int member;
-  bool isIntBool() { return false; }
+  bool argsAre_Int_bool() { return false; }
 };
 
 template <> struct D<int, int, bool> : D<int, int> {
-  bool isIntBool() { return true; }
+  bool argsAre_Int_bool() { return true; }
 };
 
-template<int Size> struct array {
-  int Arr[Size];
-  array() {}
-};
-
-int main (int argc, char const *argv[])
-{
-    C<int,16,32> myC;
-    C<int,16> myLesserC;
-    myC.member = 64;
-    (void)C<int,16,32>().isSixteenThirtyTwo();
-    (void)C<int,16>().isSixteenThirtyTwo();
-    (void)(myC.member != 64);   //% self.expect("expression -- myC", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["64"])
-                                //% self.expect("expression -- myLesserC.isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
-                                //% self.expect("expression -- myC.isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
-
-                                // Disabling until we do template lookup correctly: http://lists.llvm.org/pipermail/lldb-commits/Week-of-Mon-20180507/040689.html
-                                //#% self.expect("expression -- C<int, 16>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
-                                //#% self.expect("expression -- C<int, 16, 32>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
-   
-    D<int,int,bool> myD;
-    D<int,int> myLesserD;
-    myD.member = 64;
-    (void)D<int,int,bool>().isIntBool();
-    (void)D<int,int>().isIntBool(); //% self.expect("expression -- myD", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["64"])
-                                //% self.expect("expression -- myLesserD.isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
-                                //% self.expect("expression -- myD.isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
-
-                                // See comment above.
-                                //#% self.expect("expression -- D<int, int>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
-                                //#% self.expect("expression -- D<int, int, bool>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
-
-    array<3> myArray; //% self.expect("expression -- myArray", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["Arr"])
-
-    return 1;
+int main(int argc, char const *argv[]) {
+  C<int, 16, 32> myC;
+  C<int, 16> myLesserC;
+  myC.member = 64;
+  (void)C<int, 16, 32>().argsAre_16_32();
+  (void)C<int, 16>().argsAre_16_32();
+  (void)(myC.member != 64);
+  D<int, int, bool> myD;
+  D<int, int> myLesserD;
+  myD.member = 64;
+  (void)D<int, int, bool>().argsAre_Int_bool();
+  (void)D<int, int>().argsAre_Int_bool();
+
+  return 0; // break here
 }

diff  --git a/lldb/test/API/lang/cpp/non-type-template-param/Makefile b/lldb/test/API/lang/cpp/non-type-template-param/Makefile
new file mode 100644
index 000000000000..99998b20bcb0
--- /dev/null
+++ b/lldb/test/API/lang/cpp/non-type-template-param/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules

diff  --git a/lldb/test/API/lang/cpp/non-type-template-param/TestAlignAsBaseClass.py b/lldb/test/API/lang/cpp/non-type-template-param/TestAlignAsBaseClass.py
new file mode 100644
index 000000000000..12cf5bd3ec03
--- /dev/null
+++ b/lldb/test/API/lang/cpp/non-type-template-param/TestAlignAsBaseClass.py
@@ -0,0 +1,17 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test(self):
+        self.build()
+        self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+
+        self.expect_expr("myArray", result_type="array<3>", result_children=[
+            ValueCheck(name="Arr", type="int [3]")
+        ])

diff  --git a/lldb/test/API/lang/cpp/non-type-template-param/main.cpp b/lldb/test/API/lang/cpp/non-type-template-param/main.cpp
new file mode 100644
index 000000000000..9f508e931a1b
--- /dev/null
+++ b/lldb/test/API/lang/cpp/non-type-template-param/main.cpp
@@ -0,0 +1,8 @@
+template <int Size> struct array {
+  int Arr[Size];
+  array() {}
+};
+
+array<3> myArray;
+
+int main() {}


        


More information about the llvm-branch-commits mailing list