9
9
#include " QueryParser.h"
10
10
#include " Query.h"
11
11
#include " QuerySession.h"
12
+ #include " clang/Tooling/NodeIntrospection.h"
12
13
#include " llvm/LineEditor/LineEditor.h"
13
14
#include " gtest/gtest.h"
14
15
@@ -59,6 +60,8 @@ TEST_F(QueryParserTest, Quit) {
59
60
}
60
61
61
62
TEST_F (QueryParserTest, Set) {
63
+
64
+ bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport ();
62
65
QueryRef Q = parse (" set" );
63
66
ASSERT_TRUE (isa<InvalidQuery>(Q));
64
67
EXPECT_EQ (" expected variable name" , cast<InvalidQuery>(Q)->ErrStr );
@@ -69,17 +72,27 @@ TEST_F(QueryParserTest, Set) {
69
72
70
73
Q = parse (" set output" );
71
74
ASSERT_TRUE (isa<InvalidQuery>(Q));
72
- EXPECT_EQ (" expected 'diag', 'print', 'detailed-ast' or 'dump', got ''" ,
73
- cast<InvalidQuery>(Q)->ErrStr );
75
+ if (HasIntrospection)
76
+ EXPECT_EQ (
77
+ " expected 'diag', 'print', 'detailed-ast', 'srcloc' or 'dump', got ''" ,
78
+ cast<InvalidQuery>(Q)->ErrStr );
79
+ else
80
+ EXPECT_EQ (" expected 'diag', 'print', 'detailed-ast' or 'dump', got ''" ,
81
+ cast<InvalidQuery>(Q)->ErrStr );
74
82
75
83
Q = parse (" set bind-root true foo" );
76
84
ASSERT_TRUE (isa<InvalidQuery>(Q));
77
85
EXPECT_EQ (" unexpected extra input: ' foo'" , cast<InvalidQuery>(Q)->ErrStr );
78
86
79
87
Q = parse (" set output foo" );
80
88
ASSERT_TRUE (isa<InvalidQuery>(Q));
81
- EXPECT_EQ (" expected 'diag', 'print', 'detailed-ast' or 'dump', got 'foo'" ,
82
- cast<InvalidQuery>(Q)->ErrStr );
89
+ if (HasIntrospection)
90
+ EXPECT_EQ (" expected 'diag', 'print', 'detailed-ast', 'srcloc' or 'dump', "
91
+ " got 'foo'" ,
92
+ cast<InvalidQuery>(Q)->ErrStr );
93
+ else
94
+ EXPECT_EQ (" expected 'diag', 'print', 'detailed-ast' or 'dump', got 'foo'" ,
95
+ cast<InvalidQuery>(Q)->ErrStr );
83
96
84
97
Q = parse (" set output dump" );
85
98
ASSERT_TRUE (isa<SetExclusiveOutputQuery >(Q));
@@ -217,19 +230,23 @@ TEST_F(QueryParserTest, Complete) {
217
230
EXPECT_EQ (" output " , Comps[0 ].TypedText );
218
231
EXPECT_EQ (" output" , Comps[0 ].DisplayText );
219
232
233
+ bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport ();
234
+
220
235
Comps = QueryParser::complete (" enable output " , 14 , QS);
221
- ASSERT_EQ (5u , Comps.size ());
236
+ ASSERT_EQ (HasIntrospection ? 5u : 4u , Comps.size ());
222
237
223
238
EXPECT_EQ (" diag " , Comps[0 ].TypedText );
224
239
EXPECT_EQ (" diag" , Comps[0 ].DisplayText );
225
240
EXPECT_EQ (" print " , Comps[1 ].TypedText );
226
241
EXPECT_EQ (" print" , Comps[1 ].DisplayText );
227
242
EXPECT_EQ (" detailed-ast " , Comps[2 ].TypedText );
228
243
EXPECT_EQ (" detailed-ast" , Comps[2 ].DisplayText );
229
- EXPECT_EQ (" srcloc " , Comps[3 ].TypedText );
230
- EXPECT_EQ (" srcloc" , Comps[3 ].DisplayText );
231
- EXPECT_EQ (" dump " , Comps[4 ].TypedText );
232
- EXPECT_EQ (" dump" , Comps[4 ].DisplayText );
244
+ if (HasIntrospection) {
245
+ EXPECT_EQ (" srcloc " , Comps[3 ].TypedText );
246
+ EXPECT_EQ (" srcloc" , Comps[3 ].DisplayText );
247
+ }
248
+ EXPECT_EQ (" dump " , Comps[HasIntrospection ? 4 : 3 ].TypedText );
249
+ EXPECT_EQ (" dump" , Comps[HasIntrospection ? 4 : 3 ].DisplayText );
233
250
234
251
Comps = QueryParser::complete (" set traversal " , 14 , QS);
235
252
ASSERT_EQ (2u , Comps.size ());
0 commit comments