Commit 7f15a179 authored by Jiahao Li's avatar Jiahao Li Committed by Facebook Github Bot

Adds `make_mock` to `folly::LeakySingleton`.

Summary:
Provides a `make_mock` interface to `folly::LeakySingleton` for unit test
mocking.

Reviewed By: andriigrynenko

Differential Revision: D5382003

fbshipit-source-id: 9ab81dd64703f4f02772bfb8c85e020680abcc85
parent f0dfe0f6
......@@ -669,6 +669,21 @@ class LeakySingleton {
static T& get() { return instance(); }
static void make_mock(std::nullptr_t /* c */ = nullptr) {
make_mock([]() { return new T; });
}
static void make_mock(CreateFunc createFunc) {
auto& entry = entryInstance();
if (createFunc == nullptr) {
throw std::logic_error(
"nullptr_t should be passed if you want T to be default constructed");
}
entry.createFunc = createFunc;
entry.state = State::Dead;
}
private:
enum class State { NotRegistered, Dead, Living };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment