Skip to content

Commit

Permalink
Fix tests. lol.
Browse files Browse the repository at this point in the history
  • Loading branch information
spectria-limina committed Dec 5, 2024
1 parent cba70fb commit 3a77ef4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ env:
CARGO_TERM_COLOR: always

jobs:
build-test-x86:
build-test-x86_64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo"
- name: Build
run: cargo build --verbose
run: cargo build --all --verbose
- name: Test
run: cargo test --verbose
run: cargo test --all --verbose
build-test-wasm:
runs-on: ubuntu-latest
env:
Expand All @@ -33,9 +33,9 @@ jobs:
- name: Install Target
run: rustup target add wasm32-unknown-unknown
- name: Build
run: cargo build --verbose --target wasm32-unknown-unknown
run: cargo build --all --verbose --target wasm32-unknown-unknown
- name: Test
run: cargo test --verbose --target wasm32-unknown-unknown
run: cargo test --all --verbose --target wasm32-unknown-unknown
build-release-wasm:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ serde_json.workspace = true
tataru.workspace = true
thiserror = "2.0.3"
tracing.workspace = true
uuid = "1.11.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
convert_case = "0.6.0"
Expand Down
17 changes: 12 additions & 5 deletions src/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,13 @@ mod test {
use crate::widget::egui_context;
use crate::{testing::*, widget};

use avian2d::PhysicsPlugins;
use bevy::app::ScheduleRunnerPlugin;
use bevy::input::mouse::MouseButtonInput;
use bevy::picking::pointer::PointerInput;
use bevy::render::settings::{RenderCreation, WgpuSettings};
use bevy::render::RenderPlugin;
use bevy::window::PrimaryWindow;
use bevy::window::{PrimaryWindow, WindowEvent};
use bevy::winit::WinitPlugin;
use bevy_egui::EguiPlugin;
use bevy_egui::{egui, EguiContexts};
Expand Down Expand Up @@ -258,7 +261,7 @@ mod test {
.observe(Spawner::<Waymark>::start_drag);
commands.spawn(DragSurfaceBundle::new(Rect::from_center_half_size(
Vec2::ZERO,
Vec2::splat(100.0),
Vec2::splat(200.0),
)));
}

Expand All @@ -280,6 +283,8 @@ mod test {
.add_plugins(ScheduleRunnerPlugin {
run_mode: bevy::app::RunMode::Loop { wait: None },
})
.add_plugins(PhysicsPlugins::default())
.add_systems(PreUpdate, forward_window_events)
.add_plugins(EguiPlugin)
.add_plugins(crate::cursor::plugin())
.add_plugins(SpawnerPlugin::<Waymark>::default())
Expand All @@ -301,7 +306,6 @@ mod test {
}

#[test]
#[ignore = "broken since 0.15 for some reason: the drag ain't draggin'"]
fn spawner_drag() {
let (mut app, _) = test_app();

Expand All @@ -314,12 +318,15 @@ mod test {
button: MouseButton::Left,
duration: 10.0,
});
app.add_systems(Update, MockDrag::update)
app.add_systems(First, MockDrag::update)
.add_observer(observe_debug::<Pointer<DragStart>>)
.add_observer(observe_debug::<Pointer<Drag>>)
.add_observer(observe_debug::<Pointer<DragEnd>>)
.add_systems(Update, log_debug::<WindowEvent>)
.add_systems(Update, log_debug::<CursorMoved>)
.add_systems(Update, log_debug::<bevy::input::mouse::MouseButtonInput>)
.add_systems(Update, log_debug::<MouseButtonInput>)
.add_systems(Update, log_debug::<PointerHits>)
.add_systems(Update, log_debug::<PointerInput>)
.add_systems(First, || {
debug!("new tick");
});
Expand Down
39 changes: 28 additions & 11 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy::{
ecs::query::QuerySingleError,
input::{mouse::MouseButtonInput, ButtonState},
prelude::*,
window::PrimaryWindow,
window::{PrimaryWindow, WindowEvent},
};
use itertools::Itertools;

Expand Down Expand Up @@ -81,8 +81,7 @@ impl MockDrag {
mut q: Query<(Entity, &MockDrag, Option<&mut MockDragState>)>,
win_q: Query<Entity, With<PrimaryWindow>>,
mut commands: Commands,
mut cursor_ev: EventWriter<CursorMoved>,
mut button_ev: EventWriter<MouseButtonInput>,
mut window_ev: EventWriter<WindowEvent>,
) {
let win = win_q.single();
match q.get_single_mut() {
Expand All @@ -93,40 +92,40 @@ impl MockDrag {
pos: drag.start_pos,
..default()
});
cursor_ev.send(CursorMoved {
window_ev.send(WindowEvent::CursorMoved(CursorMoved {
window: win,
position: drag.start_pos,
delta: None,
});
}));
debug!("beginning mock drag at {}", drag.start_pos);
}
Ok((id, drag, Some(ref mut state))) => {
if state.tick == 0.0 {
button_ev.send(MouseButtonInput {
window_ev.send(WindowEvent::MouseButtonInput(MouseButtonInput {
window: win,
button: drag.button,
state: ButtonState::Pressed,
});
}));
state.tick += 1.0;
return;
}
if state.tick / drag.duration >= 1.0 + 0.0001 {
button_ev.send(MouseButtonInput {
window_ev.send(WindowEvent::MouseButtonInput(MouseButtonInput {
window: win,
button: drag.button,
state: ButtonState::Released,
});
}));
debug!("ending mock drag");
commands.entity(id).despawn();
return;
}
let progress = f32::min(state.tick / drag.duration, 1.0);
let pos = drag.start_pos.lerp(drag.end_pos, progress);
cursor_ev.send(CursorMoved {
window_ev.send(WindowEvent::CursorMoved(CursorMoved {
window: win,
position: pos,
delta: Some(pos - state.pos),
});
}));
state.tick += 1.0;
state.pos = pos;
debug!("continuing mock drag to {}", pos);
Expand All @@ -139,6 +138,24 @@ impl MockDrag {
}
}

pub fn forward_window_events(
mut reader: EventReader<WindowEvent>,
mut cursor_moved: EventWriter<CursorMoved>,
mut mouse_button_input: EventWriter<MouseButtonInput>,
) {
for ev in reader.read() {
match ev {
WindowEvent::CursorMoved(ev) => {
cursor_moved.send(ev.clone());
}
WindowEvent::MouseButtonInput(ev) => {
mouse_button_input.send(*ev);
}
_ => {}
}
}
}

#[track_caller]
pub fn debug_entities(world: &World) {
for e in world.iter_entities() {
Expand Down

0 comments on commit 3a77ef4

Please sign in to comment.