forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibclang_parser.cpp
More file actions
102 lines (86 loc) · 2.76 KB
/
Copy pathlibclang_parser.cpp
File metadata and controls
102 lines (86 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (C) 2017-2018 Jonathan Müller <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include <catch.hpp>
#include <cppast/libclang_parser.hpp>
#include <fstream>
using namespace cppast;
libclang_compilation_database get_database(const char* json)
{
std::ofstream file("compile_commands.json");
file << json;
file.close();
return libclang_compilation_database(".");
}
void require_flags(const libclang_compile_config& config, const char* flags)
{
std::string result;
auto config_flags = detail::libclang_compile_config_access::flags(config);
// skip first 4, those are the default options
for (auto iter = config_flags.begin() + 4; iter != config_flags.end(); ++iter)
result += *iter + ' ';
result.pop_back();
REQUIRE(result == flags);
}
TEST_CASE("libclang_compile_config")
{
// only test database parser
#ifdef _WIN32
auto json = R"([
{
"directory": "C:/foo",
"command": "/usr/bin/clang++ -Irelative -IC:/absolute -DA=FOO -DB(X)=X -c -o a.o a.cpp",
"file": "a.cpp"
},
{
"directory": "C:/bar/",
"command": "/usr/bin/clang++ -Irelative -DA=FOO -c -o b.o b.cpp",
"file": "C:/b.cpp",
},
{
"directory": "C:/bar/",
"command": "/usr/bin/clang++ -IC:/absolute -DB(X)=X -c -o b.o b.cpp",
"file": "C:/b.cpp",
},
{
"directory": "",
"command": "/usr/bin/clang++ -std=c++14 -fms-extensions -fms-compatibility -c -o c.o c.cpp",
"file": "C:/c.cpp",
}
])";
# define CPPAST_DETAIL_DRIVE "C:"
#else
auto json = R"([
{
"directory": "/foo",
"command": "/usr/bin/clang++ -Irelative -I/absolute -DA=FOO -DB(X)=X -c -o a.o a.cpp",
"file": "a.cpp"
},
{
"directory": "/bar/",
"command": "/usr/bin/clang++ -Irelative -DA=FOO -c -o b.o b.cpp",
"file": "/b.cpp",
},
{
"directory": "/bar/",
"command": "/usr/bin/clang++ -I/absolute -DB(X)=X -c -o b.o b.cpp",
"file": "/b.cpp",
},
{
"directory": "",
"command": "/usr/bin/clang++ -std=c++14 -fms-extensions -fms-compatibility -c -o c.o c.cpp",
"file": "/c.cpp",
}
])";
# define CPPAST_DETAIL_DRIVE
#endif
auto database = get_database(json);
libclang_compile_config a(database, CPPAST_DETAIL_DRIVE "/foo/a.cpp");
require_flags(a, "-I" CPPAST_DETAIL_DRIVE "/foo/relative -I" CPPAST_DETAIL_DRIVE
"/absolute -DA=FOO -DB(X)=X");
libclang_compile_config b(database, CPPAST_DETAIL_DRIVE "/b.cpp");
require_flags(b, "-I" CPPAST_DETAIL_DRIVE "/bar/relative -DA=FOO -I" CPPAST_DETAIL_DRIVE
"/absolute -DB(X)=X");
libclang_compile_config c(database, CPPAST_DETAIL_DRIVE "/c.cpp");
require_flags(c, "-std=c++14 -fms-extensions -fms-compatibility");
}