Skip to content

Commit 64f0462

Browse files
committed
[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.
1 parent 1b209ff commit 64f0462

File tree

6 files changed

+88
-47
lines changed

6 files changed

+88
-47
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1-
from lldbsuite.test import lldbinline
2-
from lldbsuite.test import decorators
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
35

4-
lldbinline.MakeInlineTest(
5-
__file__, globals(), [
6-
decorators.expectedFailureAll(
7-
compiler="gcc")])
6+
class TestCase(TestBase):
7+
8+
mydir = TestBase.compute_mydir(__file__)
9+
10+
@expectedFailureAll(compiler="gcc")
11+
def test(self):
12+
self.build()
13+
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
14+
15+
# Test non-type template parameter packs.
16+
self.expect_expr("myC", result_type="C<int, 16, 32>", result_children=[
17+
ValueCheck(name="C<int, 16>", children=[
18+
ValueCheck(name="member", value="64")
19+
])
20+
])
21+
self.expect_expr("myLesserC.argsAre_16_32()", result_value="false")
22+
self.expect_expr("myC.argsAre_16_32()", result_value="true")
23+
24+
# Test type template parameter packs.
25+
self.expect_expr("myD", result_type="D<int, int, bool>", result_children=[
26+
ValueCheck(name="D<int, int>", children=[
27+
ValueCheck(name="member", value="64")
28+
])
29+
])
30+
self.expect_expr("myLesserD.argsAre_Int_bool()", result_value="false")
31+
self.expect_expr("myD.argsAre_Int_bool()", result_value="true")
32+
33+
# Disabling until we do template lookup correctly: http://lists.llvm.org/pipermail/lldb-commits/Week-of-Mon-20180507/040689.html
34+
# FIXME: Rewrite this with expect_expr
35+
# self.expect("expression -- C<int, 16>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
36+
# self.expect("expression -- C<int, 16, 32>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
37+
# self.expect("expression -- D<int, int>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
38+
# self.expect("expression -- D<int, int, bool>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,43 @@
11
template <class T, int... Args> struct C {
22
T member;
3-
bool isSixteenThirtyTwo() { return false; }
3+
bool argsAre_16_32() { return false; }
44
};
55

66
template <> struct C<int, 16> {
77
int member;
8-
bool isSixteenThirtyTwo() { return false; }
8+
bool argsAre_16_32() { return false; }
99
};
1010

1111
template <> struct C<int, 16, 32> : C<int, 16> {
12-
bool isSixteenThirtyTwo() { return true; }
12+
bool argsAre_16_32() { return true; }
1313
};
1414

1515
template <class T, typename... Args> struct D {
1616
T member;
17-
bool isIntBool() { return false; }
17+
bool argsAre_Int_bool() { return false; }
1818
};
1919

2020
template <> struct D<int, int> {
2121
int member;
22-
bool isIntBool() { return false; }
22+
bool argsAre_Int_bool() { return false; }
2323
};
2424

2525
template <> struct D<int, int, bool> : D<int, int> {
26-
bool isIntBool() { return true; }
26+
bool argsAre_Int_bool() { return true; }
2727
};
2828

29-
template<int Size> struct array {
30-
int Arr[Size];
31-
array() {}
32-
};
33-
34-
int main (int argc, char const *argv[])
35-
{
36-
C<int,16,32> myC;
37-
C<int,16> myLesserC;
38-
myC.member = 64;
39-
(void)C<int,16,32>().isSixteenThirtyTwo();
40-
(void)C<int,16>().isSixteenThirtyTwo();
41-
(void)(myC.member != 64); //% self.expect("expression -- myC", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["64"])
42-
//% self.expect("expression -- myLesserC.isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
43-
//% self.expect("expression -- myC.isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
44-
45-
// Disabling until we do template lookup correctly: http://lists.llvm.org/pipermail/lldb-commits/Week-of-Mon-20180507/040689.html
46-
//#% self.expect("expression -- C<int, 16>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
47-
//#% self.expect("expression -- C<int, 16, 32>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
48-
49-
D<int,int,bool> myD;
50-
D<int,int> myLesserD;
51-
myD.member = 64;
52-
(void)D<int,int,bool>().isIntBool();
53-
(void)D<int,int>().isIntBool(); //% self.expect("expression -- myD", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["64"])
54-
//% self.expect("expression -- myLesserD.isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
55-
//% self.expect("expression -- myD.isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
56-
57-
// See comment above.
58-
//#% self.expect("expression -- D<int, int>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])
59-
//#% self.expect("expression -- D<int, int, bool>().isIntBool()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["true"])
60-
61-
array<3> myArray; //% self.expect("expression -- myArray", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["Arr"])
62-
63-
return 1;
29+
int main(int argc, char const *argv[]) {
30+
C<int, 16, 32> myC;
31+
C<int, 16> myLesserC;
32+
myC.member = 64;
33+
(void)C<int, 16, 32>().argsAre_16_32();
34+
(void)C<int, 16>().argsAre_16_32();
35+
(void)(myC.member != 64);
36+
D<int, int, bool> myD;
37+
D<int, int> myLesserD;
38+
myD.member = 64;
39+
(void)D<int, int, bool>().argsAre_Int_bool();
40+
(void)D<int, int>().argsAre_Int_bool();
41+
42+
return 0; // break here
6443
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
class TestCase(TestBase):
7+
8+
mydir = TestBase.compute_mydir(__file__)
9+
10+
@no_debug_info_test
11+
def test(self):
12+
self.build()
13+
self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
14+
15+
self.expect_expr("myArray", result_type="array<3>", result_children=[
16+
ValueCheck(name="Arr", type="int [3]")
17+
])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
template <int Size> struct array {
2+
int Arr[Size];
3+
array() {}
4+
};
5+
6+
array<3> myArray;
7+
8+
int main() {}

0 commit comments

Comments
 (0)