Fixed diagram paths filtering
This commit is contained in:
@@ -48,6 +48,14 @@ set(CLANG_UML_TEST_CONFIG_HEADER
|
||||
catch.h
|
||||
)
|
||||
|
||||
set(CLANG_UML_TEST_FILTERS_SRC
|
||||
test_filters.cc
|
||||
${TEST_FILTERS_SOURCES}
|
||||
)
|
||||
set(CLANG_UML_TEST_FILTERS_HEADER
|
||||
catch.h
|
||||
)
|
||||
|
||||
set(CLANG_UML_TEST_THREAD_POOL_EXECUTOR_SRC
|
||||
test_thread_pool_executor.cc
|
||||
)
|
||||
@@ -95,6 +103,16 @@ target_link_libraries(test_config
|
||||
${YAML_CPP_LIBRARIES}
|
||||
spdlog::spdlog clang-umllib cppast)
|
||||
|
||||
add_executable(test_filters
|
||||
${CLANG_UML_TEST_FILTERS_SRC}
|
||||
${CLANG_UML_TEST_FILTERS_HEADER})
|
||||
|
||||
target_link_libraries(test_filters
|
||||
PRIVATE
|
||||
${LIBCLANG_LIBRARIES}
|
||||
${YAML_CPP_LIBRARIES}
|
||||
spdlog::spdlog clang-umllib cppast)
|
||||
|
||||
add_executable(test_thread_pool_executor
|
||||
${CLANG_UML_TEST_THREAD_POOL_EXECUTOR_SRC}
|
||||
${CLANG_UML_TEST_THREAD_POOL_EXECUTOR_HEADER})
|
||||
@@ -145,3 +163,4 @@ add_test(NAME test_config COMMAND test_config)
|
||||
add_test(NAME test_model COMMAND test_model)
|
||||
add_test(NAME test_thread_pool_executor COMMAND test_thread_pool_executor)
|
||||
add_test(NAME test_cases COMMAND test_cases)
|
||||
add_test(NAME test_filters COMMAND test_filters)
|
||||
|
||||
@@ -14,6 +14,10 @@ diagrams:
|
||||
# Include only files belonging to these paths
|
||||
paths:
|
||||
- ../../tests/t40002
|
||||
exclude:
|
||||
paths:
|
||||
# Exclude single header
|
||||
- ../../tests/t40002/include/lib2/lib2_detail.h
|
||||
plantuml:
|
||||
before:
|
||||
- "' t40002 test include diagram"
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib2_detail.h"
|
||||
|
||||
namespace clanguml::t40002::lib2 {
|
||||
|
||||
int foo2();
|
||||
|
||||
7
tests/t40002/include/lib2/lib2_detail.h
Normal file
7
tests/t40002/include/lib2/lib2_detail.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace clanguml::t40002::lib2::detail {
|
||||
|
||||
int foo22();
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../../include/lib2/lib2.h"
|
||||
#include "../../include/lib2/lib2_detail.h"
|
||||
|
||||
namespace clanguml::t40002::lib2 {
|
||||
|
||||
@@ -8,4 +9,6 @@ int foo1() { return 1; }
|
||||
|
||||
int foo() { return foo1(); }
|
||||
|
||||
int foo22() { return 22; }
|
||||
|
||||
}
|
||||
@@ -39,6 +39,7 @@ TEST_CASE("t40002", "[test-case][package]")
|
||||
REQUIRE_THAT(puml, IsFolder("lib2"));
|
||||
REQUIRE_THAT(puml, IsFile("lib1.h"));
|
||||
REQUIRE_THAT(puml, IsFile("lib2.h"));
|
||||
REQUIRE_THAT(puml, !IsFile("lib2_detail.h"));
|
||||
REQUIRE_THAT(puml, IsFile("t40002.cc"));
|
||||
REQUIRE_THAT(puml, IsFile("lib1.cc"));
|
||||
REQUIRE_THAT(puml, IsFile("lib2.cc"));
|
||||
|
||||
20
tests/test_config_data/filters.yml
Normal file
20
tests/test_config_data/filters.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
compilation_database_dir: debug
|
||||
output_directory: output
|
||||
|
||||
diagrams:
|
||||
include_test:
|
||||
type: class
|
||||
glob:
|
||||
- src/**/*.cc
|
||||
- src/**/*.h
|
||||
include:
|
||||
paths:
|
||||
- dir1
|
||||
- dir2/dir1
|
||||
- file1.h
|
||||
exclude:
|
||||
paths:
|
||||
- dir1/file9.h
|
||||
- dir2/dir1/file9.h
|
||||
- dir1/dir3
|
||||
- file9.h
|
||||
54
tests/test_filters.cc
Normal file
54
tests/test_filters.cc
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* tests/test_filters.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.
|
||||
*/
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "catch.h"
|
||||
|
||||
#include "common/model/diagram_filter.h"
|
||||
#include "common/model/source_file.h"
|
||||
#include "config/config.h"
|
||||
|
||||
#include "include_diagram/model/diagram.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
TEST_CASE("Test diagram paths filter", "[unit-test]")
|
||||
{
|
||||
using clanguml::common::model::diagram_filter;
|
||||
using clanguml::common::model::source_file;
|
||||
|
||||
auto make_path = [](std::string_view p) {
|
||||
return source_file{
|
||||
std::filesystem::current_path() / "test_config_data" / p};
|
||||
};
|
||||
|
||||
auto cfg = clanguml::config::load("./test_config_data/filters.yml");
|
||||
|
||||
CHECK(cfg.diagrams.size() == 1);
|
||||
auto &config = *cfg.diagrams["include_test"];
|
||||
clanguml::include_diagram::model::diagram diagram;
|
||||
|
||||
diagram_filter filter(diagram, config);
|
||||
|
||||
CHECK(filter.should_include(make_path("dir1/file1.h")));
|
||||
CHECK(filter.should_include(make_path("dir1/dir2/file1.h")));
|
||||
CHECK(filter.should_include(make_path("dir1/dir2/dir3/dir4/file1.h")));
|
||||
CHECK_FALSE(filter.should_include(make_path("dir1/file9.h")));
|
||||
CHECK_FALSE(filter.should_include(make_path("dir1/dir3/file1.h")));
|
||||
CHECK_FALSE(filter.should_include(make_path("dir2/dir1/file9.h")));
|
||||
}
|
||||
@@ -55,15 +55,16 @@ TEST_CASE("Test starts_with", "[unit-test]")
|
||||
using std::filesystem::path;
|
||||
|
||||
CHECK(starts_with(path{"/a/b/c/d"}, path{"/"}));
|
||||
CHECK(!starts_with(path{"/a/b/c/d"}, path{"/a/b/c/d/e"}));
|
||||
CHECK_FALSE(starts_with(path{"/a/b/c/d"}, path{"/a/b/c/d/e"}));
|
||||
CHECK(starts_with(path{"/a/b/c/d/e"}, path{"/a/b/c/d"}));
|
||||
CHECK(starts_with(path{"/a/b/c/d/e"}, path{"/a/b/c/d/"}));
|
||||
CHECK(!starts_with(path{"/e/f/c/d/file.h"}, path{"/a/b"}));
|
||||
CHECK(!starts_with(path{"/e/f/c/d/file.h"}, path{"/a/b/"}));
|
||||
CHECK_FALSE(starts_with(path{"/e/f/c/d/file.h"}, path{"/a/b"}));
|
||||
CHECK_FALSE(starts_with(path{"/e/f/c/d/file.h"}, path{"/a/b/"}));
|
||||
CHECK(starts_with(path{"/a/b/c/d/file.h"}, path{"/a/b/c"}));
|
||||
CHECK(starts_with(path{"/a/b/c/file.h"}, path{"/a/b/c/file.h"}));
|
||||
CHECK(starts_with(path{"c/file.h"}, path{"c"}));
|
||||
CHECK(starts_with(path{"c/file.h"}, path{"c/"}));
|
||||
CHECK_FALSE(starts_with(path{"c/file1.h"}, path{"c/file2.h"}));
|
||||
}
|
||||
|
||||
TEST_CASE("Test replace_all", "[unit-test]")
|
||||
|
||||
Reference in New Issue
Block a user