@@ -3902,6 +3902,45 @@ TEST_F(LLVMCodeBuilderTest, StopAndReturn)
39023902 ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
39033903}
39043904
3905+ TEST_F (LLVMCodeBuilderTest, MultipleScripts)
3906+ {
3907+ Sprite sprite;
3908+
3909+ // Script 1
3910+ createBuilder (&sprite, nullptr );
3911+
3912+ CompilerValue *v = m_builder->addConstValue (" script1" );
3913+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String }, { v });
3914+
3915+ auto code1 = m_builder->finalize ();
3916+
3917+ // Script 2
3918+ createBuilder (&sprite, nullptr );
3919+
3920+ v = m_builder->addConstValue (" script2" );
3921+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String }, { v });
3922+
3923+ auto code2 = m_builder->finalize ();
3924+
3925+ Script script1 (&sprite, nullptr , nullptr );
3926+ script1.setCode (code1);
3927+ Thread thread1 (&sprite, nullptr , &script1);
3928+ auto ctx = code1->createExecutionContext (&thread1);
3929+
3930+ testing::internal::CaptureStdout ();
3931+ code1->run (ctx.get ());
3932+ ASSERT_EQ (testing::internal::GetCapturedStdout (), " script1\n " );
3933+
3934+ Script script2 (&sprite, nullptr , nullptr );
3935+ script2.setCode (code2);
3936+ Thread thread2 (&sprite, nullptr , &script2);
3937+ ctx = code2->createExecutionContext (&thread2);
3938+
3939+ testing::internal::CaptureStdout ();
3940+ code2->run (ctx.get ());
3941+ ASSERT_EQ (testing::internal::GetCapturedStdout (), " script2\n " );
3942+ }
3943+
39053944TEST_F (LLVMCodeBuilderTest, Procedures)
39063945{
39073946 Sprite sprite;
0 commit comments