@@ -1466,6 +1466,34 @@ TEST(VirtualMachineTest, RunProcedures)
14661466 ASSERT_EQ (vm.registerCount (), 0 );
14671467}
14681468
1469+ TEST (VirtualMachineTest, RunUndefinedProcedure)
1470+ {
1471+ static unsigned int bytecode[] = {
1472+ OP_START , OP_INIT_PROCEDURE , OP_CONST , 0 , OP_ADD_ARG , OP_CONST , 1 , OP_ADD_ARG , OP_CALL_PROCEDURE , 0 , OP_NULL , OP_EXEC , 0 , OP_INIT_PROCEDURE , OP_CALL_PROCEDURE , 1 , OP_HALT
1473+ };
1474+ static unsigned int procedure2[] = { OP_START , OP_CONST , 2 , OP_PRINT , OP_HALT };
1475+ static unsigned int *procedures[] = { nullptr , procedure2 };
1476+ static BlockFunc functions[] = { &testFunction3 };
1477+ static Value constValues[] = { " hello" , " world" , " test" };
1478+
1479+ VirtualMachine vm;
1480+ vm.setBytecode (bytecode);
1481+ vm.setProcedures (procedures);
1482+ vm.setFunctions (functions);
1483+ vm.setConstValues (constValues);
1484+ testing::internal::CaptureStdout ();
1485+ vm.run ();
1486+ ASSERT_TRUE (testing::internal::GetCapturedStdout ().empty ());
1487+ ASSERT_FALSE (vm.atEnd ());
1488+ ASSERT_EQ (vm.registerCount (), 0 );
1489+
1490+ testing::internal::CaptureStdout ();
1491+ vm.run ();
1492+ ASSERT_EQ (testing::internal::GetCapturedStdout (), " test\n " );
1493+ ASSERT_TRUE (vm.atEnd ());
1494+ ASSERT_EQ (vm.registerCount (), 0 );
1495+ }
1496+
14691497TEST (VirtualMachineTest, OP_BREAK_FRAME )
14701498{
14711499 static unsigned int bytecode1[] = { OP_START , OP_FOREVER_LOOP , OP_BREAK_FRAME , OP_LOOP_END , OP_HALT };
0 commit comments