Skip to content

Commit

Permalink
feat universal: move yaml_config and assert_macros into universal
Browse files Browse the repository at this point in the history
Tests: протестировано CI
  • Loading branch information
apolukhin committed Sep 20, 2023
1 parent 58f4de6 commit 267f102
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 53 deletions.
39 changes: 20 additions & 19 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,6 @@
"core/include/userver/utils/statistics/writer.hpp":"taxi/uservices/userver/core/include/userver/utils/statistics/writer.hpp",
"core/include/userver/utils/text.hpp":"taxi/uservices/userver/core/include/userver/utils/text.hpp",
"core/include/userver/utils/userver_info.hpp":"taxi/uservices/userver/core/include/userver/utils/userver_info.hpp",
"core/include/userver/yaml_config/fwd.hpp":"taxi/uservices/userver/core/include/userver/yaml_config/fwd.hpp",
"core/include/userver/yaml_config/impl/validate_static_config.hpp":"taxi/uservices/userver/core/include/userver/yaml_config/impl/validate_static_config.hpp",
"core/include/userver/yaml_config/iterator.hpp":"taxi/uservices/userver/core/include/userver/yaml_config/iterator.hpp",
"core/include/userver/yaml_config/map_to_array.hpp":"taxi/uservices/userver/core/include/userver/yaml_config/map_to_array.hpp",
"core/include/userver/yaml_config/merge_schemas.hpp":"taxi/uservices/userver/core/include/userver/yaml_config/merge_schemas.hpp",
"core/include/userver/yaml_config/schema.hpp":"taxi/uservices/userver/core/include/userver/yaml_config/schema.hpp",
"core/include/userver/yaml_config/yaml_config.hpp":"taxi/uservices/userver/core/include/userver/yaml_config/yaml_config.hpp",
"core/internal/include/userver/engine/task/task_processor_utils.hpp":"taxi/uservices/userver/core/internal/include/userver/engine/task/task_processor_utils.hpp",
"core/internal/include/userver/internal/net/net_listener.hpp":"taxi/uservices/userver/core/internal/include/userver/internal/net/net_listener.hpp",
"core/internal/src/net/net_listener.cpp":"taxi/uservices/userver/core/internal/src/net/net_listener.cpp",
Expand Down Expand Up @@ -1334,20 +1327,11 @@
"core/src/utils/text.cpp":"taxi/uservices/userver/core/src/utils/text.cpp",
"core/src/utils/text_test.cpp":"taxi/uservices/userver/core/src/utils/text_test.cpp",
"core/src/utils/userver_info.cpp":"taxi/uservices/userver/core/src/utils/userver_info.cpp",
"core/src/yaml_config/impl/validate_static_config.cpp":"taxi/uservices/userver/core/src/yaml_config/impl/validate_static_config.cpp",
"core/src/yaml_config/impl/validate_static_config_test.cpp":"taxi/uservices/userver/core/src/yaml_config/impl/validate_static_config_test.cpp",
"core/src/yaml_config/iterator.cpp":"taxi/uservices/userver/core/src/yaml_config/iterator.cpp",
"core/src/yaml_config/merge_schemas.cpp":"taxi/uservices/userver/core/src/yaml_config/merge_schemas.cpp",
"core/src/yaml_config/merge_schemas_test.cpp":"taxi/uservices/userver/core/src/yaml_config/merge_schemas_test.cpp",
"core/src/yaml_config/schema.cpp":"taxi/uservices/userver/core/src/yaml_config/schema.cpp",
"core/src/yaml_config/yaml_config.cpp":"taxi/uservices/userver/core/src/yaml_config/yaml_config.cpp",
"core/src/yaml_config/yaml_config_test.cpp":"taxi/uservices/userver/core/src/yaml_config/yaml_config_test.cpp",
"core/sys_coro/include/coroutines/coroutine.hpp":"taxi/uservices/userver/core/sys_coro/include/coroutines/coroutine.hpp",
"core/testing/include/userver/cache/statistics_mock.hpp":"taxi/uservices/userver/core/testing/include/userver/cache/statistics_mock.hpp",
"core/testing/include/userver/dump/operations_mock.hpp":"taxi/uservices/userver/core/testing/include/userver/dump/operations_mock.hpp",
"core/testing/include/userver/dump/test_helpers.hpp":"taxi/uservices/userver/core/testing/include/userver/dump/test_helpers.hpp",
"core/testing/include/userver/dynamic_config/test_helpers.hpp":"taxi/uservices/userver/core/testing/include/userver/dynamic_config/test_helpers.hpp",
"core/testing/include/userver/utest/assert_macros.hpp":"taxi/uservices/userver/core/testing/include/userver/utest/assert_macros.hpp",
"core/testing/include/userver/utest/current_process_open_files.hpp":"taxi/uservices/userver/core/testing/include/userver/utest/current_process_open_files.hpp",
"core/testing/include/userver/utest/default_logger_fixture.hpp":"taxi/uservices/userver/core/testing/include/userver/utest/default_logger_fixture.hpp",
"core/testing/include/userver/utest/dns_server_mock.hpp":"taxi/uservices/userver/core/testing/include/userver/utest/dns_server_mock.hpp",
Expand All @@ -1363,8 +1347,6 @@
"core/testing/src/dump/operations_mock.cpp":"taxi/uservices/userver/core/testing/src/dump/operations_mock.cpp",
"core/testing/src/dump/operations_mock_test.cpp":"taxi/uservices/userver/core/testing/src/dump/operations_mock_test.cpp",
"core/testing/src/dynamic_config/test_helpers_test.cpp":"taxi/uservices/userver/core/testing/src/dynamic_config/test_helpers_test.cpp",
"core/testing/src/utest/assert_macros.cpp":"taxi/uservices/userver/core/testing/src/utest/assert_macros.cpp",
"core/testing/src/utest/assert_macros_test.cpp":"taxi/uservices/userver/core/testing/src/utest/assert_macros_test.cpp",
"core/testing/src/utest/current_process_open_files.cpp":"taxi/uservices/userver/core/testing/src/utest/current_process_open_files.cpp",
"core/testing/src/utest/current_process_open_files_test.cpp":"taxi/uservices/userver/core/testing/src/utest/current_process_open_files_test.cpp",
"core/testing/src/utest/dns_server_mock.cpp":"taxi/uservices/userver/core/testing/src/utest/dns_server_mock.cpp",
Expand Down Expand Up @@ -3142,7 +3124,9 @@
"universal/include/userver/logging/log_helper_fwd.hpp":"taxi/uservices/userver/universal/include/userver/logging/log_helper_fwd.hpp",
"universal/include/userver/logging/null_logger.hpp":"taxi/uservices/userver/universal/include/userver/logging/null_logger.hpp",
"universal/include/userver/logging/stacktrace_cache.hpp":"taxi/uservices/userver/universal/include/userver/logging/stacktrace_cache.hpp",
"universal/include/userver/utest/assert_macros.hpp":"taxi/uservices/userver/universal/include/userver/utest/assert_macros.hpp",
"universal/include/userver/utest/death_tests.hpp":"taxi/uservices/userver/universal/include/userver/utest/death_tests.hpp",
"universal/include/userver/utest/impl/assert_macros.hpp":"taxi/uservices/userver/universal/include/userver/utest/impl/assert_macros.hpp",
"universal/include/userver/utest/literals.hpp":"taxi/uservices/userver/universal/include/userver/utest/literals.hpp",
"universal/include/userver/utest/using_namespace_userver.hpp":"taxi/uservices/userver/universal/include/userver/utest/using_namespace_userver.hpp",
"universal/include/userver/utils/algo.hpp":"taxi/uservices/userver/universal/include/userver/utils/algo.hpp",
Expand Down Expand Up @@ -3218,6 +3202,13 @@
"universal/include/userver/utils/underlying_value.hpp":"taxi/uservices/userver/universal/include/userver/utils/underlying_value.hpp",
"universal/include/userver/utils/uuid4.hpp":"taxi/uservices/userver/universal/include/userver/utils/uuid4.hpp",
"universal/include/userver/utils/void_t.hpp":"taxi/uservices/userver/universal/include/userver/utils/void_t.hpp",
"universal/include/userver/yaml_config/fwd.hpp":"taxi/uservices/userver/universal/include/userver/yaml_config/fwd.hpp",
"universal/include/userver/yaml_config/impl/validate_static_config.hpp":"taxi/uservices/userver/universal/include/userver/yaml_config/impl/validate_static_config.hpp",
"universal/include/userver/yaml_config/iterator.hpp":"taxi/uservices/userver/universal/include/userver/yaml_config/iterator.hpp",
"universal/include/userver/yaml_config/map_to_array.hpp":"taxi/uservices/userver/universal/include/userver/yaml_config/map_to_array.hpp",
"universal/include/userver/yaml_config/merge_schemas.hpp":"taxi/uservices/userver/universal/include/userver/yaml_config/merge_schemas.hpp",
"universal/include/userver/yaml_config/schema.hpp":"taxi/uservices/userver/universal/include/userver/yaml_config/schema.hpp",
"universal/include/userver/yaml_config/yaml_config.hpp":"taxi/uservices/userver/universal/include/userver/yaml_config/yaml_config.hpp",
"universal/internal/include/userver/internal/http/header_map_tests_helper.hpp":"taxi/uservices/userver/universal/internal/include/userver/internal/http/header_map_tests_helper.hpp",
"universal/internal/src/http/header_map_tests_helper.cpp":"taxi/uservices/userver/universal/internal/src/http/header_map_tests_helper.cpp",
"universal/library.yaml":"taxi/uservices/userver/universal/library.yaml",
Expand Down Expand Up @@ -3378,6 +3369,8 @@
"universal/src/logging/rate_limit.cpp":"taxi/uservices/userver/universal/src/logging/rate_limit.cpp",
"universal/src/logging/rate_limit.hpp":"taxi/uservices/userver/universal/src/logging/rate_limit.hpp",
"universal/src/logging/stacktrace_cache.cpp":"taxi/uservices/userver/universal/src/logging/stacktrace_cache.cpp",
"universal/src/utest/assert_macros.cpp":"taxi/uservices/userver/universal/src/utest/assert_macros.cpp",
"universal/src/utest/assert_macros_test.cpp":"taxi/uservices/userver/universal/src/utest/assert_macros_test.cpp",
"universal/src/utils/algo_test.cpp":"taxi/uservices/userver/universal/src/utils/algo_test.cpp",
"universal/src/utils/any_movable.cpp":"taxi/uservices/userver/universal/src/utils/any_movable.cpp",
"universal/src/utils/any_movable_test.cpp":"taxi/uservices/userver/universal/src/utils/any_movable_test.cpp",
Expand Down Expand Up @@ -3476,5 +3469,13 @@
"universal/src/utils/uuid4.cpp":"taxi/uservices/userver/universal/src/utils/uuid4.cpp",
"universal/src/utils/uuid4_test.cpp":"taxi/uservices/userver/universal/src/utils/uuid4_test.cpp",
"universal/src/utils/widget_fast_pimpl_test.cpp":"taxi/uservices/userver/universal/src/utils/widget_fast_pimpl_test.cpp",
"universal/src/utils/widget_fast_pimpl_test.hpp":"taxi/uservices/userver/universal/src/utils/widget_fast_pimpl_test.hpp"
"universal/src/utils/widget_fast_pimpl_test.hpp":"taxi/uservices/userver/universal/src/utils/widget_fast_pimpl_test.hpp",
"universal/src/yaml_config/impl/validate_static_config.cpp":"taxi/uservices/userver/universal/src/yaml_config/impl/validate_static_config.cpp",
"universal/src/yaml_config/impl/validate_static_config_test.cpp":"taxi/uservices/userver/universal/src/yaml_config/impl/validate_static_config_test.cpp",
"universal/src/yaml_config/iterator.cpp":"taxi/uservices/userver/universal/src/yaml_config/iterator.cpp",
"universal/src/yaml_config/merge_schemas.cpp":"taxi/uservices/userver/universal/src/yaml_config/merge_schemas.cpp",
"universal/src/yaml_config/merge_schemas_test.cpp":"taxi/uservices/userver/universal/src/yaml_config/merge_schemas_test.cpp",
"universal/src/yaml_config/schema.cpp":"taxi/uservices/userver/universal/src/yaml_config/schema.cpp",
"universal/src/yaml_config/yaml_config.cpp":"taxi/uservices/userver/universal/src/yaml_config/yaml_config.cpp",
"universal/src/yaml_config/yaml_config_test.cpp":"taxi/uservices/userver/universal/src/yaml_config/yaml_config_test.cpp"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/// @file userver/utest/assert_macros.hpp
/// @brief Extensions to the gtest macros for printing and testing exceptions
/// that could work even without coroutine environment.
/// @ingroup userver_universal

#include <exception>
#include <functional>
Expand All @@ -13,37 +15,9 @@
#include <gtest/gtest.h>

#include <userver/utest/death_tests.hpp>
#include <userver/utest/impl/assert_macros.hpp>
#include <userver/utils/invariant_error.hpp>

USERVER_NAMESPACE_BEGIN

namespace utest::impl {

template <typename ExceptionType>
bool IsSubtype(const std::exception& ex) noexcept {
static_assert(
std::is_base_of_v<std::exception, ExceptionType>,
"Exception types not inherited from std::exception are not supported");
if constexpr (std::is_same_v<ExceptionType, std::exception>) {
return true;
} else {
return dynamic_cast<const ExceptionType*>(&ex) != nullptr;
}
}

std::string AssertThrow(std::function<void()> statement,
std::string_view statement_text,
std::function<bool(const std::exception&)> type_checker,
const std::type_info& expected_type,
std::string_view message_substring);

std::string AssertNoThrow(std::function<void()> statement,
std::string_view statement_text);

} // namespace utest::impl

USERVER_NAMESPACE_END

/// @cond
// NOLINTNEXTLINE (cppcoreguidelines-macro-usage)
#define IMPL_UTEST_ASSERT_THROW(statement, exception_type, message_substring, \
Expand Down
3 changes: 2 additions & 1 deletion universal/include/userver/utest/death_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/// @file userver/utest/death_tests.hpp
/// @brief Contains facilities for testing service crashes
/// @ingroup userver_universal

#include <gtest/gtest.h>

Expand Down Expand Up @@ -29,7 +30,7 @@ class DeathTestScope final {

USERVER_NAMESPACE_END

/// @ingroup userver_universal userver_utest
/// @ingroup userver_utest
///
/// @brief An optimized equivalent of EXPECT_DEATH.
///
Expand Down
37 changes: 37 additions & 0 deletions universal/include/userver/utest/impl/assert_macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <exception>
#include <functional>
#include <string>
#include <string_view>
#include <type_traits>
#include <typeinfo>

USERVER_NAMESPACE_BEGIN

namespace utest::impl {

template <typename ExceptionType>
bool IsSubtype(const std::exception& ex) noexcept {
static_assert(
std::is_base_of_v<std::exception, ExceptionType>,
"Exception types not inherited from std::exception are not supported");
if constexpr (std::is_same_v<ExceptionType, std::exception>) {
return true;
} else {
return dynamic_cast<const ExceptionType*>(&ex) != nullptr;
}
}

std::string AssertThrow(std::function<void()> statement,
std::string_view statement_text,
std::function<bool(const std::exception&)> type_checker,
const std::type_info& expected_type,
std::string_view message_substring);

std::string AssertNoThrow(std::function<void()> statement,
std::string_view statement_text);

} // namespace utest::impl

USERVER_NAMESPACE_END
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// @file userver/utest/using_namespace_userver.hpp
/// @brief For samples and snippets only! Has a `using namespace
/// USERVER_NAMESPACE;` if the USERVER_NAMESPACE is not empty.
/// @ingroup userver_universal

// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define USERVER_IS_EMPTY_MACRO_HELPER(X) X##1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/// @file userver/yaml_config/fwd.hpp
/// @brief Forward declarations of YamlConfig type and formats::parse::To.
/// @ingroup userver_universal

#include <userver/formats/parse/to.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/// @file userver/yaml_config/merge_schemas.hpp
/// @brief @copybrief yaml_config::MergeSchemas
/// @ingroup userver_universal

#include <userver/yaml_config/schema.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class SchemaPtr final {
formats::yaml::Value Serialize(const SchemaPtr& schema,
formats::serialize::To<formats::yaml::Value>);

/// @ingroup userver_universal
///
/// @brief JSON Schema-like type definition
///
/// @see @ref static-configs-validation "Static configs validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace yaml_config {
using Exception = formats::yaml::Exception;
using ParseException = formats::yaml::ParseException;

/// @ingroup userver_formats
/// @ingroup userver_formats userver_universal
///
/// @brief Datatype that represents YAML with substituted variables
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <userver/utest/assert_macros.hpp>
#include <userver/utest/impl/assert_macros.hpp>

#include <fmt/format.h>

Expand All @@ -7,6 +7,11 @@
#include <userver/utils/assert.hpp>
#include <userver/utils/traceful_exception.hpp>

#ifdef EXPECT_EQ
#error gtest.h headers should not be included to avoid userver-universal \
dependency on testing library
#endif

USERVER_NAMESPACE_BEGIN

namespace utest::impl {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <userver/yaml_config/schema.hpp>
#include <userver/yaml_config/yaml_config.hpp>

#include <userver/utest/utest.hpp>
#include <userver/utest/assert_macros.hpp>

USERVER_NAMESPACE_BEGIN

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <userver/yaml_config/schema.hpp>

#include <userver/utest/utest.hpp>
#include <userver/utest/assert_macros.hpp>

USERVER_NAMESPACE_BEGIN

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 267f102

Please sign in to comment.