Properly detect include guard macros when fast preprocessing

Fixes #35.
This commit is contained in:
Jonathan Müller 2018-02-17 13:01:34 +01:00
commit b36a4a84b8
2 changed files with 148 additions and 5 deletions

View file

@ -28,7 +28,38 @@ TEST_CASE("preprocessor_parses_escaped_character", "[!hide][clang4]")
libclang_compile_config config;
config.set_flags(cpp_standard::cpp_latest);
auto&& preprocessed = detail::preprocess(config, "ppec.cpp", default_logger().get());
auto preprocessed = detail::preprocess(config, "ppec.cpp", default_logger().get());
REQUIRE(preprocessed.includes.size() == 1);
REQUIRE(preprocessed.includes[0].file_name == "ppec.hpp");
}
TEST_CASE("fast_preprocessing include guard")
{
auto file_name = "fast_preprocessing_include_guard";
write_file(file_name, R"(
// This is a C++ comment that should get skipped.
/// This as well.
/* C style comments
#ifndef FALSE_POSITIVE
#define FALSE_POSITIVE
*/ #ifndef INCLUDE_GUARD // the include guard macro
#define INCLUDE_GUARD
struct foo {};
#endif
)");
libclang_compile_config config;
config.set_flags(cpp_standard::cpp_latest);
config.fast_preprocessing(true);
auto result = detail::preprocess(config, file_name, default_logger().get());
REQUIRE(result.macros.size() == 1u);
REQUIRE(result.macros[0].macro->name() == "INCLUDE_GUARD");
}