Fixed link generation in include diagrams for include directives

This commit is contained in:
Bartek Kryza
2022-04-12 23:36:26 +02:00
parent a2f82bc847
commit 1915bd85b1
3 changed files with 27 additions and 4 deletions

View File

@@ -64,7 +64,7 @@ void translation_unit_visitor::process_include_directive(
auto include_path = std::filesystem::path(include_directive.full_path());
// Make sure the include_path is absolute with respect to the
// Make sure the file_path is absolute with respect to the
// filesystem, and in normal form
if (include_path.is_relative()) {
include_path = ctx.config().base_directory() / include_path;
@@ -103,9 +103,10 @@ void translation_unit_visitor::process_include_directive(
ctx.get_current_file().value().add_relationship(
relationship{relationship_type, include_file.alias()});
include_file.set_file(std::filesystem::absolute(include_path)
.lexically_normal()
.string());
include_file.set_file(
std::filesystem::absolute(include_directive.full_path())
.lexically_normal()
.string());
include_file.set_line(0);
}
else {

View File

@@ -48,6 +48,20 @@ TEST_CASE("t40002", "[test-case][package]")
REQUIRE_THAT(puml, IsAssociation(_A("lib1.cc"), _A("lib1.h")));
REQUIRE_THAT(puml, IsAssociation(_A("lib2.cc"), _A("lib2.h")));
REQUIRE_THAT(puml,
HasLink(_A("lib1.h"),
fmt::format("https://github.com/bkryza/clang-uml/blob/{}/tests/"
"t40002/include/lib1/lib1.h#L0",
clanguml::util::get_git_commit()),
"lib1.h"));
REQUIRE_THAT(puml,
HasLink(_A("lib2.h"),
fmt::format("https://github.com/bkryza/clang-uml/blob/{}/tests/"
"t40002/include/lib2/lib2.h#L0",
clanguml::util::get_git_commit()),
"lib2.h"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -373,6 +373,14 @@ ContainsMatcher HasNote(std::string const &cls, std::string const &position,
fmt::format("note {} of {}", position, cls), caseSensitivity));
}
ContainsMatcher HasLink(std::string const &alias, std::string const &link,
std::string const &tooltip,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(CasedString(
fmt::format("{} [[{}{{{}}}]]", alias, link, tooltip), caseSensitivity));
}
template <typename... Ts>
ContainsMatcher IsMethod(std::string const &name,
std::string const &type = "void",