-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
DropTestHelper cannot be used when not testing for at least one panic #5615
Copy link
Copy link
Open
Labels
C-TestingA change that impacts how we test Bevy or how users test their appsA change that impacts how we test Bevy or how users test their apps
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:
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:
#[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 DropTestHelpers expected_panic_flag needs to be defused by dropping a drop_test_helper.make_component(true, _) (note the true parameter):
bevy/crates/bevy_ecs/src/world/mod.rs
Lines 1691 to 1696 in cd19d27
| if !expected_panic_flag { | |
| match panic_res { | |
| Ok(()) => panic!("Expected a panic but it didn't happen"), | |
| Err(e) => panic::resume_unwind(e), | |
| } | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-TestingA change that impacts how we test Bevy or how users test their appsA change that impacts how we test Bevy or how users test their apps