Fix full path of includes
This commit is contained in:
parent
2ced972b9f
commit
c2b86d1cad
7 changed files with 113 additions and 16 deletions
|
|
@ -115,7 +115,7 @@ b
|
|||
REQUIRE(include.target().name() == include.name());
|
||||
REQUIRE(include.include_kind() == cppast::cpp_include_kind::local);
|
||||
REQUIRE(include.target().get(idx).empty());
|
||||
REQUIRE(include.full_path() == "cpp_include_directive-header.hpp");
|
||||
REQUIRE(include.full_path() == "./cpp_include_directive-header.hpp");
|
||||
}
|
||||
else
|
||||
REQUIRE(false);
|
||||
|
|
@ -129,7 +129,7 @@ b
|
|||
REQUIRE(include.include_kind() == cppast::cpp_include_kind::local);
|
||||
REQUIRE(
|
||||
equal_ref(idx, include.target(), cpp_file_ref(cpp_entity_id(""), "header_a.hpp")));
|
||||
REQUIRE(include.full_path() == "header_a.hpp");
|
||||
REQUIRE(include.full_path() == "./header_a.hpp");
|
||||
}
|
||||
else
|
||||
REQUIRE(false);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,15 @@ TEST_CASE("preprocessor escaped character", "[!hide][clang4]")
|
|||
libclang_compile_config config;
|
||||
config.set_flags(cpp_standard::cpp_latest);
|
||||
|
||||
SECTION("fast")
|
||||
{
|
||||
config.fast_preprocessing(true);
|
||||
}
|
||||
SECTION("normal")
|
||||
{
|
||||
config.fast_preprocessing(false);
|
||||
}
|
||||
|
||||
auto preprocessed = detail::preprocess(config, "ppec.cpp", default_logger().get());
|
||||
REQUIRE(preprocessed.includes.size() == 1);
|
||||
REQUIRE(preprocessed.includes[0].file_name == "ppec.hpp");
|
||||
|
|
@ -37,6 +46,16 @@ TEST_CASE("preprocessor escaped character", "[!hide][clang4]")
|
|||
|
||||
TEST_CASE("preprocessing use external macro")
|
||||
{
|
||||
bool fast_preprocessing = false;
|
||||
SECTION("fast_preprocessing")
|
||||
{
|
||||
fast_preprocessing = true;
|
||||
}
|
||||
SECTION("normal")
|
||||
{
|
||||
fast_preprocessing = false;
|
||||
}
|
||||
|
||||
auto file = parse({}, "preprocessing_external_macro.cpp", R"(
|
||||
#include <cmath>
|
||||
#ifdef _GLIBCXX_RELEASE
|
||||
|
|
@ -46,7 +65,7 @@ TEST_CASE("preprocessing use external macro")
|
|||
auto result = NAN;
|
||||
|
||||
#endif
|
||||
)");
|
||||
)", fast_preprocessing);
|
||||
|
||||
test_visit<cpp_variable>(*file, [&](const cpp_variable&) {});
|
||||
}
|
||||
|
|
@ -91,6 +110,16 @@ struct foo {};
|
|||
|
||||
TEST_CASE("preprocessor line numbers")
|
||||
{
|
||||
bool fast_preprocessing = false;
|
||||
SECTION("fast_preprocessing")
|
||||
{
|
||||
fast_preprocessing = true;
|
||||
}
|
||||
SECTION("normal")
|
||||
{
|
||||
fast_preprocessing = false;
|
||||
}
|
||||
|
||||
auto code = R"(/// 1
|
||||
|
||||
#include <iostream>
|
||||
|
|
@ -130,7 +159,7 @@ lines
|
|||
/// 37
|
||||
)";
|
||||
|
||||
auto file = parse({}, "preprocessor_line_numbers.cpp", code);
|
||||
auto file = parse({}, "preprocessor_line_numbers.cpp", code, fast_preprocessing);
|
||||
for (auto& comment : file->unmatched_comments())
|
||||
{
|
||||
if (comment.content[0] != '\n')
|
||||
|
|
@ -188,6 +217,16 @@ with indent */
|
|||
|
||||
TEST_CASE("comment matching")
|
||||
{
|
||||
bool fast_preprocessing = false;
|
||||
SECTION("fast_preprocessing")
|
||||
{
|
||||
fast_preprocessing = true;
|
||||
}
|
||||
SECTION("normal")
|
||||
{
|
||||
fast_preprocessing = false;
|
||||
}
|
||||
|
||||
auto code = R"(
|
||||
/// u
|
||||
|
||||
|
|
@ -243,7 +282,7 @@ template <typename T/**/>
|
|||
void j();
|
||||
)";
|
||||
|
||||
auto file = parse({}, "comment-matching.cpp", code);
|
||||
auto file = parse({}, "comment-matching.cpp", code, fast_preprocessing);
|
||||
visit(*file, [&](const cpp_entity& e, visitor_info) {
|
||||
if (e.kind() == cpp_entity_kind::file_t)
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -24,12 +24,14 @@ inline void write_file(const char* name, const char* code)
|
|||
}
|
||||
|
||||
inline std::unique_ptr<cppast::cpp_file> parse_file(const cppast::cpp_entity_index& idx,
|
||||
const char* name)
|
||||
const char* name,
|
||||
bool fast_preprocessing = false)
|
||||
{
|
||||
using namespace cppast;
|
||||
|
||||
libclang_compile_config config;
|
||||
config.set_flags(cpp_standard::cpp_latest);
|
||||
config.fast_preprocessing(fast_preprocessing);
|
||||
|
||||
libclang_parser p(default_logger());
|
||||
|
||||
|
|
@ -40,10 +42,11 @@ inline std::unique_ptr<cppast::cpp_file> parse_file(const cppast::cpp_entity_ind
|
|||
}
|
||||
|
||||
inline std::unique_ptr<cppast::cpp_file> parse(const cppast::cpp_entity_index& idx,
|
||||
const char* name, const char* code)
|
||||
const char* name, const char* code,
|
||||
bool fast_preprocessing = false)
|
||||
{
|
||||
write_file(name, code);
|
||||
return parse_file(idx, name);
|
||||
return parse_file(idx, name, fast_preprocessing);
|
||||
}
|
||||
|
||||
class test_generator : public cppast::code_generator
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue