Updated remove_compile_flags option
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
|
||||
file(GLOB_RECURSE TEST_CASE_SOURCES t*/*.cc t*/*.c t*/src/*.c)
|
||||
file(GLOB_RECURSE TEST_CASE_CONFIGS t*/.clang-uml)
|
||||
file(GLOB_RECURSE TEST_CONFIG_YMLS test_config_data/*.yml)
|
||||
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)
|
||||
|
||||
@@ -36,6 +38,7 @@ set(TEST_CASES
|
||||
test_util
|
||||
test_model
|
||||
test_cases
|
||||
test_compilation_database
|
||||
test_decorator_parser
|
||||
test_config
|
||||
test_cli_handler
|
||||
|
||||
+17
-20
@@ -19,6 +19,7 @@
|
||||
#include "test_cases.h"
|
||||
|
||||
#include "cli/cli_handler.h"
|
||||
#include "common/compilation_database.h"
|
||||
#include "common/generators/generators.h"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
@@ -33,32 +34,28 @@ void inject_diagram_options(std::shared_ptr<clanguml::config::diagram> diagram)
|
||||
diagram->generate_links.set(links_config);
|
||||
}
|
||||
|
||||
std::pair<clanguml::config::config,
|
||||
std::unique_ptr<clang::tooling::CompilationDatabase>>
|
||||
std::pair<clanguml::config::config, clanguml::common::compilation_database_ptr>
|
||||
load_config(const std::string &test_name)
|
||||
{
|
||||
auto config = clanguml::config::load(test_name + "/.clang-uml", true);
|
||||
std::pair<clanguml::config::config,
|
||||
clanguml::common::compilation_database_ptr>
|
||||
res;
|
||||
|
||||
res.first = clanguml::config::load(test_name + "/.clang-uml", true);
|
||||
|
||||
LOG_DBG("Loading compilation database from {}",
|
||||
config.compilation_database_dir());
|
||||
res.first.compilation_database_dir());
|
||||
|
||||
std::string err{};
|
||||
auto compilation_database =
|
||||
clang::tooling::CompilationDatabase::autoDetectFromDirectory(
|
||||
config.compilation_database_dir(), err);
|
||||
res.second =
|
||||
clanguml::common::compilation_database::auto_detect_from_directory(
|
||||
res.first);
|
||||
|
||||
if (!err.empty()) {
|
||||
LOG_ERROR("Failed to load compilation database from {}",
|
||||
config.compilation_database_dir());
|
||||
throw std::runtime_error{err};
|
||||
}
|
||||
|
||||
return std::make_pair(std::move(config), std::move(compilation_database));
|
||||
return res;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template <typename DiagramConfig>
|
||||
auto generate_diagram_impl(clang::tooling::CompilationDatabase &db,
|
||||
auto generate_diagram_impl(clanguml::common::compilation_database &db,
|
||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||
{
|
||||
using diagram_config = DiagramConfig;
|
||||
@@ -117,7 +114,7 @@ auto generate_diagram_json(
|
||||
}
|
||||
|
||||
std::unique_ptr<clanguml::class_diagram::model::diagram> generate_class_diagram(
|
||||
clang::tooling::CompilationDatabase &db,
|
||||
clanguml::common::compilation_database &db,
|
||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||
{
|
||||
return detail::generate_diagram_impl<clanguml::config::class_diagram>(
|
||||
@@ -125,7 +122,7 @@ std::unique_ptr<clanguml::class_diagram::model::diagram> generate_class_diagram(
|
||||
}
|
||||
|
||||
std::unique_ptr<clanguml::sequence_diagram::model::diagram>
|
||||
generate_sequence_diagram(clang::tooling::CompilationDatabase &db,
|
||||
generate_sequence_diagram(clanguml::common::compilation_database &db,
|
||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||
{
|
||||
return detail::generate_diagram_impl<clanguml::config::sequence_diagram>(
|
||||
@@ -133,7 +130,7 @@ generate_sequence_diagram(clang::tooling::CompilationDatabase &db,
|
||||
}
|
||||
|
||||
std::unique_ptr<clanguml::package_diagram::model::diagram>
|
||||
generate_package_diagram(clang::tooling::CompilationDatabase &db,
|
||||
generate_package_diagram(clanguml::common::compilation_database &db,
|
||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||
{
|
||||
return detail::generate_diagram_impl<clanguml::config::package_diagram>(
|
||||
@@ -141,7 +138,7 @@ generate_package_diagram(clang::tooling::CompilationDatabase &db,
|
||||
}
|
||||
|
||||
std::unique_ptr<clanguml::include_diagram::model::diagram>
|
||||
generate_include_diagram(clang::tooling::CompilationDatabase &db,
|
||||
generate_include_diagram(clanguml::common::compilation_database &db,
|
||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||
{
|
||||
return detail::generate_diagram_impl<clanguml::config::include_diagram>(
|
||||
|
||||
+2
-2
@@ -23,6 +23,7 @@
|
||||
#include "class_diagram/model/diagram.h"
|
||||
#include "class_diagram/visitor/translation_unit_visitor.h"
|
||||
#include "common/clang_utils.h"
|
||||
#include "common/compilation_database.h"
|
||||
#include "config/config.h"
|
||||
#include "include_diagram/generators/plantuml/include_diagram_generator.h"
|
||||
#include "include_diagram/visitor/translation_unit_visitor.h"
|
||||
@@ -54,8 +55,7 @@ using Catch::Matchers::VectorContains;
|
||||
|
||||
using namespace clanguml::util;
|
||||
|
||||
std::pair<clanguml::config::config,
|
||||
std::unique_ptr<clang::tooling::CompilationDatabase>>
|
||||
std::pair<clanguml::config::config, clanguml::common::compilation_database_ptr>
|
||||
load_config(const std::string &test_name);
|
||||
|
||||
std::string generate_sequence_puml(
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* tests/test_compilation_database.cc
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "common/compilation_database.h"
|
||||
|
||||
#include "util/util.h"
|
||||
|
||||
#include "catch.h"
|
||||
#include <spdlog/sinks/ostream_sink.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
std::shared_ptr<spdlog::logger> make_sstream_logger(std::ostream &ostr)
|
||||
{
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(ostr);
|
||||
return std::make_shared<spdlog::logger>(
|
||||
"clanguml-logger", std::move(oss_sink));
|
||||
}
|
||||
|
||||
TEST_CASE("Test compilation_database should work", "[unit-test]")
|
||||
{
|
||||
using clanguml::common::compilation_database;
|
||||
using clanguml::common::compilation_database_ptr;
|
||||
using clanguml::common::model::access_t;
|
||||
using clanguml::common::model::relationship_t;
|
||||
using clanguml::util::contains;
|
||||
|
||||
auto cfg =
|
||||
clanguml::config::load("./test_compilation_database_data/config.yml");
|
||||
|
||||
try {
|
||||
const auto db =
|
||||
clanguml::common::compilation_database::auto_detect_from_directory(
|
||||
cfg);
|
||||
|
||||
auto all_files = db->getAllFiles();
|
||||
|
||||
REQUIRE(all_files.size() == 3);
|
||||
REQUIRE(all_files.at(0) ==
|
||||
"src/class_diagram/generators/json/class_diagram_generator.cc");
|
||||
REQUIRE(all_files.at(1) ==
|
||||
"src/class_diagram/generators/plantuml/"
|
||||
"class_diagram_generator.cc");
|
||||
REQUIRE(all_files.at(2) == "src/class_diagram/model/class.cc");
|
||||
|
||||
auto ccs = db->getAllCompileCommands();
|
||||
|
||||
REQUIRE(contains(ccs.at(0).CommandLine, "-Wno-error"));
|
||||
REQUIRE(contains(ccs.at(0).CommandLine, "-Wno-unknown-warning-option"));
|
||||
REQUIRE(
|
||||
!contains(ccs.at(0).CommandLine, "-Wno-deprecated-declarations"));
|
||||
}
|
||||
catch (clanguml::common::compilation_database_error &e) {
|
||||
REQUIRE(false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Test compilation_database should throw", "[unit-test]")
|
||||
{
|
||||
using clanguml::common::compilation_database;
|
||||
using clanguml::common::compilation_database_error;
|
||||
using clanguml::common::compilation_database_ptr;
|
||||
using clanguml::util::contains;
|
||||
|
||||
auto cfg = clanguml::config::load(
|
||||
"./test_compilation_database_data/config_bad.yml");
|
||||
|
||||
REQUIRE_THROWS_AS(
|
||||
clanguml::common::compilation_database::auto_detect_from_directory(cfg),
|
||||
compilation_database_error);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
compilation_database_dir: .
|
||||
output_directory: .
|
||||
add_compile_flags: [-Wno-unknown-warning-option, -Wno-error]
|
||||
remove_compile_flags: [-Wno-deprecated-declarations]
|
||||
diagrams:
|
||||
class_main:
|
||||
type: class
|
||||
@@ -0,0 +1,5 @@
|
||||
compilation_database_dir: /tmp/no_such_directory___
|
||||
output_directory: .
|
||||
diagrams:
|
||||
class_main:
|
||||
type: class
|
||||
Reference in New Issue
Block a user