Build: qualify wasm test suite with portable libc++ fallbacks (refs #38)

This commit is contained in:
faumaray committed 2026-12-03 17:43:14 +03:00
1 parent 1ba60d5d6a
commit f0820b778f
7 files changed
+163 -12

No files matched your search

+48
View File
@@ -7,6 +7,10 @@
#include <optional>
#include <utility>
#if !defined(__cpp_lib_atomic_shared_ptr)
#include <mutex>
#endif
namespace Void::Core
{
@@ -226,7 +230,51 @@ template <typename T> class Publication
private:
#if defined(__cpp_lib_atomic_shared_ptr)
std::atomic<std::shared_ptr<State>> current_;
#else
// Older libc++ (e.g. Emscripten) does not implement the
// atomic<shared_ptr> specialization. Keep the same load /
// compare-exchange surface with a mutex-protected pointer; the
// publication is still coherent for single-writer/multi-reader use.
class AtomicStatePtr
{
public:
explicit AtomicStatePtr(std::shared_ptr<State> initial)
: current_(std::move(initial))
{
}
[[nodiscard]] std::shared_ptr<State>
load(std::memory_order) const
{
std::lock_guard lock{mutex_};
return current_;
}
bool compare_exchange_weak(std::shared_ptr<State>& expected,
std::shared_ptr<State> desired,
std::memory_order,
std::memory_order)
{
std::lock_guard lock{mutex_};
if (current_ != expected) {
expected = current_;
return false;
}
current_ = std::move(desired);
return true;
}
private:
mutable std::mutex mutex_;
std::shared_ptr<State> current_;
};
AtomicStatePtr current_;
#endif
};
} // namespace Void::Core
+5
View File
@@ -1,6 +1,7 @@
#pragma once
#include <Void/TestingMock/Matcher.hpp>
#include <Void/TestingMock/MoveOnlyFunction.hpp>
#include <Void/TestingMock/Session.hpp>
#include <concepts>
@@ -30,7 +31,11 @@ namespace Void::TestingMock::Detail
std::tuple<MatcherHolder<std::decay_t<Args>>...>;
/// Move-only function — supports unique_ptr-capturing lambdas,
/// move-only arguments, and move-only return values.
#if defined(__cpp_lib_move_only_function)
using Action = std::move_only_function<R(Args...)>;
#else
using Action = MoveOnlyFunction<R(Args...)>;
#endif
Expectation(MatcherTuple matchers, std::source_location loc)
: m_matchers(std::move(matchers)), m_location(loc)
@@ -0,0 +1,73 @@
#pragma once
#include <concepts>
#include <cstddef>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
namespace Void::TestingMock::Detail
{
/// Minimal move-only type-erased callable with the subset of
/// std::move_only_function used by TestingMock. Only needed on standard
/// libraries that do not implement std::move_only_function (older libc++,
/// e.g. Emscripten).
template <typename Signature> class MoveOnlyFunction;
template <typename R, typename... Args>
class MoveOnlyFunction<R(Args...)>
{
private:
struct Base {
virtual ~Base() = default;
virtual R invoke(Args&&... args) = 0;
};
template <typename F> struct Model final : Base {
explicit Model(F callable) : fn(std::move(callable)) {}
R invoke(Args&&... args) override
{
return std::invoke(fn, std::forward<Args>(args)...);
}
F fn;
};
public:
MoveOnlyFunction() noexcept = default;
MoveOnlyFunction(std::nullptr_t) noexcept {}
template <typename F>
requires std::invocable<F&, Args...> &&
(!std::same_as<std::remove_cvref_t<F>,
MoveOnlyFunction>)
MoveOnlyFunction(F&& callable)
: impl_(std::make_unique<Model<std::remove_cvref_t<F>>>(
std::forward<F>(callable)))
{
}
MoveOnlyFunction(MoveOnlyFunction&&) noexcept = default;
MoveOnlyFunction& operator=(MoveOnlyFunction&&) noexcept = default;
MoveOnlyFunction(const MoveOnlyFunction&) = delete;
MoveOnlyFunction& operator=(const MoveOnlyFunction&) = delete;
[[nodiscard]] explicit operator bool() const noexcept
{
return impl_ != nullptr;
}
R operator()(Args... args)
{
return impl_->invoke(std::forward<Args>(args)...);
}
private:
std::unique_ptr<Base> impl_;
};
} // namespace Void::TestingMock::Detail