Skip to content

Commit 57011a5

Browse files
committed
draft up test suite for adjustCommandLine
1 parent 4d13984 commit 57011a5

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Vinnie Falco ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#include "lib/ConfigImpl.hpp"
12+
#include "lib/MrDocsCompilationDatabase.hpp"
13+
#include "lib/SingleFileDB.hpp"
14+
#include <mrdocs/Support/Algorithm.hpp>
15+
#include <mrdocs/Support/Path.hpp>
16+
#include <mrdocs/Support/ThreadPool.hpp>
17+
#include <test_suite/test_suite.hpp>
18+
19+
namespace clang {
20+
namespace mrdocs {
21+
22+
/** Compilation database for a single .cpp file.
23+
*/
24+
class SingleFileTestDB
25+
: public tooling::CompilationDatabase
26+
{
27+
tooling::CompileCommand cc_;
28+
29+
public:
30+
explicit
31+
SingleFileTestDB(
32+
tooling::CompileCommand cc)
33+
: cc_(std::move(cc))
34+
{}
35+
36+
std::vector<tooling::CompileCommand>
37+
getCompileCommands(
38+
llvm::StringRef FilePath) const override
39+
{
40+
if (FilePath != cc_.Filename)
41+
return {};
42+
return { cc_ };
43+
}
44+
45+
std::vector<std::string>
46+
getAllFiles() const override
47+
{
48+
return { cc_.Filename };
49+
}
50+
51+
std::vector<tooling::CompileCommand>
52+
getAllCompileCommands() const override
53+
{
54+
return { cc_ };
55+
}
56+
};
57+
58+
struct MrDocsCompilationDatabase_test
59+
{
60+
Config::Settings fileSettings_;
61+
ThreadPool threadPool_;
62+
ReferenceDirectories dirs_;
63+
64+
std::shared_ptr<ConfigImpl const> config_ =
65+
ConfigImpl::load(fileSettings_, dirs_, threadPool_).value();
66+
67+
auto adjustCompileCommand(std::vector<std::string> CommandLine) const
68+
{
69+
tooling::CompileCommand cc;
70+
cc.Directory = ".";
71+
cc.Filename = "test.cpp"; // file does not exist
72+
cc.CommandLine = std::move(CommandLine);
73+
cc.CommandLine.push_back(cc.Filename);
74+
cc.Heuristic = "unit test";
75+
76+
// Create an adjusted MrDocsDatabase
77+
std::unordered_map<std::string, std::vector<std::string>> defaultIncludePaths;
78+
MrDocsCompilationDatabase compilations(
79+
llvm::StringRef(cc.Directory), SingleFileTestDB(cc), config_, defaultIncludePaths);
80+
return compilations.getCompileCommands(cc.Filename).front().CommandLine;
81+
}
82+
83+
void testClangCL()
84+
{
85+
auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++latest"});
86+
BOOST_TEST_GE(adjusted.size(), 2);
87+
BOOST_TEST_EQ(adjusted[0], "clang");
88+
BOOST_TEST(contains(adjusted, "-std=c++23"));
89+
}
90+
91+
void run()
92+
{
93+
testClangCL();
94+
}
95+
};
96+
97+
TEST_SUITE(
98+
MrDocsCompilationDatabase_test,
99+
"clang.mrdocs.MrDocsCompilationDatabase");
100+
101+
} // mrdocs
102+
} // clang

0 commit comments

Comments
 (0)