bevyengine / bevyengine/bevy

`DropTestHelper` cannot be used when not testing for at least one `panic`

Open
#5,615 0 comments 0 reactions 0 assignees View on GitHub
C-Testing
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

`bevy_ecs` has a `DropTestHelper` struct for asserting the expected drop order/panic behavior for components/resource.
This is what a test using it could look like:
```rust
let helper = DropTestHelper::new();

let res = panic::catch_unwind(|| {
let mut world = World::new();
world
.spawn()
.insert(helper.make_component(true, 0))
.insert(helper.make_component(false, 1));

println!("Done inserting! Dropping world...");
});

let drop_log = helper.finish(res);

assert_eq!(
&*drop_log,
[
DropLogItem::Create(0),
DropLogItem::Create(1),
DropLogItem::Drop(0),
DropLogItem::Drop(1),
]
);
```

This test however fails:
```rust
#[test]
fn drop_test_helper() {
let drop_test_helper = DropTestHelper::new();
let res = std::panic::catch_unwind(|| {
drop(drop_test_helper.make_component(false, 0));
});
drop_test_helper.finish(res);
}
```
because the `DropTestHelper`s `expected_panic_flag` needs to be _defused_ by dropping a `drop_test_helper.make_component(true, _)` (note the `true` parameter):
https://github.com/bevyengine/bevy/blob/cd19d2757bd1effa78b7798d210072b55b61b847/crates/bevy_ecs/src/world/mod.rs#L1691-L1696

Contributor guide

Open the contributing guide

Research direction

Start in crates/bevy_ecs/src/world/mod.rs around the linked DropTestHelper implementation and reproduce the minimal test case that drops a non-panicking component. Confirm that DropTestHelper can finish successfully without requiring a component created with the true panic parameter, then verify the existing drop-order and panic tests still behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.