clang-tools 23.0.0git
ConfigCompileTests.cpp
Go to the documentation of this file.
1//===-- ConfigCompileTests.cpp --------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Config.h"
10#include "ConfigFragment.h"
11#include "ConfigTesting.h"
12#include "Diagnostics.h"
13#include "Feature.h"
14#include "TestFS.h"
15#include "clang/Basic/DiagnosticSema.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/Path.h"
18#include "llvm/Support/SourceMgr.h"
19#include "gmock/gmock.h"
20#include "gtest/gtest.h"
21#include <optional>
22#include <string>
23
24namespace clang {
25namespace clangd {
26namespace config {
27namespace {
28using ::testing::AllOf;
29using ::testing::Contains;
30using ::testing::ElementsAre;
31using ::testing::IsEmpty;
32using ::testing::SizeIs;
33using ::testing::StartsWith;
34using ::testing::UnorderedElementsAre;
35
36class ConfigCompileTests : public ::testing::Test {
37protected:
38 CapturedDiags Diags;
39 Config Conf;
40 Fragment Frag;
41 Params Parm;
42
43 bool compileAndApply() {
44 Conf = Config();
45 Diags.Diagnostics.clear();
46 auto Compiled = std::move(Frag).compile(Diags.callback());
47 return Compiled(Parm, Conf);
48 }
49};
50
51TEST_F(ConfigCompileTests, Condition) {
52 // No condition.
53 Frag = {};
54 Frag.CompileFlags.Add.emplace_back("X");
55 EXPECT_TRUE(compileAndApply()) << "Empty config";
56 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
57 EXPECT_THAT(Conf.CompileFlags.Edits, SizeIs(1));
58
59 // Regex with no file.
60 Frag = {};
61 Frag.If.PathMatch.emplace_back("fo*");
62 EXPECT_FALSE(compileAndApply());
63 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
64 EXPECT_THAT(Conf.CompileFlags.Edits, SizeIs(0));
65
66 // Following tests have a file path set.
67 Parm.Path = "bar";
68
69 // Non-matching regex.
70 Frag = {};
71 Frag.If.PathMatch.emplace_back("fo*");
72 EXPECT_FALSE(compileAndApply());
73 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
74
75 // Matching regex.
76 Frag = {};
77 Frag.If.PathMatch.emplace_back("fo*");
78 Frag.If.PathMatch.emplace_back("ba*r");
79 EXPECT_TRUE(compileAndApply());
80 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
81
82 // Excluded regex.
83 Frag = {};
84 Frag.If.PathMatch.emplace_back("b.*");
85 Frag.If.PathExclude.emplace_back(".*r");
86 EXPECT_FALSE(compileAndApply()) << "Included but also excluded";
87 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
88
89 // Invalid regex.
90 Frag = {};
91 Frag.If.PathMatch.emplace_back("**]@theu");
92 EXPECT_TRUE(compileAndApply());
93 EXPECT_THAT(Diags.Diagnostics, SizeIs(1));
94 EXPECT_THAT(Diags.Diagnostics.front().Message, StartsWith("Invalid regex"));
95
96 // Valid regex and unknown key.
97 Frag = {};
98 Frag.If.HasUnrecognizedCondition = true;
99 Frag.If.PathMatch.emplace_back("ba*r");
100 EXPECT_FALSE(compileAndApply());
101 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
102
103 // Only matches case-insensitively.
104 Frag = {};
105 Frag.If.PathMatch.emplace_back("B.*R");
106 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
107#ifdef CLANGD_PATH_CASE_INSENSITIVE
108 EXPECT_TRUE(compileAndApply());
109#else
110 EXPECT_FALSE(compileAndApply());
111#endif
112
113 Frag = {};
114 Frag.If.PathExclude.emplace_back("B.*R");
115 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
116#ifdef CLANGD_PATH_CASE_INSENSITIVE
117 EXPECT_FALSE(compileAndApply());
118#else
119 EXPECT_TRUE(compileAndApply());
120#endif
121}
122
123TEST_F(ConfigCompileTests, CompileCommands) {
124 Frag.CompileFlags.Compiler.emplace("tpc.exe");
125 Frag.CompileFlags.Add.emplace_back("-foo");
126 Frag.CompileFlags.Remove.emplace_back("--include-directory=");
127 std::vector<std::string> Argv = {"clang", "-I", "bar/", "--", "a.cc"};
128 EXPECT_TRUE(compileAndApply());
129 EXPECT_THAT(Conf.CompileFlags.Edits, SizeIs(3));
130 for (auto &Edit : Conf.CompileFlags.Edits)
131 Edit(Argv);
132 EXPECT_THAT(Argv, ElementsAre("tpc.exe", "-foo", "--", "a.cc"));
133}
134
135TEST_F(ConfigCompileTests, CompilationDatabase) {
136 Frag.CompileFlags.CompilationDatabase.emplace("None");
137 EXPECT_TRUE(compileAndApply());
138 EXPECT_EQ(Conf.CompileFlags.CDBSearch.Policy,
140
141 Frag.CompileFlags.CompilationDatabase.emplace("Ancestors");
142 EXPECT_TRUE(compileAndApply());
143 EXPECT_EQ(Conf.CompileFlags.CDBSearch.Policy,
145
146 // Relative path not allowed without directory set.
147 Frag.CompileFlags.CompilationDatabase.emplace("Something");
148 EXPECT_TRUE(compileAndApply());
149 EXPECT_EQ(Conf.CompileFlags.CDBSearch.Policy,
151 << "default value";
152 EXPECT_THAT(Diags.Diagnostics,
153 ElementsAre(diagMessage(
154 "CompilationDatabase must be an absolute path, because this "
155 "fragment is not associated with any directory.")));
156
157 // Relative path allowed if directory is set.
158 Frag.Source.Directory = testRoot();
159 EXPECT_TRUE(compileAndApply());
160 EXPECT_EQ(Conf.CompileFlags.CDBSearch.Policy,
162 EXPECT_EQ(Conf.CompileFlags.CDBSearch.FixedCDBPath, testPath("Something"));
163 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
164
165 // Absolute path allowed.
166 Frag.Source.Directory.clear();
167 Frag.CompileFlags.CompilationDatabase.emplace(testPath("Something2"));
168 EXPECT_TRUE(compileAndApply());
169 EXPECT_EQ(Conf.CompileFlags.CDBSearch.Policy,
171 EXPECT_EQ(Conf.CompileFlags.CDBSearch.FixedCDBPath, testPath("Something2"));
172 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
173}
174
175TEST_F(ConfigCompileTests, Index) {
176 Frag.Index.Background.emplace("Skip");
177 EXPECT_TRUE(compileAndApply());
178 EXPECT_EQ(Conf.Index.Background, Config::BackgroundPolicy::Skip);
179
180 Frag = {};
181 Frag.Index.Background.emplace("Foo");
182 EXPECT_TRUE(compileAndApply());
183 EXPECT_EQ(Conf.Index.Background, Config::BackgroundPolicy::Build)
184 << "by default";
185 EXPECT_THAT(
186 Diags.Diagnostics,
187 ElementsAre(diagMessage(
188 "Invalid Background value 'Foo'. Valid values are Build, Skip.")));
189}
190
191TEST_F(ConfigCompileTests, PathSpecMatch) {
192 auto BarPath = llvm::sys::path::convert_to_slash(testPath("foo/bar.h"));
193 Parm.Path = BarPath;
194
195 struct {
196 std::string Directory;
197 std::string PathSpec;
198 bool ShouldMatch;
199 } Cases[] = {
200 {
201 // Absolute path matches.
202 "",
203 llvm::sys::path::convert_to_slash(testPath("foo/bar.h")),
204 true,
205 },
206 {
207 // Absolute path fails.
208 "",
209 llvm::sys::path::convert_to_slash(testPath("bar/bar.h")),
210 false,
211 },
212 {
213 // Relative should fail to match as /foo/bar.h doesn't reside under
214 // /baz/.
215 testPath("baz"),
216 "bar\\.h",
217 false,
218 },
219 {
220 // Relative should pass with /foo as directory.
221 testPath("foo"),
222 "bar\\.h",
223 true,
224 },
225 };
226
227 // PathMatch
228 for (const auto &Case : Cases) {
229 Frag = {};
230 Frag.If.PathMatch.emplace_back(Case.PathSpec);
231 Frag.Source.Directory = Case.Directory;
232 EXPECT_EQ(compileAndApply(), Case.ShouldMatch);
233 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
234 }
235
236 // PathEclude
237 for (const auto &Case : Cases) {
238 SCOPED_TRACE(Case.Directory);
239 SCOPED_TRACE(Case.PathSpec);
240 Frag = {};
241 Frag.If.PathExclude.emplace_back(Case.PathSpec);
242 Frag.Source.Directory = Case.Directory;
243 EXPECT_NE(compileAndApply(), Case.ShouldMatch);
244 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
245 }
246}
247
248TEST_F(ConfigCompileTests, DiagnosticsIncludeCleaner) {
249 // Defaults to Strict.
250 EXPECT_TRUE(compileAndApply());
251 EXPECT_EQ(Conf.Diagnostics.UnusedIncludes, Config::IncludesPolicy::Strict);
252
253 Frag = {};
254 Frag.Diagnostics.UnusedIncludes.emplace("None");
255 EXPECT_TRUE(compileAndApply());
256 EXPECT_EQ(Conf.Diagnostics.UnusedIncludes, Config::IncludesPolicy::None);
257
258 Frag = {};
259 Frag.Diagnostics.UnusedIncludes.emplace("Strict");
260 EXPECT_TRUE(compileAndApply());
261 EXPECT_EQ(Conf.Diagnostics.UnusedIncludes, Config::IncludesPolicy::Strict);
262
263 Frag = {};
264 EXPECT_TRUE(Conf.Diagnostics.Includes.IgnoreHeader.empty())
265 << Conf.Diagnostics.Includes.IgnoreHeader.size();
266 Frag.Diagnostics.Includes.IgnoreHeader.push_back(
267 Located<std::string>("foo.h"));
268 Frag.Diagnostics.Includes.IgnoreHeader.push_back(
269 Located<std::string>(".*inc"));
270 EXPECT_TRUE(compileAndApply());
271 auto HeaderFilter = [this](llvm::StringRef Path) {
272 for (auto &Filter : Conf.Diagnostics.Includes.IgnoreHeader) {
273 if (Filter(Path))
274 return true;
275 }
276 return false;
277 };
278 EXPECT_TRUE(HeaderFilter("foo.h"));
279 EXPECT_FALSE(HeaderFilter("bar.h"));
280
281 Frag = {};
282 EXPECT_FALSE(Conf.Diagnostics.Includes.AnalyzeAngledIncludes);
283 Frag.Diagnostics.Includes.AnalyzeAngledIncludes = true;
284 EXPECT_TRUE(compileAndApply());
285 EXPECT_TRUE(Conf.Diagnostics.Includes.AnalyzeAngledIncludes);
286}
287
288TEST_F(ConfigCompileTests, DiagnosticSuppression) {
289 Frag.Diagnostics.Suppress.emplace_back("bugprone-use-after-move");
290 Frag.Diagnostics.Suppress.emplace_back("unreachable-code");
291 Frag.Diagnostics.Suppress.emplace_back("-Wunused-variable");
292 Frag.Diagnostics.Suppress.emplace_back("typecheck_bool_condition");
293 Frag.Diagnostics.Suppress.emplace_back("err_unexpected_friend");
294 Frag.Diagnostics.Suppress.emplace_back("warn_alloca");
295 EXPECT_TRUE(compileAndApply());
296 EXPECT_THAT(Conf.Diagnostics.Suppress.keys(),
297 UnorderedElementsAre("bugprone-use-after-move",
298 "unreachable-code", "unused-variable",
299 "typecheck_bool_condition",
300 "unexpected_friend", "warn_alloca"));
301 Frag.Diagnostics.Suppress.emplace_back("*");
302 EXPECT_TRUE(compileAndApply());
303 EXPECT_TRUE(Conf.Diagnostics.SuppressAll);
304 EXPECT_THAT(Conf.Diagnostics.Suppress, IsEmpty());
305}
306
307TEST_F(ConfigCompileTests, Tidy) {
308 auto &Tidy = Frag.Diagnostics.ClangTidy;
309 Tidy.Add.emplace_back("bugprone-use-after-move");
310 Tidy.Add.emplace_back("llvm-*");
311 Tidy.Remove.emplace_back("llvm-include-order");
312 Tidy.Remove.emplace_back("readability-*");
313 Tidy.CheckOptions.emplace_back(std::make_pair(
314 std::string("example-check.ExampleOption"), std::string("0")));
315 EXPECT_TRUE(compileAndApply());
316 EXPECT_EQ(Conf.Diagnostics.ClangTidy.CheckOptions.size(), 1U);
317 EXPECT_EQ(Conf.Diagnostics.ClangTidy.CheckOptions.lookup(
318 "example-check.ExampleOption"),
319 "0");
320#if CLANGD_TIDY_CHECKS
321 EXPECT_EQ(
322 Conf.Diagnostics.ClangTidy.Checks,
323 "bugprone-use-after-move,llvm-*,-llvm-include-order,-readability-*");
324 EXPECT_THAT(Diags.Diagnostics, IsEmpty());
325#else // !CLANGD_TIDY_CHECKS
326 EXPECT_EQ(Conf.Diagnostics.ClangTidy.Checks, "llvm-*,-readability-*");
327 EXPECT_THAT(
328 Diags.Diagnostics,
329 ElementsAre(
330 diagMessage(
331 "clang-tidy check 'bugprone-use-after-move' was not found"),
332 diagMessage("clang-tidy check 'llvm-include-order' was not found")));
333#endif
334}
335
336TEST_F(ConfigCompileTests, TidyBadChecks) {
337 auto &Tidy = Frag.Diagnostics.ClangTidy;
338 Tidy.Add.emplace_back("unknown-check");
339 Tidy.Remove.emplace_back("*");
340 Tidy.Remove.emplace_back("llvm-includeorder");
341 EXPECT_TRUE(compileAndApply());
342 // Ensure bad checks are stripped from the glob.
343 EXPECT_EQ(Conf.Diagnostics.ClangTidy.Checks, "-*");
344 EXPECT_THAT(
345 Diags.Diagnostics,
346 ElementsAre(
347 AllOf(diagMessage("clang-tidy check 'unknown-check' was not found"),
348 diagKind(llvm::SourceMgr::DK_Warning)),
349 AllOf(
350 diagMessage("clang-tidy check 'llvm-includeorder' was not found"),
351 diagKind(llvm::SourceMgr::DK_Warning))));
352}
353
354TEST_F(ConfigCompileTests, ExternalServerNeedsTrusted) {
356 External.Server.emplace("xxx");
357 Frag.Index.External = std::move(External);
358 compileAndApply();
359 EXPECT_THAT(
360 Diags.Diagnostics,
361 ElementsAre(diagMessage(
362 "Remote index may not be specified by untrusted configuration. "
363 "Copy this into user config to use it.")));
364 EXPECT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
365}
366
367TEST_F(ConfigCompileTests, ExternalBlockWarnOnMultipleSource) {
368 Frag.Source.Trusted = true;
370 External.File.emplace("");
371 External.Server.emplace("");
372 Frag.Index.External = std::move(External);
373 compileAndApply();
374#ifdef CLANGD_ENABLE_REMOTE
375 EXPECT_THAT(
376 Diags.Diagnostics,
377 Contains(
378 AllOf(diagMessage("Exactly one of File, Server or None must be set."),
379 diagKind(llvm::SourceMgr::DK_Error))));
380#else
381 ASSERT_TRUE(Conf.Index.External.hasValue());
382 EXPECT_EQ(Conf.Index.External->Kind, Config::ExternalIndexSpec::File);
383#endif
384}
385
386TEST_F(ConfigCompileTests, ExternalBlockDisableWithNone) {
387 compileAndApply();
388 EXPECT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
389
391 External.IsNone = true;
392 Frag.Index.External = std::move(External);
393 compileAndApply();
394 EXPECT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
395}
396
397TEST_F(ConfigCompileTests, ExternalBlockErrOnNoSource) {
398 Frag.Index.External.emplace(Fragment::IndexBlock::ExternalBlock{});
399 compileAndApply();
400 EXPECT_THAT(
401 Diags.Diagnostics,
402 Contains(
403 AllOf(diagMessage("Exactly one of File, Server or None must be set."),
404 diagKind(llvm::SourceMgr::DK_Error))));
405}
406
407TEST_F(ConfigCompileTests, ExternalBlockDisablesBackgroundIndex) {
408 auto BazPath = testPath("foo/bar/baz.h", llvm::sys::path::Style::posix);
409 Parm.Path = BazPath;
410 Frag.Index.Background.emplace("Build");
412 External.File.emplace(testPath("foo"));
413 External.MountPoint.emplace(
414 testPath("foo/bar", llvm::sys::path::Style::posix));
415 Frag.Index.External = std::move(External);
416 compileAndApply();
417 EXPECT_EQ(Conf.Index.Background, Config::BackgroundPolicy::Skip);
418}
419
420TEST_F(ConfigCompileTests, ExternalBlockMountPoint) {
421 auto GetFrag = [](llvm::StringRef Directory,
422 std::optional<const char *> MountPoint) {
423 Fragment Frag;
424 Frag.Source.Directory = Directory.str();
426 External.File.emplace(testPath("foo"));
427 if (MountPoint)
428 External.MountPoint.emplace(*MountPoint);
429 Frag.Index.External = std::move(External);
430 return Frag;
431 };
432
433 auto BarPath = testPath("foo/bar.h", llvm::sys::path::Style::posix);
434 BarPath = llvm::sys::path::convert_to_slash(BarPath);
435 Parm.Path = BarPath;
436 // Non-absolute MountPoint without a directory raises an error.
437 Frag = GetFrag("", "foo");
438 compileAndApply();
439 ASSERT_THAT(
440 Diags.Diagnostics,
441 ElementsAre(
442 AllOf(diagMessage("MountPoint must be an absolute path, because this "
443 "fragment is not associated with any directory."),
444 diagKind(llvm::SourceMgr::DK_Error))));
445 EXPECT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
446
447 auto FooPath = testPath("foo/", llvm::sys::path::Style::posix);
448 FooPath = llvm::sys::path::convert_to_slash(FooPath);
449 // Ok when relative.
450 Frag = GetFrag(testRoot(), "foo/");
451 compileAndApply();
452 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
453 ASSERT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::File);
454 EXPECT_THAT(Conf.Index.External.MountPoint, FooPath);
455
456 // None defaults to ".".
457 Frag = GetFrag(FooPath, std::nullopt);
458 compileAndApply();
459 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
460 ASSERT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::File);
461 EXPECT_THAT(Conf.Index.External.MountPoint, FooPath);
462
463 // Without a file, external index is empty.
464 Parm.Path = "";
465 Frag = GetFrag("", FooPath.c_str());
466 compileAndApply();
467 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
468 ASSERT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
469
470 // File outside MountPoint, no index.
471 auto BazPath = testPath("bar/baz.h", llvm::sys::path::Style::posix);
472 BazPath = llvm::sys::path::convert_to_slash(BazPath);
473 Parm.Path = BazPath;
474 Frag = GetFrag("", FooPath.c_str());
475 compileAndApply();
476 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
477 ASSERT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
478
479 // File under MountPoint, index should be set.
480 BazPath = testPath("foo/baz.h", llvm::sys::path::Style::posix);
481 BazPath = llvm::sys::path::convert_to_slash(BazPath);
482 Parm.Path = BazPath;
483 Frag = GetFrag("", FooPath.c_str());
484 compileAndApply();
485 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
486 ASSERT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::File);
487 EXPECT_THAT(Conf.Index.External.MountPoint, FooPath);
488
489 // Only matches case-insensitively.
490 BazPath = testPath("fOo/baz.h", llvm::sys::path::Style::posix);
491 BazPath = llvm::sys::path::convert_to_slash(BazPath);
492 Parm.Path = BazPath;
493
494 FooPath = testPath("FOO/", llvm::sys::path::Style::posix);
495 FooPath = llvm::sys::path::convert_to_slash(FooPath);
496 Frag = GetFrag("", FooPath.c_str());
497 compileAndApply();
498 ASSERT_THAT(Diags.Diagnostics, IsEmpty());
499#ifdef CLANGD_PATH_CASE_INSENSITIVE
500 ASSERT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::File);
501 EXPECT_THAT(Conf.Index.External.MountPoint, FooPath);
502#else
503 ASSERT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
504#endif
505}
506
507TEST_F(ConfigCompileTests, AllScopes) {
508 // Defaults to true.
509 EXPECT_TRUE(compileAndApply());
510 EXPECT_TRUE(Conf.Completion.AllScopes);
511
512 Frag = {};
513 Frag.Completion.AllScopes = false;
514 EXPECT_TRUE(compileAndApply());
515 EXPECT_FALSE(Conf.Completion.AllScopes);
516
517 Frag = {};
518 Frag.Completion.AllScopes = true;
519 EXPECT_TRUE(compileAndApply());
520 EXPECT_TRUE(Conf.Completion.AllScopes);
521}
522
523TEST_F(ConfigCompileTests, Style) {
524 Frag = {};
525 Frag.Style.FullyQualifiedNamespaces.push_back(std::string("foo"));
526 Frag.Style.FullyQualifiedNamespaces.push_back(std::string("bar"));
527 EXPECT_TRUE(compileAndApply());
528 EXPECT_THAT(Conf.Style.FullyQualifiedNamespaces, ElementsAre("foo", "bar"));
529
530 {
531 Frag = {};
532 EXPECT_TRUE(Conf.Style.QuotedHeaders.empty())
533 << Conf.Style.QuotedHeaders.size();
534 Frag.Style.QuotedHeaders.push_back(Located<std::string>("foo.h"));
535 Frag.Style.QuotedHeaders.push_back(Located<std::string>(".*inc"));
536 EXPECT_TRUE(compileAndApply());
537 auto HeaderFilter = [this](llvm::StringRef Path) {
538 for (auto &Filter : Conf.Style.QuotedHeaders) {
539 if (Filter(Path))
540 return true;
541 }
542 return false;
543 };
544 EXPECT_TRUE(HeaderFilter("foo.h"));
545 EXPECT_TRUE(HeaderFilter("prefix/foo.h"));
546 EXPECT_FALSE(HeaderFilter("bar.h"));
547 EXPECT_FALSE(HeaderFilter("foo.h/bar.h"));
548 }
549
550 {
551 Frag = {};
552 EXPECT_TRUE(Conf.Style.AngledHeaders.empty())
553 << Conf.Style.AngledHeaders.size();
554 Frag.Style.AngledHeaders.push_back(Located<std::string>("foo.h"));
555 Frag.Style.AngledHeaders.push_back(Located<std::string>(".*inc"));
556 EXPECT_TRUE(compileAndApply());
557 auto HeaderFilter = [this](llvm::StringRef Path) {
558 for (auto &Filter : Conf.Style.AngledHeaders) {
559 if (Filter(Path))
560 return true;
561 }
562 return false;
563 };
564 EXPECT_TRUE(HeaderFilter("foo.h"));
565 EXPECT_FALSE(HeaderFilter("bar.h"));
566 }
567}
568} // namespace
569} // namespace config
570} // namespace clangd
571} // namespace clang
static cl::opt< std::string > Directory(cl::Positional, cl::Required, cl::desc("<Search Root Directory>"))
static cl::opt< std::string > Config("config", desc(R"( Specifies a configuration in YAML/JSON format: -config="{Checks:' *', CheckOptions:{x:y}}" When the value is empty, clang-tidy will attempt to find a file named .clang-tidy for each source file in its parent directories. )"), cl::init(""), cl::cat(ClangTidyCategory))
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition AST.cpp:44
TEST_F(BackgroundIndexTest, NoCrashOnErrorFile)
std::string testPath(PathRef File, llvm::sys::path::Style Style)
Definition TestFS.cpp:93
llvm::ArrayRef< std::function< bool(llvm::StringRef)> > HeaderFilter
Definition Headers.h:36
std::string Path
A typedef to represent a file path.
Definition Path.h:26
const char * testRoot()
Definition TestFS.cpp:85
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
@ Strict
Diagnose missing and unused includes.
Definition Config.h:98
An external index uses data source outside of clangd itself.
std::optional< Located< std::string > > Server
Address and port number for a clangd-index-server.
Located< bool > IsNone
Whether the block is explicitly set to None.
std::optional< Located< std::string > > File
Path to an index file generated by clangd-indexer.
std::string Directory
Absolute path to directory the fragment is associated with.
A chunk of configuration obtained from a config file, LSP, or elsewhere.
An entity written in config along, with its optional location in the file.