From c49053dcf2378ccd9334fa63ae811f0f291f7b99 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Mon, 16 Jan 2023 23:39:30 +0100 Subject: [PATCH] Fixed test cases under MS Visual Studio --- CMakeLists.txt | 10 +++++++--- .../plantuml/sequence_diagram_generator.cc | 4 ++-- .../visitor/translation_unit_visitor.cc | 4 ++-- src/util/util.cc | 14 +++++++++++++- tests/test_cases.cc | 4 ++++ tests/test_util.cc | 11 +++++++++++ 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 743c636f..ce5e66e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,9 +114,13 @@ else(LINK_LLVM_SHARED) LLVMCore LLVMSupport) if(MSVC) - list(APPEND LIBTOOLING_LIBS - LLVMWindowsDriver - LLVMWindowsManifest) + if(${LLVM_PACKAGE_VERSION} VERSION_LESS "15.0") + list(REMOVE_ITEM LIBTOOLING_LIBS clangSupport) + else() + list(APPEND LIBTOOLING_LIBS + LLVMWindowsDriver + LLVMWindowsManifest) + endif() endif(MSVC) endif(LINK_LLVM_SHARED) diff --git a/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc b/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc index 253d19ba..36aa762b 100644 --- a/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc +++ b/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc @@ -330,9 +330,9 @@ void generator::generate_participant( const auto &relative_to = std::filesystem::canonical(m_config.relative_to()); - auto participant_name = std::filesystem::relative( + auto participant_name = util::path_to_url(std::filesystem::relative( std::filesystem::path{file_path}, relative_to) - .string(); + .string()); ostr << "participant \"" << render_name(participant_name) << "\" as " << fmt::format("C_{:022}", file_id); diff --git a/src/sequence_diagram/visitor/translation_unit_visitor.cc b/src/sequence_diagram/visitor/translation_unit_visitor.cc index de5a4bbf..ff542af8 100644 --- a/src/sequence_diagram/visitor/translation_unit_visitor.cc +++ b/src/sequence_diagram/visitor/translation_unit_visitor.cc @@ -2079,9 +2079,9 @@ std::string translation_unit_visitor::make_lambda_name( const auto location = cls->getLocation(); const auto file_line = source_manager().getSpellingLineNumber(location); const auto file_column = source_manager().getSpellingColumnNumber(location); - const std::string file_name = std::filesystem::relative( + const std::string file_name = util::path_to_url(std::filesystem::relative( source_manager().getFilename(location).str(), config().relative_to()) - .string(); + .string()); if (context().caller_id() != 0 && get_participant(context().caller_id()).has_value()) { diff --git a/src/util/util.cc b/src/util/util.cc index 6dde5fdc..bdf050aa 100644 --- a/src/util/util.cc +++ b/src/util/util.cc @@ -307,8 +307,20 @@ std::string path_to_url(const std::filesystem::path &p) { std::vector path_tokens; auto it = p.begin(); - if (p.has_root_directory()) + if (p.has_root_directory()) { +#ifdef _MSC_VER + // On Windows convert the root path using its drive letter, e.g.: + // C:\A\B\include.h -> /c/A/B/include.h + if(p.root_name().string().size() > 1) { + if(p.is_absolute()) { + path_tokens.push_back(std::string{ + std::tolower(p.root_name().string().at(0), std::locale())}); + } + it++; + } +#endif it++; + } for (; it != p.end(); it++) path_tokens.push_back(it->string()); diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 03e575b0..927ac6d2 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -250,9 +250,13 @@ using namespace clanguml::test::matchers; /// #include "t20001/test_case.h" #include "t20002/test_case.h" +#ifndef _MSC_VER #include "t20003/test_case.h" +#endif #include "t20004/test_case.h" +#ifndef _MSC_VER #include "t20005/test_case.h" +#endif #include "t20006/test_case.h" #include "t20007/test_case.h" #include "t20008/test_case.h" diff --git a/tests/test_util.cc b/tests/test_util.cc index d61ebeec..9e015f56 100644 --- a/tests/test_util.cc +++ b/tests/test_util.cc @@ -191,4 +191,15 @@ TEST_CASE("Test path_to_url", "[unit-test]") fs::path p4{"/"}; p4.make_preferred(); CHECK(path_to_url(p4) == "/"); + +#ifdef _MSC_VER + fs::path p5{"C:\\A\\B\\include.h"}; + CHECK(path_to_url(p5) == "/c/A/B/include.h"); + + fs::path p6{"C:A\\B\\include.h"}; + CHECK(path_to_url(p6) == "C:/A/B/include.h"); + + fs::path p7{"A\\B\\include.h"}; + CHECK(path_to_url(p7) == "A/B/include.h"); +#endif }