Skip to content

Commit 3e95d3e

Browse files
committed
[lldb][test] Add tests for clang::PreferredNameAttr formatting
Add some tests to make sure we're formatting structures with preferred names correctly. Differential Revision: https://reviews.llvm.org/D145832 (cherry picked from commit 1eaf3b7)
1 parent 6c82678 commit 3e95d3e

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
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+
CXXFLAGS_EXTRAS := -std=c++20 -glldb
3+
include Makefile.rules
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Test formatting of types annotated with
3+
[[clang::preferred_name]] attributes.
4+
"""
5+
6+
import lldb
7+
import lldbsuite.test.lldbutil as lldbutil
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import decorators
10+
11+
12+
class TestPreferredName(TestBase):
13+
14+
def test_frame_var(self):
15+
self.build()
16+
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec("main.cpp"))
17+
18+
self.expect("frame variable barInt", substrs=["BarInt"])
19+
self.expect("frame variable barDouble", substrs=["BarDouble"])
20+
self.expect("frame variable barShort", substrs=["Bar<short>"])
21+
self.expect("frame variable barChar", substrs=["Bar<char>"])
22+
23+
self.expect("frame variable varInt", substrs=["BarInt"])
24+
self.expect("frame variable varDouble", substrs=["BarDouble"])
25+
self.expect("frame variable varShort", substrs=["Bar<short>"])
26+
self.expect("frame variable varChar", substrs=["Bar<char>"])
27+
self.expect("frame variable varFooInt", substrs=["Foo<BarInt>"])
28+
29+
def test_expr(self):
30+
self.build()
31+
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec("main.cpp"))
32+
33+
self.expect_expr("barInt", result_type="BarInt")
34+
self.expect_expr("barDouble", result_type="BarDouble")
35+
self.expect_expr("barShort", result_type="Bar<short>")
36+
self.expect_expr("barChar", result_type="Bar<char>")
37+
38+
self.expect_expr("varInt", result_type="BarInt")
39+
self.expect_expr("varDouble", result_type="BarDouble")
40+
self.expect_expr("varShort", result_type="Bar<short>")
41+
self.expect_expr("varChar", result_type="Bar<char>")
42+
self.expect_expr("varFooInt", result_type="Foo<BarInt>")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
template <typename T> struct Foo;
2+
3+
typedef Foo<int> BarInt;
4+
typedef Foo<double> BarDouble;
5+
6+
template <typename T> using Bar = Foo<T>;
7+
8+
template <typename T>
9+
struct [[clang::preferred_name(BarInt), clang::preferred_name(BarDouble),
10+
clang::preferred_name(Bar<short>), clang::preferred_name(Bar<short>),
11+
clang::preferred_name(Bar<double>),
12+
clang::preferred_name(Bar<char>)]] Foo{};
13+
14+
int main() {
15+
BarInt barInt;
16+
BarDouble barDouble;
17+
Bar<short> barShort;
18+
Bar<char> barChar;
19+
20+
Foo<int> varInt;
21+
Foo<double> varDouble;
22+
Foo<short> varShort;
23+
Foo<char> varChar;
24+
Foo<Foo<int>> varFooInt;
25+
return 0;
26+
}

0 commit comments

Comments
 (0)