bevyengine / bevyengine/bevy

Add regression test for spawning entities during remove hooks

Open
#16,260 2 comments 1 reaction 0 assignees View on GitHub
A-ECS C-Testing D-Straightforward S-Ready-For-Implementation X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

I have made a test for this, that fails at 0.14.2 but passes in current bevy main, so it should cover from this regression

```rs
#[test]
fn test_spawn_entities_during_on_remove_hook() {
#[derive(Component)]
struct MyComponent;

App::new()
.add_plugins(MinimalPlugins)
.add_systems(Startup, |world: &mut World| {
world.register_component_hooks::().on_remove(
|mut world, _entity, _component_id| {
world.commands().spawn_empty();
},
);
})
.add_systems(
Update,
|mut commands: Commands,
my_component_q: Query>,
mut exit_event: EventWriter,
mut after_first_frame: Local| {
for entity in &my_component_q {
commands.entity(entity).despawn();
}

commands.spawn(MyComponent);

if *after_first_frame {
exit_event.send(AppExit::Success);
}

*after_first_frame = true;
},
)
.run();
}
```

It's a bit of an unusual test (I'm not even sure if `MinimalPlugins` can be used in a test like this). It's more an integration test rather than a unit test. I don't know if there is some place inside Bevy repo where more of these tests exist. If so, I can open a PR to add it.

_Originally posted by @Maximetinu in https://github.com/bevyengine/bevy/issues/16219#issuecomment-2458452806_

Contributor guide

Open the contributing guide

Research direction

Start by locating existing Bevy integration or component-hook tests and determine where a test using App, MinimalPlugins, and the test_spawn_entities_during_on_remove_hook entry point belongs. Add the supplied regression scenario there and verify the test passes on current main while covering spawning entities from an on_remove hook.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.