[orc-rt] De-duplicate some test helper APIs. (#187187)

Moves noErrors, mockExecutorProcessInfo, and NoDispatcher into
CommonTestUtils.h where they can be re-used between tests.
This commit is contained in:
Lang Hames 2026-03-18 16:31:45 +11:00 committed by GitHub
parent dc8fd02b62
commit 950292535e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 30 deletions

View File

@ -15,22 +15,10 @@
#include "orc-rt/TaskDispatcher.h"
#include "gtest/gtest.h"
#include "CommonTestUtils.h"
using namespace orc_rt;
static ExecutorProcessInfo mockExecutorProcessInfo() noexcept {
return ExecutorProcessInfo("arm64-apple-darwin", 16384);
}
class NoDispatcher : public TaskDispatcher {
public:
void dispatch(std::unique_ptr<Task> T) override {
assert(false && "strictly no dispatching!");
}
void shutdown() override {}
};
static void noErrors(Error Err) { cantFail(std::move(Err)); }
TEST(BootstrapInfoTest, ExplicitConstruction) {
Session S(mockExecutorProcessInfo(), std::make_unique<NoDispatcher>(),
noErrors);

View File

@ -9,11 +9,28 @@
#ifndef ORC_RT_UNITTEST_COMMONTESTUTILS_H
#define ORC_RT_UNITTEST_COMMONTESTUTILS_H
#include "orc-rt/Error.h"
#include "orc-rt/ExecutorProcessInfo.h"
#include "orc-rt/TaskDispatcher.h"
#include "orc-rt/move_only_function.h"
#include <cstddef>
#include <future>
inline void noErrors(orc_rt::Error Err) { orc_rt::cantFail(std::move(Err)); }
inline orc_rt::ExecutorProcessInfo mockExecutorProcessInfo() noexcept {
return orc_rt::ExecutorProcessInfo("arm64-apple-darwin", 16384);
}
class NoDispatcher : public orc_rt::TaskDispatcher {
public:
void dispatch(std::unique_ptr<orc_rt::Task> T) override {
assert(false && "strictly no dispatching!");
}
void shutdown() override {}
};
template <size_t Idx = 0> class OpCounter {
public:
OpCounter() { ++DefaultConstructions; }

View File

@ -17,6 +17,8 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "CommonTestUtils.h"
#include <chrono>
#include <deque>
#include <future>
@ -68,18 +70,6 @@ public:
void doMoreConfig(int) noexcept {}
};
static ExecutorProcessInfo mockExecutorProcessInfo() noexcept {
return ExecutorProcessInfo("arm64-apple-darwin", 16384);
}
class NoDispatcher : public TaskDispatcher {
public:
void dispatch(std::unique_ptr<Task> T) override {
assert(false && "strictly no dispatching!");
}
void shutdown() override {}
};
class EnqueueingDispatcher : public TaskDispatcher {
public:
using OnShutdownRunFn = move_only_function<void()>;
@ -273,10 +263,6 @@ private:
orc_rt_WrapperFunction Fn;
};
// Non-overloaded version of cantFail: allows easy construction of
// move_only_functions<void(Error)>s.
static void noErrors(Error Err) { cantFail(std::move(Err)); }
TEST(SessionTest, TrivialConstructionAndDestruction) {
Session S(mockExecutorProcessInfo(), std::make_unique<NoDispatcher>(),
noErrors);