Added cyclic dependency include diagram test case

This commit is contained in:
Bartek Kryza
2022-04-10 22:42:57 +02:00
parent 49874df533
commit c033879b01
10 changed files with 146 additions and 7 deletions

View File

@@ -130,6 +130,15 @@ void translation_unit_visitor::process_file(const std::string &file,
}
}
auto diagram_file_path = f->path() | f->name();
if (!ctx.diagram().get_element(diagram_file_path).has_value()) {
ctx.diagram().add_file(std::move(f));
}
auto &diagram_source_file =
ctx.diagram().get_element(diagram_file_path).value();
if (!register_as_current) {
auto relationship_type =
common::model::relationship_t::kAssociation;
@@ -138,17 +147,15 @@ void translation_unit_visitor::process_file(const std::string &file,
relationship_type = common::model::relationship_t::kDependency;
ctx.get_current_file().value().add_relationship(
common::model::relationship{relationship_type, f->alias()});
common::model::relationship{
relationship_type, diagram_source_file.alias()});
auto fp = std::filesystem::absolute(file).lexically_normal();
f->set_file(fp.string());
f->set_line(0);
diagram_source_file.set_file(fp.string());
diagram_source_file.set_line(0);
}
if (!ctx.diagram().get_element(f->path() | f->name()).has_value()) {
ctx.set_current_file(type_safe::opt_ref(*f));
ctx.diagram().add_file(std::move(f));
}
ctx.set_current_file(type_safe::opt_ref(diagram_source_file));
}
}
}

19
tests/t40002/.clang-uml Normal file
View File

@@ -0,0 +1,19 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t40002_include:
type: include
# Provide the files to parse in order to look
# for #include directives
glob:
- ../../tests/t40002/**/*.cc
- ../../tests/t40002/**/*.h
# Render the paths relative to this directory
relative_to: ../../tests/t40002
include:
# Include only files belonging to these paths
paths:
- ../../tests/t40002
plantuml:
before:
- "' t40002 test include diagram"

View File

@@ -0,0 +1,13 @@
#pragma once
#include "../lib2/lib2.h"
namespace clanguml::t40002::lib1 {
int foo0();
int foo1();
int foo();
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "../lib1/lib1.h"
namespace clanguml::t40002::lib2 {
int foo2();
int foo3();
int foo();
}

View File

@@ -0,0 +1,11 @@
#include "../../include/lib1/lib1.h"
namespace clanguml::t40002::lib1 {
int foo0() { return 0; }
int foo1() { return 1; }
int foo() { return foo1(); }
}

View File

@@ -0,0 +1,11 @@
#include "../../include/lib2/lib2.h"
namespace clanguml::t40002::lib2 {
int foo0() { return 0; }
int foo1() { return 1; }
int foo() { return foo1(); }
}

View File

@@ -0,0 +1,8 @@
#include "../include/lib1/lib1.h"
#include "../include/lib2/lib2.h"
namespace clanguml::t40002 {
int foo() { return lib1::foo() + lib2::foo(); }
}

53
tests/t40002/test_case.h Normal file
View File

@@ -0,0 +1,53 @@
/**
* tests/t40002/test_case.cc
*
* Copyright (c) 2021-2022 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("t40002", "[test-case][package]")
{
auto [config, db] = load_config("t40002");
auto diagram = config.diagrams["t40002_include"];
REQUIRE(diagram->name == "t40002_include");
auto model = generate_include_diagram(db, diagram);
REQUIRE(model->name() == "t40002_include");
auto puml = generate_include_puml(diagram, *model);
AliasMatcher _A(puml);
REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
REQUIRE_THAT(puml, IsFolder("lib1"));
REQUIRE_THAT(puml, IsFolder("lib2"));
REQUIRE_THAT(puml, IsFile("lib1.h"));
REQUIRE_THAT(puml, IsFile("lib2.h"));
REQUIRE_THAT(puml, IsFile("t40002.cc"));
REQUIRE_THAT(puml, IsFile("lib1.cc"));
REQUIRE_THAT(puml, IsFile("lib2.cc"));
REQUIRE_THAT(puml, IsAssociation(_A("t40002.cc"), _A("lib1.h")));
REQUIRE_THAT(puml, IsAssociation(_A("lib1.h"), _A("lib2.h")));
REQUIRE_THAT(puml, IsAssociation(_A("lib1.cc"), _A("lib1.h")));
REQUIRE_THAT(puml, IsAssociation(_A("lib2.cc"), _A("lib2.h")));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -256,6 +256,7 @@ using namespace clanguml::test::matchers;
// Include diagram tests
//
#include "t40001/test_case.h"
#include "t40002/test_case.h"
//
// Other tests (e.g. configuration file)

View File

@@ -153,6 +153,9 @@ test_cases:
- name: t40001
title: Basic include graph diagram test case
description:
- name: t40002
title: Cyclic include graph diagram test case
description:
Configuration diagrams:
- name: t90000
title: Basic config test