forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 f548d1b.
- Loading branch information
1 parent
d39a30f
commit 6ce931b
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+3.03 KB
test/fixtures/execute/tw-self-restarting-script-keeps-running-until-yield.sb3
Binary file not shown.
38 changes: 38 additions & 0 deletions
38
...napshot/__snapshots__/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; }) |
38 changes: 38 additions & 0 deletions
38
...napshots__/warp-timer/tw-self-restarting-script-keeps-running-until-yield.sb3.tw-snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; }) |