File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 22
33#pragma once
44
5- #include " global .h"
5+ #include " valuedata .h"
66#include " spimpl.h"
77
88namespace libscratchcpp
@@ -27,6 +27,7 @@ class LIBSCRATCHCPP_EXPORT Thread
2727 Script *script () const ;
2828
2929 void run ();
30+ ValueData runReporter ();
3031 bool runPredicate ();
3132 void kill ();
3233 void reset ();
Original file line number Diff line number Diff line change @@ -60,6 +60,15 @@ void Thread::run()
6060 string_pool_set_thread (nullptr );
6161}
6262
63+ /* ! Runs the reporter and returns its return value. */
64+ ValueData Thread::runReporter ()
65+ {
66+ string_pool_set_thread (this );
67+ ValueData ret = impl->code ->runReporter (impl->executionContext .get ());
68+ string_pool_set_thread (nullptr );
69+ return ret;
70+ }
71+
6372/* ! Runs the hat predicate and returns its return value. */
6473bool Thread::runPredicate ()
6574{
Original file line number Diff line number Diff line change 22#include < scratchcpp/script.h>
33#include < scratchcpp/executioncontext.h>
44#include < scratchcpp/promise.h>
5+ #include < scratchcpp/value.h>
56#include < targetmock.h>
67#include < enginemock.h>
78#include < executablecodemock.h>
@@ -50,6 +51,13 @@ TEST_F(ThreadTest, Run)
5051 m_thread->run ();
5152}
5253
54+ TEST_F (ThreadTest, RunReporter)
55+ {
56+ Value v = " test" ;
57+ EXPECT_CALL (*m_code, runReporter (m_ctx.get ())).WillOnce (Return (v.data ()));
58+ ASSERT_EQ (Value (m_thread->runReporter ()).toString (), v.toString ());
59+ }
60+
5361TEST_F (ThreadTest, RunPredicate)
5462{
5563 ASSERT_FALSE (m_thread->runPredicate ());
You can’t perform that action at this time.
0 commit comments