container: root: macros: add Pluggable support
- Adds requirements to support auto-(un)load'ing, refactors - Adds loader argument to unit tests and benchmarks * Filters can now be passed as a loader argument - Adds loader argument to Hash macro * Factored out from shell caller
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// docker-finance | modern accounting for the power-user
|
||||
//
|
||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@@ -61,24 +61,57 @@ class Unit
|
||||
|
||||
public:
|
||||
//! \brief Macro for running all tests
|
||||
//! \todo parameter arg that takes list of tests
|
||||
static int run()
|
||||
static int run(const std::string& arg)
|
||||
{
|
||||
static bool loaded{false};
|
||||
static const std::initializer_list<std::string> paths{
|
||||
{"test/unit/hash.hh"},
|
||||
{"test/unit/random.hh"},
|
||||
{"test/unit/type.hh"},
|
||||
{"test/unit/utility.hh"}};
|
||||
::testing::GTEST_FLAG(filter) = arg.empty() ? "*" : arg;
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
::dfi::common::Command::load(paths);
|
||||
loaded = true;
|
||||
}
|
||||
public:
|
||||
static constexpr std::initializer_list<std::string_view> m_paths{
|
||||
{"test/unit/hash.hh"},
|
||||
{"test/unit/random.hh"},
|
||||
{"test/unit/type.hh"},
|
||||
{"test/unit/utility.hh"}};
|
||||
};
|
||||
|
||||
//! \brief Pluggable entrypoint
|
||||
//! \ingroup cpp_macro_impl
|
||||
//! \since docker-finance 1.1.0
|
||||
class unit_C final
|
||||
{
|
||||
public:
|
||||
unit_C() = default;
|
||||
~unit_C() = default;
|
||||
|
||||
unit_C(const unit_C&) = default;
|
||||
unit_C& operator=(const unit_C&) = default;
|
||||
|
||||
unit_C(unit_C&&) = default;
|
||||
unit_C& operator=(unit_C&&) = default;
|
||||
|
||||
public:
|
||||
//! \brief Macro auto-loader
|
||||
//! \param arg GoogleTest regex filter
|
||||
static void load(const std::string& arg = {})
|
||||
{
|
||||
for (auto path : Unit::m_paths)
|
||||
::dfi::common::load(std::string{path});
|
||||
|
||||
::testing::InitGoogleTest();
|
||||
return RUN_ALL_TESTS(); // TODO(unassigned): caller do something about this
|
||||
|
||||
Unit::run(arg);
|
||||
}
|
||||
|
||||
//! \brief Macro auto-unloader
|
||||
//! \param arg Optional code to execute before unloading
|
||||
static void unload(const std::string& arg = {})
|
||||
{
|
||||
if (!arg.empty())
|
||||
::dfi::common::line(arg);
|
||||
|
||||
for (auto path : Unit::m_paths)
|
||||
::dfi::common::unload(std::string{path});
|
||||
}
|
||||
};
|
||||
} // namespace test
|
||||
|
||||
Reference in New Issue
Block a user