Refactored command line handling
This commit is contained in:
@@ -38,6 +38,7 @@ set(TEST_CASES
|
||||
test_cases
|
||||
test_decorator_parser
|
||||
test_config
|
||||
test_cli_handler
|
||||
test_filters
|
||||
test_thread_pool_executor)
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
|
||||
#include "test_cases.h"
|
||||
|
||||
#include "cli/cli_handler.h"
|
||||
#include "common/generators/plantuml/generator.h"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
@@ -345,7 +347,17 @@ int main(int argc, char *argv[])
|
||||
if (returnCode != 0)
|
||||
return returnCode;
|
||||
|
||||
clanguml::util::setup_logging(debug_log ? 3 : 1);
|
||||
clanguml::cli::cli_handler clih;
|
||||
|
||||
std::vector<const char *> argvv = {
|
||||
"clang-uml", "--config", "./test_config_data/simple.yml"};
|
||||
|
||||
if (debug_log)
|
||||
argvv.push_back("-vvv");
|
||||
else
|
||||
argvv.push_back("-q");
|
||||
|
||||
clih.handle_options(argvv.size(), argvv.data());
|
||||
|
||||
return session.run();
|
||||
}
|
||||
|
||||
74
tests/test_cli_handler.cc
Normal file
74
tests/test_cli_handler.cc
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* tests/test_cli_handler.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 "cli/cli_handler.h"
|
||||
#include "version.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 cli handler print_version", "[unit-test]")
|
||||
{
|
||||
using clanguml::cli::cli_flow_t;
|
||||
using clanguml::cli::cli_handler;
|
||||
|
||||
std::vector<const char *> argv = {"clang-uml", "--version"};
|
||||
|
||||
std::ostringstream ostr;
|
||||
cli_handler cli{ostr, make_sstream_logger(ostr)};
|
||||
|
||||
auto res = cli.handle_options(argv.size(), argv.data());
|
||||
|
||||
REQUIRE(res == cli_flow_t::kExit);
|
||||
|
||||
auto output = ostr.str();
|
||||
|
||||
REQUIRE(output.find(fmt::format(
|
||||
"clang-uml {}", clanguml::version::CLANG_UML_VERSION)) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Test cli handler print_config", "[unit-test]")
|
||||
{
|
||||
using clanguml::cli::cli_flow_t;
|
||||
using clanguml::cli::cli_handler;
|
||||
|
||||
std::vector<const char *> argv = {"clang-uml", "--config",
|
||||
"./test_config_data/simple.yml", "--dump-config"};
|
||||
|
||||
std::ostringstream ostr;
|
||||
cli_handler cli{ostr, make_sstream_logger(ostr)};
|
||||
|
||||
auto res = cli.handle_options(argv.size(), argv.data());
|
||||
|
||||
REQUIRE(res == cli_flow_t::kExit);
|
||||
|
||||
auto output = ostr.str();
|
||||
YAML::Node doc = YAML::Load(output);
|
||||
|
||||
REQUIRE(doc["diagrams"]["class_main"]);
|
||||
}
|
||||
@@ -265,39 +265,55 @@ TEST_CASE("Test config diagram_templates", "[unit-test]")
|
||||
auto cfg =
|
||||
clanguml::config::load("./test_config_data/diagram_templates.yml");
|
||||
|
||||
REQUIRE(cfg.diagram_templates().size() == 3);
|
||||
REQUIRE(cfg.diagram_templates().size() == 4);
|
||||
|
||||
REQUIRE(cfg.diagram_templates()["bases_hierarchy_tmpl"].type ==
|
||||
REQUIRE(cfg.diagram_templates()["parents_hierarchy_tmpl"].type ==
|
||||
clanguml::common::model::diagram_t::kClass);
|
||||
REQUIRE(cfg.diagram_templates()["bases_hierarchy_tmpl"].jinja_template ==
|
||||
R"("{{ class_name }}_parents_hierarchy":
|
||||
REQUIRE(cfg.diagram_templates()["parents_hierarchy_tmpl"].jinja_template ==
|
||||
"{{ diagram_name }}:"
|
||||
R"(
|
||||
type: class
|
||||
{% if exists("glob") %}
|
||||
glob: [{{ glob }}]
|
||||
{% endif %}
|
||||
{% if exists("using_namespace") %}
|
||||
using_namespace: {{ using_namespace }}
|
||||
{% endif %}
|
||||
include:
|
||||
parents: "{{ class_name }}"
|
||||
namespaces: "{{ namespace_name }}"
|
||||
parents: [{{ class_name }}]
|
||||
namespaces: [{{ namespace_names }}]
|
||||
relationships:
|
||||
- inheritance
|
||||
exclude:
|
||||
access: [public, protected, private]
|
||||
plantuml:
|
||||
before:
|
||||
- left to right direction)");
|
||||
- left to right direction
|
||||
)");
|
||||
|
||||
REQUIRE(cfg.diagram_templates()["children_hierarchy_tmpl"].type ==
|
||||
clanguml::common::model::diagram_t::kClass);
|
||||
REQUIRE(cfg.diagram_templates()["children_hierarchy_tmpl"].jinja_template ==
|
||||
R"("{{ class_name }}_children_hierarchy":
|
||||
REQUIRE(cfg.diagram_templates()["subclass_hierarchy_tmpl"].jinja_template ==
|
||||
"{{ diagram_name }}:"
|
||||
R"(
|
||||
type: class
|
||||
{% if exists("glob") %}
|
||||
glob: [{{ glob }}]
|
||||
{% endif %}
|
||||
{% if exists("using_namespace") %}
|
||||
using_namespace: {{ using_namespace }}
|
||||
{% endif %}
|
||||
include:
|
||||
subclasses: "{{ class_name }}"
|
||||
namespaces: "{{ namespace_name }}"
|
||||
parents: [{{ class_name }}]
|
||||
namespaces: [{{ namespace_name }}]
|
||||
relationships:
|
||||
- inheritance
|
||||
exclude:
|
||||
access: [public, protected, private]
|
||||
plantuml:
|
||||
before:
|
||||
- left to right direction)");
|
||||
- left to right direction
|
||||
)");
|
||||
|
||||
REQUIRE(cfg.diagram_templates()["main_sequence_tmpl"].type ==
|
||||
clanguml::common::model::diagram_t::kSequence);
|
||||
|
||||
@@ -2,33 +2,10 @@ compilation_database_dir: debug
|
||||
output_directory: output
|
||||
|
||||
diagram_templates:
|
||||
bases_hierarchy_tmpl:
|
||||
'{{ class_name }}_parents_hierarchy':
|
||||
type: class
|
||||
include:
|
||||
parents: '{{ class_name }}'
|
||||
namespaces: '{{ namespace_name }}'
|
||||
relationships:
|
||||
- inheritance
|
||||
exclude:
|
||||
access: [public, protected, private]
|
||||
plantuml:
|
||||
before:
|
||||
- left to right direction
|
||||
children_hierarchy_tmpl: |
|
||||
'{{ class_name }}_children_hierarchy':
|
||||
type: class
|
||||
include:
|
||||
subclasses: '{{ class_name }}'
|
||||
namespaces: '{{ namespace_name }}'
|
||||
relationships:
|
||||
- inheritance
|
||||
exclude:
|
||||
access: [public, protected, private]
|
||||
plantuml:
|
||||
before:
|
||||
- left to right direction
|
||||
main_sequence_tmpl: |
|
||||
main_sequence_tmpl:
|
||||
description: Sequence diagram of the main() function
|
||||
type: sequence
|
||||
template: |
|
||||
main_sequence_diagram:
|
||||
type: sequence
|
||||
glob: [ {{ glob }} ]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
compilation_database_dir: debug
|
||||
output_directory: output
|
||||
|
||||
diagrams:
|
||||
class_main:
|
||||
type: class
|
||||
|
||||
Reference in New Issue
Block a user