wip: feat: lsd
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
light7734 2025-11-17 13:17:05 +03:30
parent b7ae2f7048
commit 72662f3742
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
10 changed files with 98 additions and 40 deletions

View file

@ -8,7 +8,9 @@ add_module(
arr.cppm arr.cppm
str.cppm str.cppm
set.cppm set.cppm
span.cppm
hash.cppm hash.cppm
utils.cppm
scope.cppm scope.cppm
bitwise.cppm bitwise.cppm
thread.cppm thread.cppm
@ -16,12 +18,6 @@ add_module(
src_location.cppm src_location.cppm
) )
add_module(NAME logger INTERFACES logger.cppm DEPENDENCIES lsd) add_module(NAME logger INTERFACES logger.cppm DEPENDENCIES lsd)
return()
add_module(NAME bitwise INTERFACES operations.cppm)
add_module(NAME env INTERFACES constants.cppm)
add_module(NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm)
add_module(NAME time INTERFACES timer.cppm)
add_module( add_module(
NAME NAME
test test
@ -32,8 +28,13 @@ add_module(
SOURCES SOURCES
entrypoint.cpp entrypoint.cpp
DEPENDENCIES DEPENDENCIES
lsd
logger logger
) )
return()
add_module(NAME env INTERFACES constants.cppm)
add_module(NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm)
add_module(NAME time INTERFACES timer.cppm)
add_module( add_module(
NAME NAME

View file

@ -1,6 +1,4 @@
export module logger; export module logger;
import std;
import lsd; import lsd;
namespace lt::log { namespace lt::log {
@ -64,16 +62,16 @@ struct [[maybe_unused]] print
} }
// clang-format on // clang-format on
std::unreachable(); lsd::unreachable();
}; };
const auto path = std::filesystem::path { location.file_name() }; const auto path = lsd::filesystem::path { location.file_name() };
std::println( lsd::println(
"{} {} ==> {}", "{} {} ==> {}",
to_string(level, location), to_string(level, location),
std::format("{}:{}", path.filename().string(), location.line()), lsd::format("{}:{}", path.filename().string(), location.line()),
std::format(format, std::forward<Args>(arguments)...) lsd::format(format, lsd::forward<Args>(arguments)...)
); );
} }
}; };
@ -91,7 +89,7 @@ struct [[maybe_unused]] trace
const lsd::src_location &location = lsd::src_location::current() const lsd::src_location &location = lsd::src_location::current()
) noexcept ) noexcept
{ {
print(Level::trace, location, format, std::forward<Args>(arguments)...); print(Level::trace, location, format, lsd::forward<Args>(arguments)...);
} }
}; };
@ -107,7 +105,7 @@ struct [[maybe_unused]] debug
const lsd::src_location &location = lsd::src_location::current() const lsd::src_location &location = lsd::src_location::current()
) noexcept ) noexcept
{ {
print(Level::debug, location, format, std::forward<Args>(arguments)...); print(Level::debug, location, format, lsd::forward<Args>(arguments)...);
} }
}; };
@ -123,7 +121,7 @@ struct [[maybe_unused]] info
const lsd::src_location &location = lsd::src_location::current() const lsd::src_location &location = lsd::src_location::current()
) noexcept ) noexcept
{ {
print(Level::info, location, format, std::forward<Args>(arguments)...); print(Level::info, location, format, lsd::forward<Args>(arguments)...);
} }
}; };
@ -139,7 +137,7 @@ struct [[maybe_unused]] warn
const lsd::src_location &location = lsd::src_location::current() const lsd::src_location &location = lsd::src_location::current()
) noexcept ) noexcept
{ {
print(Level::warn, location, format, std::forward<Args>(arguments)...); print(Level::warn, location, format, lsd::forward<Args>(arguments)...);
} }
}; };
@ -155,7 +153,7 @@ struct [[maybe_unused]] error
const lsd::src_location &location = lsd::src_location::current() const lsd::src_location &location = lsd::src_location::current()
) noexcept ) noexcept
{ {
print(Level::error, location, format, std::forward<Args>(arguments)...); print(Level::error, location, format, lsd::forward<Args>(arguments)...);
} }
}; };
@ -171,7 +169,7 @@ struct [[maybe_unused]] critical
const lsd::src_location &location = lsd::src_location::current() const lsd::src_location &location = lsd::src_location::current()
) noexcept ) noexcept
{ {
print(Level::critical, location, format, std::forward<Args>(arguments)...); print(Level::critical, location, format, lsd::forward<Args>(arguments)...);
} }
}; };

View file

@ -1,4 +1,5 @@
export module lsd.arr; export module lsd.arr;
import lsd.primitives;
import std; import std;
export namespace lt::lsd { export namespace lt::lsd {

12
modules/lsd/literals.cppm Normal file
View file

@ -0,0 +1,12 @@
export module lsd.literals;
import lsd.str;
import std;
export namespace lt {
constexpr str_view operator""sv(const char *str, unsigned long len) noexcept
{
return str_view { str, len };
}
} // namespace lt

View file

@ -4,7 +4,8 @@ export import lsd.vec;
export import lsd.arr; export import lsd.arr;
export import lsd.str; export import lsd.str;
export import lsd.hash; export import lsd.hash;
export import lsd.hash; export import lsd.span;
export import lsd.utils;
export import lsd.thread; export import lsd.thread;
export import lsd.ref_ptr; export import lsd.ref_ptr;
export import lsd.bitwise; export import lsd.bitwise;

View file

@ -18,4 +18,6 @@ using i64 = std::int64_t;
using f32 = float; using f32 = float;
using f64 = double; using f64 = double;
using size_t = std::size_t;
} // namespace lt } // namespace lt

6
modules/lsd/span.cppm Normal file
View file

@ -0,0 +1,6 @@
export module lsd.span;
import std;
export namespace lt::lsd {
using ::std::span;
}

View file

@ -9,7 +9,6 @@ using str = std::string;
using str_view = std::string_view; using str_view = std::string_view;
template<typename... T> template<typename... T>
using format_str = std::format_string<T...>; using format_str = std::format_string<T...>;

32
modules/lsd/utils.cppm Normal file
View file

@ -0,0 +1,32 @@
export module lsd.utils;
import std;
export namespace lt::lsd {
[[noreturn]] void unreachable() noexcept
{
#if defined(__clang__) || defined(__GNUC__)
__builtin_unreachable();
#elif defined(_MSC_VER)
std::terminate();
__assume(0);
#else
std::terminate();
#endif
}
// NOLINTBEGIN
using ::std::declval;
using ::std::format;
using ::std::forward;
using ::std::move;
using ::std::println;
namespace filesystem {
using ::std::filesystem::path;
}
// NOLINTEND
} // namespace lt::lsd

View file

@ -2,22 +2,28 @@ import logger;
import test.test; import test.test;
import test.registry; import test.registry;
import std; import lsd;
using namespace ::lt;
using namespace ::lt::test; using namespace ::lt::test;
void parse_option(std::string_view argument, Registry::Options &options) constexpr lsd::str_view operator""_sv(const char *str, unsigned long len) noexcept
{ {
constexpr auto case_str = std::string_view { "--case=" }; return lsd::str_view { str, len };
constexpr auto suite_str = std::string_view { "--suite=" }; }
if (argument == "--stop-on-fail") void parse_option(lsd::str_view argument, Registry::Options &options)
{
constexpr auto case_str = lsd::str_view { "--case=" };
constexpr auto suite_str = lsd::str_view { "--suite=" };
if (argument == "--stop-on-fail"_sv)
{ {
options.stop_on_fail = true; options.stop_on_fail = true;
return; return;
} }
if (argument.starts_with("--mode=") && argument.substr(7ul) == "stats") if (argument.starts_with("--mode="_sv) && argument.substr(7ul) == "stats")
{ {
options.execution_policy = Registry::ExecutionPolicy::stats; options.execution_policy = Registry::ExecutionPolicy::stats;
return; return;
@ -26,14 +32,14 @@ void parse_option(std::string_view argument, Registry::Options &options)
if (argument.starts_with(suite_str) && argument.length() > suite_str.size()) if (argument.starts_with(suite_str) && argument.length() > suite_str.size())
{ {
options.suite_regex = argument.substr(suite_str.length()); options.suite_regex = argument.substr(suite_str.length());
std::println("SUITE REGEX: {}", options.suite_regex); lsd::println("SUITE REGEX: {}", options.suite_regex);
return; return;
} }
if (argument.starts_with(case_str) && argument.length() > case_str.size()) if (argument.starts_with(case_str) && argument.length() > case_str.size())
{ {
options.case_regex = argument.substr(case_str.length()); options.case_regex = argument.substr(case_str.length());
std::println("CASE REGEX: {}", options.case_regex); lsd::println("CASE REGEX: {}", options.case_regex);
return; return;
} }
@ -42,19 +48,19 @@ void parse_option(std::string_view argument, Registry::Options &options)
void print_help() void print_help()
{ {
std::println("Options: "); lsd::println("Options: ");
std::println("--stop-on-fail --> Stops executing the remaining tests on first failure"); lsd::println("--stop-on-fail --> Stops executing the remaining tests on first failure");
std::println("--suite --> Regex for running specific suite(s)"); lsd::println("--suite --> Regex for running specific suite(s)");
std::println("--case --> Regex for running specific test(s)"); lsd::println("--case --> Regex for running specific test(s)");
std::println("--mode=stats --> Executes tests with an alternative policy"); lsd::println("--mode=stats --> Executes tests with an alternative policy");
std::println("\t---> stats: Print statistics about the tests without running any"); lsd::println("\t---> stats: Print statistics about the tests without running any");
std::println("--help | -h --> ~You just used it! :D"); lsd::println("--help | -h --> ~You just used it! :D");
} }
auto main(std::int32_t argc, char **argv) -> std::int32_t auto main(i32 argc, char **argv) -> i32
try try
{ {
auto raw_arguments = std::span<char *>(argv, argc); auto raw_arguments = lsd::span<char *>(argv, argc);
auto options = Registry::Options {}; auto options = Registry::Options {};
for (auto idx = 0; auto &raw_argument : raw_arguments) for (auto idx = 0; auto &raw_argument : raw_arguments)
@ -65,7 +71,7 @@ try
continue; continue;
} }
auto argument = std::string_view(raw_argument); auto argument = lsd::str_view(raw_argument);
if (argument == "-h" || argument == "--help") if (argument == "-h" || argument == "--help")
{ {
@ -83,7 +89,7 @@ try
} }
} }
return static_cast<std::int32_t>(Registry::run_all(options)); return static_cast<i32>(Registry::run_all(options));
} }
catch (const std::exception &exp) catch (const std::exception &exp)
{ {