Skip to content

Commit aaa9d9a

Browse files
committed
fix some test setup, add debug to dev crate features
1 parent 357c2fe commit aaa9d9a

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ bevy = { workspace = true, features = [
251251
"bevy_ui",
252252
"default_font",
253253
"custom_cursor",
254+
"debug",
254255
] }
255256
bevy_platform = { workspace = true }
256257
clap = { workspace = true, features = ["derive"] }

crates/testing_crates/test_utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ bevy_log = { workspace = true, default-features = false, features = [] }
1212
bevy_diagnostic = { workspace = true, default-features = false, features = [] }
1313
bevy_reflect = { workspace = true, default-features = false, features = [] }
1414
bevy_time = { workspace = true, default-features = false, features = [] }
15+
bevy_utils = { workspace = true, default-features = false, features = [
16+
"debug",
17+
] }
1518

1619

1720
[lib]

crates/testing_crates/test_utils/src/test_data.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl SimpleEnum {
267267
}
268268

269269
pub(crate) const TEST_COMPONENT_ID_START: usize = 20;
270-
pub(crate) const TEST_ENTITY_ID_START: u32 = 0;
270+
pub(crate) const TEST_ENTITY_ID_START: u32 = 1;
271271

272272
pub trait GetTestComponentId {
273273
fn test_component_id() -> ComponentId;
@@ -306,6 +306,10 @@ macro_rules! impl_test_component_ids {
306306

307307
pub(crate) fn init_all_components(world: &mut World, registry: &mut TypeRegistry) {
308308
$(
309+
// world
310+
// .components()
311+
// .iter_registered()
312+
// .for_each(|c| println!("--> {:?}", c));
309313
world.register_component::<$comp_type>();
310314
registry.register::<$comp_type>();
311315
let registered_id = world.component_id::<$comp_type>().unwrap().index();
@@ -338,8 +342,8 @@ macro_rules! impl_test_component_ids {
338342
};
339343
}
340344

341-
impl_test_component_ids!(
342-
[ TestComponent => 0,
345+
impl_test_component_ids!([
346+
TestComponent => 0,
343347
CompWithFromWorld => 1,
344348
CompWithDefault => 2,
345349
CompWithDefaultAndComponentData => 3,
@@ -362,6 +366,21 @@ fn init_world<F: FnOnce(&mut World, &mut TypeRegistry)>(world: &mut World, init:
362366
let type_registry = world.get_resource_or_init::<AppTypeRegistry>().clone();
363367
let mut type_registry_guard = type_registry.0.write();
364368

369+
// bevy now spawns an ineternal component `bevy_ecs::event::EventWrapperComponent<bevy_ecs::archetype::ArchetypeCreated>`
370+
// when an entity with a component is inserted :shrug:, make that happen early
371+
#[derive(Component)]
372+
pub struct Dummy;
373+
world.register_component::<Dummy>();
374+
world.spawn((Dummy,));
375+
376+
if world.components().len() > TEST_COMPONENT_ID_START {
377+
panic!("world has more components than the first test component ID requires")
378+
}
379+
380+
if world.entities().len() > TEST_ENTITY_ID_START {
381+
panic!("world has more entities than the first test component ID requires")
382+
}
383+
365384
while world.components().len() < TEST_COMPONENT_ID_START {
366385
unsafe {
367386
world.register_component_with_descriptor(ComponentDescriptor::new_with_layout(

0 commit comments

Comments
 (0)