Fixed config includes relative paths
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace clanguml {
|
||||
namespace config {
|
||||
@@ -25,6 +26,12 @@ config load(const std::string &config_file)
|
||||
try {
|
||||
YAML::Node doc = YAML::LoadFile(config_file);
|
||||
|
||||
// Store the parent path of the config_file to properly resolve
|
||||
// the include files paths
|
||||
auto config_file_path = std::filesystem::path{config_file};
|
||||
doc.force_insert(
|
||||
"__parent_path", config_file_path.parent_path().string());
|
||||
|
||||
return doc.as<config>();
|
||||
}
|
||||
catch (YAML::BadFile &e) {
|
||||
@@ -416,8 +423,11 @@ template <> struct convert<config> {
|
||||
std::shared_ptr<clanguml::config::diagram> diagram_config{};
|
||||
|
||||
if (has_key(d.second, "include!")) {
|
||||
YAML::Node node =
|
||||
YAML::LoadFile(d.second["include!"].as<std::string>());
|
||||
auto parent_path = node["__parent_path"].as<std::string>();
|
||||
auto include_path = std::filesystem::path{parent_path};
|
||||
include_path /= d.second["include!"].as<std::string>();
|
||||
|
||||
YAML::Node node = YAML::LoadFile(include_path.string());
|
||||
|
||||
diagram_config = parse_diagram_config(node);
|
||||
}
|
||||
|
||||
@@ -52,3 +52,23 @@ TEST_CASE("Test config inherited", "[unit-test]")
|
||||
CHECK(clanguml::util::contains(cus.using_namespace(), "clanguml::ns1"));
|
||||
CHECK(cus.include_relations_also_as_members());
|
||||
}
|
||||
|
||||
TEST_CASE("Test config includes", "[unit-test]")
|
||||
{
|
||||
auto cfg = clanguml::config::load("./test_config_data/includes.yml");
|
||||
|
||||
CHECK(cfg.diagrams.size() == 2);
|
||||
auto &def = *cfg.diagrams["class_1"];
|
||||
CHECK(def.type() == clanguml::config::diagram_type::class_diagram);
|
||||
CHECK(def.glob().size() == 2);
|
||||
CHECK(def.glob()[0] == "src/**/*.cc");
|
||||
CHECK(def.glob()[1] == "src/**/*.h");
|
||||
CHECK(clanguml::util::contains(def.using_namespace(), "clanguml"));
|
||||
|
||||
auto &cus = *cfg.diagrams["class_2"];
|
||||
CHECK(cus.type() == clanguml::config::diagram_type::class_diagram);
|
||||
CHECK(cus.glob().size() == 1);
|
||||
CHECK(cus.glob()[0] == "src/main.cc");
|
||||
CHECK(clanguml::util::contains(cus.using_namespace(), "clanguml::ns1"));
|
||||
CHECK(cus.include_relations_also_as_members());
|
||||
}
|
||||
18
tests/test_config_data/includes.yml
Normal file
18
tests/test_config_data/includes.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
compilation_database_dir: debug
|
||||
output_directory: output
|
||||
include_relations_also_as_members: false
|
||||
using_namespace:
|
||||
- clanguml
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml
|
||||
- ABCD
|
||||
glob:
|
||||
- src/**/*.cc
|
||||
- src/**/*.h
|
||||
|
||||
diagrams:
|
||||
class_1:
|
||||
include!: includes1.yml
|
||||
class_2:
|
||||
include!: includes2.yml
|
||||
1
tests/test_config_data/includes1.yml
Normal file
1
tests/test_config_data/includes1.yml
Normal file
@@ -0,0 +1 @@
|
||||
type: class
|
||||
6
tests/test_config_data/includes2.yml
Normal file
6
tests/test_config_data/includes2.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
type: class
|
||||
using_namespace:
|
||||
- clanguml::ns1
|
||||
include_relations_also_as_members: true
|
||||
glob:
|
||||
- src/main.cc
|
||||
Reference in New Issue
Block a user