12namespace hegel::impl::test_case {
48 TestCase(
const TestCase&) =
delete;
49 TestCase& operator=(
const TestCase&) =
delete;
56 TestCase& operator=(TestCase&&) noexcept;
77 template <typename T> T
draw(const
generators::Generator<T>& gen) const;
93 T
draw(std::string_view name,
100 T
draw(std::string_view name,
101 const
generators::AnyGenerator<T>& gen) const;
120 template <typename T>
137 template <typename T>
185 void target(
double score, std::string_view label =
"") const;
203 void event(std::string_view label) const;
251 [[noreturn]]
void repeat(const std::function<
void()>& body) const;
263 void note(std::string_view message) const;
340 template <typename F> auto
spawn(F fn) const;
343 explicit TestCase(std::unique_ptr<impl::test_case::TestCaseData> data);
347 impl::test_case::TestCaseData* data()
const {
return data_.get(); }
351 std::unique_ptr<impl::test_case::TestCaseData> data_;
364 Worker(std::thread thread, std::future<T> future)
365 : thread_(std::move(thread)), future_(std::move(future)) {}
372 if (thread_.joinable()) {
386 if (thread_.joinable()) {
389 return future_.get();
394 std::future<T> future_;
398 using R = std::invoke_result_t<F, TestCase&>;
399 std::packaged_task<R()> task(
400 [fn = std::move(fn), cloned_tc =
clone()]()
mutable {
401 return fn(cloned_tc);
403 std::future<R> future = task.get_future();
404 return Worker<R>(std::thread(std::move(task)), std::move(future));
Writes to the document that a failure report shows.
Definition printer.h:55
auto spawn(F fn) const
Run fn on a clone of this test case in a new thread.
Definition test_case.h:397
void set_worker(std::size_t worker_index)
Attribute what this test case prints from now on to a worker.
void repeat(const std::function< void()> &body) const
Run body over and over until the engine ends the test case. It never returns.
void event(std::string_view label) const
Record an event for the end-of-run statistics report.
void reject() const
Reject the current test case unconditionally.
void assume(bool condition) const
Reject the current test case if condition is false.
void target(double score, std::string_view label="") const
Record a score for the engine's targeted-search phase to maximize.
T draw_and_print(const generators::Generator< T > &gen, Printer &printer) const
Draw a value from a printable generator and print it to printer.
Definition core.h:1063
TestCase clone() const
Creates a clone of this test case with an independent choice sequence forked from this test case.
TestCase(TestCase &&) noexcept
Move-constructs, transferring ownership of the underlying handle.
void event_value(std::string_view label, double value) const
Record a numeric observation for the end-of-run statistics report.
void note(std::string_view message) const
Record a message that will be printed on the final replay of a failing test case.
T draw_silent(const generators::AnyGenerator< T > &gen) const
Draw a random value from any generator, without printing it.
Definition core.h:1053
T draw(const generators::Generator< T > &gen) const
Draw a random value from a printable generator.
Definition core.h:993
Handle to a worker started by TestCase::spawn().
Definition test_case.h:361
T join()
Await the worker and return its result.
Definition test_case.h:385
Worker(Worker &&) noexcept=default
Move-constructs, transferring ownership of the running worker.
A generator: a handle to an IGenerator.
Definition core.h:311
A printable generator: TestCase::draw() accepts it.
Definition core.h:470
Hegel generators.
Definition core.h:25
Main namespace.
Definition config.h:29