Skip to content

Commit e92a8e9

Browse files
committed
feat: add tests
1 parent 981b703 commit e92a8e9

File tree

1 file changed

+60
-0
lines changed
  • crates/bevy_ecs/src/system/commands

1 file changed

+60
-0
lines changed

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,4 +1444,64 @@ mod tests {
14441444
assert!(world.contains_resource::<W<i32>>());
14451445
assert!(world.contains_resource::<W<f64>>());
14461446
}
1447+
1448+
mod non_send {
1449+
use super::*;
1450+
1451+
#[allow(dead_code)]
1452+
struct MyNonSend(*const ());
1453+
1454+
impl Default for MyNonSend {
1455+
fn default() -> Self {
1456+
MyNonSend(std::ptr::null())
1457+
}
1458+
}
1459+
1460+
#[test]
1461+
fn init() {
1462+
let mut world = World::default();
1463+
let mut queue = CommandQueue::default();
1464+
1465+
{
1466+
let mut commands = Commands::new(&mut queue, &world);
1467+
commands.init_non_send_resource::<MyNonSend>();
1468+
}
1469+
1470+
queue.apply(&mut world);
1471+
1472+
assert!(world.contains_non_send::<MyNonSend>());
1473+
}
1474+
1475+
#[test]
1476+
fn insert() {
1477+
let mut world = World::default();
1478+
let mut queue = CommandQueue::default();
1479+
1480+
{
1481+
let mut commands = Commands::new(&mut queue, &world);
1482+
commands.insert_non_send_resource(|| MyNonSend(std::ptr::from_ref(&())));
1483+
}
1484+
1485+
queue.apply(&mut world);
1486+
1487+
assert!(world.contains_non_send::<MyNonSend>());
1488+
}
1489+
1490+
#[test]
1491+
fn remove() {
1492+
let mut world = World::default();
1493+
let mut queue = CommandQueue::default();
1494+
1495+
world.init_non_send_resource::<MyNonSend>();
1496+
1497+
{
1498+
let mut commands = Commands::new(&mut queue, &world);
1499+
commands.remove_non_send_resource::<MyNonSend>();
1500+
}
1501+
1502+
queue.apply(&mut world);
1503+
1504+
assert!(!world.contains_non_send::<MyNonSend>());
1505+
}
1506+
}
14471507
}

0 commit comments

Comments
 (0)