Terasology icon indicating copy to clipboard operation
Terasology copied to clipboard

load game from save file in unit test

Open keturn opened this issue 2 years ago • 3 comments

In order to do full round-trip tests of saving and loading Terasology worlds, MTE needs a way to load from a saved game.

keturn avatar Jun 15 '22 22:06 keturn

I was going to say "this is probably not too hard," but I didn't expect this: https://github.com/MovingBlocks/Terasology/blob/fbc40c3fe2cf0c605f950c19e6c021f43aa43c05/engine/src/main/java/org/terasology/engine/core/subsystem/headless/mode/StateHeadlessSetup.java#L55-L60

Headless mode always loads a save if it can find any! That's useful, but also a little scary: it means MTE could end up loading a game that doesn't match its supplied configuration without even realizing it.

keturn avatar Jun 15 '22 22:06 keturn

Here's where MTE sets its home path: https://github.com/MovingBlocks/Terasology/blob/fbc40c3fe2cf0c605f950c19e6c021f43aa43c05/engine-tests/src/main/java/org/terasology/engine/integrationenvironment/Engines.java#L228-L230

so if we want to load things, we either need to put the things in that place, or point it to the place where things are, before it goes in to the StateHeadlessSetup state.

It seems like we can hack this together with the custom subsystem support we already have.

Is there any way for us to tell, once the world is up and running, whether it's from a saved game or newly-generated in this session?

keturn avatar Jun 15 '22 22:06 keturn

This works, more or less: https://github.com/Terasology/WildAnimals/blob/158a008ec595daacf61fe8696bae66031859743a/src/test/java/org/terasology/wildAnimals/system/WildAnimalsSpawnSystemTest.java#L148

Leaving the test lifecycle on PER_METHOD, then using a static field in the subsystem to keep the home directory the same between tests.

Having more explicit support for this would still be nice, as that implementation relies on some unstable implementation details, such as the way the first test's home directory isn't cleaned up right away as soon as that one test finishes.

keturn avatar Jun 17 '22 14:06 keturn