Added support for class diagram filtering based on C++20 modules (#195)
This commit is contained in:
@@ -1,11 +1,30 @@
|
||||
|
||||
file(GLOB_RECURSE TEST_CASE_SOURCES t*/*.cc t*/*.c t*/src/*.c)
|
||||
file(GLOB_RECURSE TEST_CASE_MODULE_SOURCES t*/src/*.cppm)
|
||||
file(GLOB_RECURSE TEST_CASE_CONFIGS t*/.clang-uml)
|
||||
file(GLOB_RECURSE TEST_CONFIG_YMLS test_config_data/*.yml
|
||||
test_compilation_database_data/*.yml
|
||||
test_compilation_database_data/*.json)
|
||||
|
||||
set(TEST_CASES_REQUIRING_CXX20 t00056 t00058 t00059 t00065 t00069)
|
||||
set(TEST_CASES_REQUIRING_CXX20_MODULES t00070)
|
||||
|
||||
if(ENABLE_CXX_MODULES_TEST_CASES)
|
||||
foreach(CXX20_MOD_TC ${TEST_CASES_REQUIRING_CXX20_MODULES})
|
||||
list(APPEND TEST_CASES_REQUIRING_CXX20 ${CXX20_MOD_TC})
|
||||
endforeach()
|
||||
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
|
||||
else()
|
||||
foreach(CXX20_MOD_TC ${TEST_CASES_REQUIRING_CXX20_MODULES})
|
||||
list(FILTER TEST_CASE_SOURCES
|
||||
EXCLUDE
|
||||
REGEX ".*${CXX20_MOD_TC}.*")
|
||||
list(FILTER TEST_CASE_CONFIGS
|
||||
EXCLUDE
|
||||
REGEX ".*${CXX20_MOD_TC}.*")
|
||||
|
||||
endforeach()
|
||||
endif(ENABLE_CXX_MODULES_TEST_CASES)
|
||||
|
||||
set(CLANG_UML_TEST_LIBRARIES
|
||||
clang-umllib
|
||||
@@ -19,6 +38,7 @@ endif(MSVC)
|
||||
|
||||
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_20 SUPPORTS_CXX_STD_20)
|
||||
|
||||
# Remove test cases which require C++20 if they are not supported here
|
||||
if(SUPPORTS_CXX_STD_20 EQUAL -1
|
||||
OR ${LLVM_PACKAGE_VERSION} VERSION_LESS "14.0")
|
||||
set(ENABLE_CXX_STD_20_TEST_CASES 0)
|
||||
@@ -34,7 +54,7 @@ else()
|
||||
set(ENABLE_CXX_STD_20_TEST_CASES 1)
|
||||
endif()
|
||||
|
||||
set(TEST_CASES
|
||||
set(TEST_NAMES
|
||||
test_util
|
||||
test_model
|
||||
test_cases
|
||||
@@ -46,15 +66,24 @@ set(TEST_CASES
|
||||
test_thread_pool_executor
|
||||
test_query_driver_output_extractor)
|
||||
|
||||
foreach(TEST_NAME ${TEST_CASES})
|
||||
add_executable(${TEST_NAME}
|
||||
${TEST_NAME}.cc
|
||||
$<$<STREQUAL:${TEST_NAME},test_cases>:${TEST_CASE_SOURCES}>
|
||||
catch.h)
|
||||
foreach(TEST_NAME ${TEST_NAMES})
|
||||
add_executable(${TEST_NAME})
|
||||
if(TEST_NAME STREQUAL "test_cases")
|
||||
if(ENABLE_CXX_MODULES_TEST_CASES)
|
||||
target_sources(${TEST_NAME} PUBLIC FILE_SET CXX_MODULES FILES
|
||||
${TEST_CASE_MODULE_SOURCES})
|
||||
endif(ENABLE_CXX_MODULES_TEST_CASES)
|
||||
target_sources(${TEST_NAME} PUBLIC ${TEST_NAME}.cc
|
||||
${TEST_CASE_SOURCES} catch.h)
|
||||
else()
|
||||
target_sources(${TEST_NAME} PUBLIC ${TEST_NAME}.cc catch.h)
|
||||
endif(TEST_NAME STREQUAL "test_cases")
|
||||
|
||||
target_compile_features(${TEST_NAME} PRIVATE
|
||||
$<IF:${ENABLE_CXX_STD_20_TEST_CASES},cxx_std_20,cxx_std_17>)
|
||||
target_compile_definitions(${TEST_NAME} PRIVATE
|
||||
$<$<EQUAL:${ENABLE_CXX_STD_20_TEST_CASES},1>:ENABLE_CXX_STD_20_TEST_CASES>)
|
||||
$<$<EQUAL:${ENABLE_CXX_STD_20_TEST_CASES},1>:ENABLE_CXX_STD_20_TEST_CASES>
|
||||
$<$<BOOL:${ENABLE_CXX_MODULES_TEST_CASES}>:ENABLE_CXX_MODULES_TEST_CASES>)
|
||||
target_compile_options(${TEST_NAME} PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:CXX>:
|
||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
||||
@@ -89,6 +118,6 @@ foreach(TEST_CONFIG_YML ${TEST_CONFIG_YMLS})
|
||||
COPYONLY)
|
||||
endforeach()
|
||||
|
||||
foreach(TEST_NAME ${TEST_CASES})
|
||||
foreach(TEST_NAME ${TEST_NAMES})
|
||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||
endforeach()
|
||||
|
||||
12
tests/t00070/.clang-uml
Normal file
12
tests/t00070/.clang-uml
Normal file
@@ -0,0 +1,12 @@
|
||||
diagrams:
|
||||
t00070_class:
|
||||
type: class
|
||||
glob:
|
||||
- t00070.cc
|
||||
include:
|
||||
modules:
|
||||
- t00070
|
||||
exclude:
|
||||
modules:
|
||||
- t00070.lib2
|
||||
using_namespace: clanguml::t00070
|
||||
11
tests/t00070/src/common.cppm
Normal file
11
tests/t00070/src/common.cppm
Normal file
@@ -0,0 +1,11 @@
|
||||
export module t00070;
|
||||
export import t00070.lib1;
|
||||
export import t00070.lib2;
|
||||
|
||||
export namespace clanguml::t00070 {
|
||||
class A {
|
||||
int get() { return a; }
|
||||
|
||||
int a;
|
||||
};
|
||||
}
|
||||
11
tests/t00070/src/lib1.cppm
Normal file
11
tests/t00070/src/lib1.cppm
Normal file
@@ -0,0 +1,11 @@
|
||||
export module t00070.lib1;
|
||||
|
||||
export namespace clanguml::t00070 {
|
||||
class B { };
|
||||
|
||||
template <typename T> class BB {
|
||||
T t;
|
||||
};
|
||||
|
||||
enum class BBB { bbb1, bbb2 };
|
||||
}
|
||||
11
tests/t00070/src/lib2.cppm
Normal file
11
tests/t00070/src/lib2.cppm
Normal file
@@ -0,0 +1,11 @@
|
||||
export module t00070.lib2;
|
||||
|
||||
export namespace clanguml::t00070 {
|
||||
class C { };
|
||||
|
||||
template <typename T> class CC {
|
||||
T t;
|
||||
};
|
||||
|
||||
enum class CCC { ccc1, ccc2 };
|
||||
}
|
||||
14
tests/t00070/t00070.cc
Normal file
14
tests/t00070/t00070.cc
Normal file
@@ -0,0 +1,14 @@
|
||||
import t00070.lib1;
|
||||
import t00070.lib2;
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00070 {
|
||||
int tmain()
|
||||
{
|
||||
B b;
|
||||
C c;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
78
tests/t00070/test_case.h
Normal file
78
tests/t00070/test_case.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* tests/t00070/test_case.h
|
||||
*
|
||||
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
TEST_CASE("t00070", "[test-case][class]")
|
||||
{
|
||||
auto [config, db] = load_config("t00070");
|
||||
|
||||
auto diagram = config.diagrams["t00070_class"];
|
||||
|
||||
REQUIRE(diagram->name == "t00070_class");
|
||||
|
||||
auto model = generate_class_diagram(*db, diagram);
|
||||
|
||||
REQUIRE(model->name() == "t00070_class");
|
||||
|
||||
{
|
||||
auto src = generate_class_puml(diagram, *model);
|
||||
AliasMatcher _A(src);
|
||||
|
||||
REQUIRE_THAT(src, StartsWith("@startuml"));
|
||||
REQUIRE_THAT(src, EndsWith("@enduml\n"));
|
||||
|
||||
REQUIRE_THAT(src, !IsClass(_A("A")));
|
||||
REQUIRE_THAT(src, IsClass(_A("B")));
|
||||
REQUIRE_THAT(src, !IsClass(_A("C")));
|
||||
|
||||
REQUIRE_THAT(src, IsClassTemplate("BB", "T"));
|
||||
REQUIRE_THAT(src, !IsClassTemplate("CC", "T"));
|
||||
|
||||
REQUIRE_THAT(src, IsEnum(_A("BBB")));
|
||||
REQUIRE_THAT(src, !IsEnum(_A("CCC")));
|
||||
|
||||
save_puml(config.output_directory(), diagram->name + ".puml", src);
|
||||
}
|
||||
|
||||
{
|
||||
auto j = generate_class_json(diagram, *model);
|
||||
|
||||
using namespace json;
|
||||
|
||||
save_json(config.output_directory(), diagram->name + ".json", j);
|
||||
}
|
||||
|
||||
{
|
||||
auto src = generate_class_mermaid(diagram, *model);
|
||||
|
||||
mermaid::AliasMatcher _A(src);
|
||||
using mermaid::IsClass;
|
||||
using mermaid::IsEnum;
|
||||
|
||||
REQUIRE_THAT(src, !IsClass(_A("A")));
|
||||
REQUIRE_THAT(src, IsClass(_A("B")));
|
||||
REQUIRE_THAT(src, !IsClass(_A("C")));
|
||||
|
||||
REQUIRE_THAT(src, IsClass(_A("BB<T>")));
|
||||
REQUIRE_THAT(src, !IsClass(_A("CC<T>")));
|
||||
|
||||
REQUIRE_THAT(src, IsEnum(_A("BBB")));
|
||||
REQUIRE_THAT(src, !IsEnum(_A("CCC")));
|
||||
|
||||
save_mermaid(config.output_directory(), diagram->name + ".mmd", src);
|
||||
}
|
||||
}
|
||||
@@ -407,6 +407,9 @@ using namespace clanguml::test::matchers;
|
||||
#if defined(ENABLE_CXX_STD_20_TEST_CASES)
|
||||
#include "t00069/test_case.h"
|
||||
#endif
|
||||
#if defined(ENABLE_CXX_MODULES_TEST_CASES)
|
||||
#include "t00070/test_case.h"
|
||||
#endif
|
||||
|
||||
///
|
||||
/// Sequence diagram tests
|
||||
|
||||
Reference in New Issue
Block a user