From 6ce931b60a21693ef35a33827d572a70f665ce9f Mon Sep 17 00:00:00 2001 From: Muffin Date: Thu, 23 May 2024 14:09:37 -0500 Subject: [PATCH] Add test for behavior of self-restarting scripts The behavior is non-trivial as it will keep running the old thread unti it yields. I briefly tested putting `thread.status = 4` at the start of _restartThread and all the old execution tests still passed, so let's just add a bit more coverage. This was nearly regressed by f548d1b33c5a7dfa9053586e921384723f6cb407. --- ...rting-script-keeps-running-until-yield.sb3 | Bin 0 -> 3104 bytes ...-keeps-running-until-yield.sb3.tw-snapshot | 38 ++++++++++++++++++ ...-keeps-running-until-yield.sb3.tw-snapshot | 38 ++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 test/fixtures/execute/tw-self-restarting-script-keeps-running-until-yield.sb3 create mode 100644 test/snapshot/__snapshots__/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot create mode 100644 test/snapshot/__snapshots__/warp-timer/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot diff --git a/test/fixtures/execute/tw-self-restarting-script-keeps-running-until-yield.sb3 b/test/fixtures/execute/tw-self-restarting-script-keeps-running-until-yield.sb3 new file mode 100644 index 0000000000000000000000000000000000000000..ee8c61885e05aeaeed4c700156f37e610e7844f6 GIT binary patch literal 3104 zcma);XHXO97KRg=^j;N0?+6$IAt1eXL|{X22`EyfmxzRFl-`6;q&KBE1?d40pk zqDb%3k#gC&KX$J(cV^F-GvCZN^PZXa&v{;BJwhUK002M=fW2&nzmDsdY$5^xMrZ*5 z%IjaR$DXc8Ctq<_A5RZlhP%&q8QT61-HP^yom06F6mAa@mtB%*#!oyRXWsdS5ad#}cv@ zBC4JWz$NF7g{RvK`b+D_IFFPzFIV=*#w3OhrutUCdvSm@|O+PR?l^@r0gJjqkG;(Tg${hq{8CV2IRzICIE9Kls*oM93 zR#MRPKR$+a5}WFFN+sDY_ynYi`v=jEdex@MGZW+*wwO9?rQ}n6_x>KZ{*bekmnRT` zZYB~99oBft)Rve6)OQdrccl;X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zizf8R`$9v#4X)l=2#299-DS7$&`c{wB7{zAgFqQlVR&io)={e+u&vq2*i$cj} zNhDo6X<^wpc$mwFfKsEWq0+s;S2VK7lcPZ_u*sI06(OnxFG^1U0~!`JdY}j1IxBTka9mO)dy>o{ESRlvDiU6F zR?IFdeUZ%YWTnV%Hta@F2OB5LgX81Yd4k)@bE)9vUC2gMPW$^nn6~BgjHoIiwj=+gdl;npqodTlVa4&SOy!Xebx5+Y& zw!rkFqOL%yN#xq75a5NsW+!Ph5L9%iPix-9CIyj!FD4PEn6ccALBtq8H3EiKPLwtXsLE+(wABSBFoh0t_C=OtZFKeG)9nrV*Dp2NA&M2l8`azOnl z=qF`j`b&3F6TrAPsS_hsmzheyMV>>NS{Y{Q9)$POr?NHFW_6j45Od_sY9vXbfoA}- zst8EDh@$wjiToT%$P(27$^InOUdrUmq*e9ILN_l#NesD82?W+|bksRiiYe4hX0_$Y zW;&~^KN8(q^Inus6LXc>Q!@#T4y;!DxfHIHXL1l36qSPRbvXu(yS1M!!<{4e zFN5W}19QCkHvS+k+Jjvs%(Sbja!HG|oA{)a6%Rj6iHTQ^qwPKq;)Y{om|oxa$)$=& z66`ltsi$J>TBx82g};P;5dlB?n6ZAF;9bDVbLSvaJ2bJK@V6+O?;^vHwi441?)%{9 zO!l|Hj7#STR^};8qcYqL&Tx9*t8~>KH+Mz0fIIw|kg$FnMrf=DBwz&m|FnD!lz-Ge yv-9uD-#PTRY~eb6{~Id(zVUYm{JpX98V&yj3C4QFB!8(0ulvjOD|U?&0N_6uq=JtC literal 0 HcmV?d00001 diff --git a/test/snapshot/__snapshots__/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot b/test/snapshot/__snapshots__/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot new file mode 100644 index 00000000000..2783ca0147a --- /dev/null +++ b/test/snapshot/__snapshots__/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot @@ -0,0 +1,38 @@ +// TW Snapshot +// Input SHA-256: dc029abbf128cea0830f4578e89619949837ec26dfa76f110ca599a9ee12e66e + +// Sprite1 script +(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); +const b0 = runtime.getOpcodeFunction("looks_say"); +const b1 = stage.variables["G{NQ*NXG*qzywe1Q3?FM"]; +const b2 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +return function* genXYZ () { +yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "c", null); +b1.value = 0; +b2.value = 0; +startHats("event_whenbroadcastreceived", { BROADCAST_OPTION: "message1" }); +retire(); return; +}; }) + +// Sprite1 script +(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); +const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +const b1 = stage.variables["G{NQ*NXG*qzywe1Q3?FM"]; +const b2 = runtime.getOpcodeFunction("looks_say"); +return function* genXYZ () { +if (compareEqual(b0.value, 0)) { +b0.value = 1; +startHats("event_whenbroadcastreceived", { BROADCAST_OPTION: "message1" }); +b1.value = 1; +for (var a0 = 1; a0 >= 0.5; a0--) { +yield; +} +b1.value = 2; +} else { +if (((+b1.value || 0) === 1)) { +yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b2, false, false, "p", null); +} +yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b2, false, false, "n", null); +} +retire(); return; +}; }) diff --git a/test/snapshot/__snapshots__/warp-timer/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot b/test/snapshot/__snapshots__/warp-timer/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot new file mode 100644 index 00000000000..2783ca0147a --- /dev/null +++ b/test/snapshot/__snapshots__/warp-timer/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot @@ -0,0 +1,38 @@ +// TW Snapshot +// Input SHA-256: dc029abbf128cea0830f4578e89619949837ec26dfa76f110ca599a9ee12e66e + +// Sprite1 script +(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); +const b0 = runtime.getOpcodeFunction("looks_say"); +const b1 = stage.variables["G{NQ*NXG*qzywe1Q3?FM"]; +const b2 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +return function* genXYZ () { +yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "c", null); +b1.value = 0; +b2.value = 0; +startHats("event_whenbroadcastreceived", { BROADCAST_OPTION: "message1" }); +retire(); return; +}; }) + +// Sprite1 script +(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); +const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +const b1 = stage.variables["G{NQ*NXG*qzywe1Q3?FM"]; +const b2 = runtime.getOpcodeFunction("looks_say"); +return function* genXYZ () { +if (compareEqual(b0.value, 0)) { +b0.value = 1; +startHats("event_whenbroadcastreceived", { BROADCAST_OPTION: "message1" }); +b1.value = 1; +for (var a0 = 1; a0 >= 0.5; a0--) { +yield; +} +b1.value = 2; +} else { +if (((+b1.value || 0) === 1)) { +yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b2, false, false, "p", null); +} +yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b2, false, false, "n", null); +} +retire(); return; +}; })