Added class diagram test
This commit is contained in:
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@@ -12,3 +12,4 @@ jobs:
|
||||
- name: Build and unit test
|
||||
run: |
|
||||
make debug
|
||||
make test
|
||||
|
||||
4
Makefile
4
Makefile
@@ -37,11 +37,13 @@ release/CMakeLists.txt:
|
||||
|
||||
debug: debug/CMakeLists.txt
|
||||
make -C debug -j
|
||||
make -C debug test
|
||||
|
||||
release: release/CMakeLists.txt
|
||||
make -C release -j
|
||||
|
||||
test: debug
|
||||
CTEST_OUTPUT_ON_FAILURE=1 make -C debug test
|
||||
|
||||
.PHONY: clang-format
|
||||
clang-format:
|
||||
docker run --rm -v $(CURDIR):/root/sources bkryza/clang-format-check:1.2
|
||||
|
||||
@@ -119,6 +119,7 @@ struct config {
|
||||
// directory
|
||||
std::vector<std::string> glob;
|
||||
std::string compilation_database_dir{"."};
|
||||
std::string output_directory{};
|
||||
std::map<std::string, std::shared_ptr<diagram>> diagrams;
|
||||
};
|
||||
|
||||
@@ -242,6 +243,9 @@ template <> struct convert<config> {
|
||||
if (node["glob"])
|
||||
rhs.glob = node["glob"].as<std::vector<std::string>>();
|
||||
|
||||
if (node["output_directory"])
|
||||
rhs.output_directory = node["output_directory"].as<std::string>();
|
||||
|
||||
if (node["compilation_database_dir"])
|
||||
rhs.compilation_database_dir =
|
||||
node["compilation_database_dir"].as<std::string>();
|
||||
|
||||
@@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
set(CLANG_UML_TEST_CASES_SRC
|
||||
test_cases.cc
|
||||
t00001/t00001.cc
|
||||
t00002/t00002.cc
|
||||
)
|
||||
set(CLANG_UML_TEST_CASES_HEADER
|
||||
catch.h
|
||||
@@ -23,5 +24,6 @@ target_link_libraries(test_cases
|
||||
spdlog::spdlog clang-umllib)
|
||||
|
||||
configure_file(t00001/.clanguml t00001/.clanguml COPYONLY)
|
||||
configure_file(t00002/.clanguml t00002/.clanguml COPYONLY)
|
||||
|
||||
add_test(NAME test_cases COMMAND test_cases)
|
||||
|
||||
17
tests/t00002/.clanguml
Normal file
17
tests/t00002/.clanguml
Normal file
@@ -0,0 +1,17 @@
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t00002_class:
|
||||
type: class
|
||||
glob:
|
||||
- ../../tests/t00002/t00002.cc
|
||||
using_namespace:
|
||||
- clanguml::t00002
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t00002
|
||||
plantuml:
|
||||
before:
|
||||
- "' t00002 test class diagram"
|
||||
after:
|
||||
- 'note over "A": A class'
|
||||
21
tests/t00002/t00002.cc
Normal file
21
tests/t00002/t00002.cc
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <vector>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00002 {
|
||||
|
||||
class A {
|
||||
public:
|
||||
virtual void foo() {}
|
||||
};
|
||||
|
||||
class B : public A {
|
||||
};
|
||||
|
||||
class C : public A {
|
||||
};
|
||||
|
||||
class D : public B, public C {
|
||||
std::vector<A *> as;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ auto generate_sequence_diagram(compilation_database &db,
|
||||
}
|
||||
|
||||
auto generate_class_diagram(compilation_database &db,
|
||||
std::shared_ptr<clanguml::config::class_diagram> diagram)
|
||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||
{
|
||||
auto diagram_model =
|
||||
clanguml::generators::class_diagram::generate(db, diagram->name,
|
||||
@@ -64,6 +64,31 @@ std::string generate_sequence_puml(
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string generate_class_puml(
|
||||
std::shared_ptr<clanguml::config::diagram> config,
|
||||
clanguml::model::class_diagram::diagram &model)
|
||||
{
|
||||
using namespace clanguml::generators::class_diagram::puml;
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
ss << generator(
|
||||
dynamic_cast<clanguml::config::class_diagram &>(*config), model);
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void save_puml(const std::string &path, const std::string &puml)
|
||||
{
|
||||
std::filesystem::path p{path};
|
||||
spdlog::error("PWD: {}", std::filesystem::current_path().string());
|
||||
spdlog::error("SAVING TEST PWD {} DIAGRAM: {}", p.string());
|
||||
std::ofstream ofs;
|
||||
ofs.open(p, std::ofstream::out | std::ofstream::trunc);
|
||||
ofs << puml;
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
TEST_CASE("Test t00001", "[unit-test]")
|
||||
{
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
@@ -94,4 +119,39 @@ TEST_CASE("Test t00001", "[unit-test]")
|
||||
|
||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||
}
|
||||
|
||||
TEST_CASE("Test t00002", "[unit-test]")
|
||||
{
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
|
||||
auto [config, db] = load_config("t00002");
|
||||
|
||||
auto diagram = config.diagrams["t00002_class"];
|
||||
|
||||
REQUIRE(diagram->name == "t00002_class");
|
||||
|
||||
REQUIRE(diagram->include.namespaces.size() == 1);
|
||||
REQUIRE_THAT(diagram->include.namespaces,
|
||||
VectorContains(std::string{"clanguml::t00002"}));
|
||||
|
||||
REQUIRE(diagram->exclude.namespaces.size() == 0);
|
||||
|
||||
REQUIRE(diagram->should_include("clanguml::t00002::A"));
|
||||
REQUIRE(!diagram->should_include("std::vector"));
|
||||
|
||||
auto model = generate_class_diagram(db, diagram);
|
||||
|
||||
REQUIRE(model.name == "t00002_class");
|
||||
|
||||
auto puml = generate_class_puml(diagram, model);
|
||||
|
||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user