bevy_ecs_ldtk
bevy_ecs_ldtk copied to clipboard
LdtkPlugin cannot be ran in Testing Environment
Problem
When running this library (mimicking the basic example) in a Test, the test fails due to Resources existing relating to Rendering:
thread 'plugin_does_not_crash_without_render' panicked at /home/divark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.2/src/system/system_param.rs:570:17:
Resource requested by bevy_ecs_ldtk::systems::process_ldtk_levels does not exist: bevy_asset::assets::Assets<bevy_sprite::texture_atlas::TextureAtlasLayout>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_ecs_ldtk::systems::process_ldtk_levels`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
Steps to Reproduce
- Clone this library.
- Copy the test code below into
tests/no_render.rs
- Run
cargo test --test no_render --no-default-features --features=internal_levels
- Observe the error message mentioned above.
The Test Code
use bevy::prelude::*;
use bevy_ecs_ldtk::prelude::*;
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(LdtkWorldBundle {
ldtk_handle: asset_server.load("my_project.ldtk"),
..Default::default()
});
}
#[test]
fn plugin_does_not_crash_without_render() {
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.add_plugins(AssetPlugin::default());
app.add_plugins(ImagePlugin::default());
app.add_plugins(LdtkPlugin);
app.add_systems(Startup, setup);
app.insert_resource(LevelSelection::index(0));
let mut num_entities = 0;
loop {
app.update();
num_entities = app
.world
.query::<&EntityInstance>()
.iter(&app.world)
.count();
if num_entities != 0 {
break;
}
}
assert_ne!(num_entities, 0);
}