use crate::accessibility::{AccessNode, Role};
use crate::event::{Button, Event, Mods, parse_keys};
use crate::geom::{Point, Rect, Size, pt, rect};
use crate::id::Id;
use crate::platform::LocalClipboard;
use crate::surface::Surface;
use crate::text::BuiltInFont;
use crate::ui::Ui;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
const STEP: Duration = Duration::from_millis(16);
const DOUBLE_CLICK: Duration = Duration::from_millis(500);
const DRAG_MOVES: usize = 8;
type Describes<A> = Box<dyn FnMut(&mut A, &mut Ui)>;
type Tells<A> = Box<dyn FnMut(&mut A, Duration)>;
static FAILED: AtomicUsize = AtomicUsize::new(0);
pub struct Trial<A> {
pub app: A,
pub ui: Ui,
pub screen: Surface,
pub passes: usize,
describe: Describes<A>,
clock: Option<Tells<A>>,
now: Duration,
pointer: Point,
pressed: Option<(Duration, Point)>,
}
impl<A> std::fmt::Debug for Trial<A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Trial").field("ui", &self.ui).field("screen", &self.screen).field("passes", &self.passes).field("now", &self.now).finish_non_exhaustive()
}
}
impl<A> Trial<A> {
pub fn new(app: A, describe: impl FnMut(&mut A, &mut Ui) + 'static) -> Self {
let mut ui = Ui::new(Box::new(BuiltInFont), Box::new(LocalClipboard::default()));
ui.set_screen_reader(true);
ui.resize(Size { w: 640.0, h: 480.0 }, 1.0);
let screen = Surface::draw(&mut ui, 64);
let mut trial = Trial { app, ui, screen, passes: 0, describe: Box::new(describe), clock: None, now: Duration::ZERO, pointer: pt(-1.0, -1.0), pressed: None };
trial.run();
trial
}
pub fn set_time(&mut self, to: impl FnMut(&mut A, Duration) + 'static) {
self.clock = Some(Box::new(to));
self.run();
}
pub fn resize(&mut self, width: f32, height: f32, scale: f32) {
self.ui.resize(Size { w: width, h: height }, scale);
self.run();
}
pub fn run(&mut self) -> Rect {
if let Some(clock) = &mut self.clock {
clock(&mut self.app, self.now);
}
let (app, describe, passes) = (&mut self.app, &mut self.describe, &mut self.passes);
*passes = 0;
let changed = self.ui.run(&mut |ui| {
*passes += 1;
describe(app, ui);
});
self.screen.redraw(&mut self.ui, changed);
let afresh = Surface::draw(&mut self.ui, 64);
if afresh.pixels != self.screen.pixels {
let [left, top, right, bottom] = differs(self.screen.width, &self.screen.pixels, &afresh.pixels);
let what = format!("drawing only what changed ({changed:?}) left the window different from drawing all of it, in pixels {left}..{right} across and {top}..{bottom} down");
self.fail(&what, ["stale-shown", "stale-afresh"], &afresh);
}
let again = self.ui.run(&mut |ui| describe(app, ui));
if !again.is_empty() {
let what = format!(
"the window changed in {again:?} when it was run again with nothing new: what the app keeps was changed after the part that shows it was described, so a window would show it as it was until something else happens. Say `ui.rerun()` where it changes. (The app was described {} times in that run; a run describes it eight times at most.)",
self.passes
);
let after = Surface::draw(&mut self.ui, 64);
self.fail(&what, ["unsettled-shown", "unsettled-after"], &after);
}
changed
}
fn fail(&self, what: &str, names: [&str; 2], other: &Surface) -> ! {
let (folder, number) = (std::env::temp_dir().join("taut-trial"), FAILED.fetch_add(1, Ordering::Relaxed));
let [shown, should] = names.map(|name| folder.join(format!("{}-{number}-{name}.png", std::process::id())));
let saved = std::fs::create_dir_all(&folder).and(std::fs::write(&shown, self.screen.to_png())).and(std::fs::write(&should, other.to_png()));
let pictures = saved.map_or_else(|why| format!("(the pictures could not be saved: {why})"), |_| format!("as shown: {}, as it should be: {}", shown.display(), should.display()));
panic!("{what}; {pictures}");
}
pub fn wait(&mut self, time: Duration) {
let end = self.now + time;
while let Some(due) = self.ui.wake_in().map(|wait| self.now + wait.max(Duration::from_millis(1))).filter(|due| *due <= end) {
self.now = due;
self.ui.set_time(due);
self.run();
}
self.now = end;
self.ui.set_time(end);
}
pub fn event(&mut self, event: Event) {
self.wait(STEP);
if self.ui.event(event) {
self.run();
}
}
pub fn move_to(&mut self, at: Point) {
self.pointer = at;
self.event(Event::Move(at));
}
pub fn click(&mut self, at: Point) {
self.click_with(at, Button::Left, Mods::NONE);
}
pub fn right_click(&mut self, at: Point) {
self.click_with(at, Button::Right, Mods::NONE);
}
pub fn click_with(&mut self, at: Point, button: Button, mods: Mods) {
let press = self.now + STEP * 2;
let soon = self.pressed.filter(|(when, last)| press < *when + DOUBLE_CLICK && (at.x - last.x).abs() < 4.0 && (at.y - last.y).abs() < 4.0);
if let Some((when, _)) = soon.filter(|_| button == Button::Left) {
self.wait(when + DOUBLE_CLICK - press);
}
self.move_to(at);
self.press_and_let_go(button, mods);
}
pub fn double_click(&mut self, at: Point) {
self.click(at);
self.press_and_let_go(Button::Left, Mods::NONE);
}
fn press_and_let_go(&mut self, button: Button, mods: Mods) {
self.pressed = (button == Button::Left).then_some((self.now + STEP, self.pointer)).or(self.pressed);
self.event(Event::Press(button, mods));
self.event(Event::Release(button));
}
pub fn drag(&mut self, from: Point, to: Point) {
self.move_to(from);
self.pressed = Some((self.now + STEP, from));
self.event(Event::Press(Button::Left, Mods::NONE));
for step in 1..=DRAG_MOVES {
let along = step as f32 / DRAG_MOVES as f32;
self.move_to(pt(from.x + (to.x - from.x) * along, from.y + (to.y - from.y) * along));
}
self.event(Event::Release(Button::Left));
}
pub fn wheel(&mut self, at: Point, across: f32, down: f32) {
self.move_to(at);
self.event(Event::Wheel(across, down));
}
pub fn drop_files(&mut self, at: Point, files: &[PathBuf]) {
self.event(Event::FilesHovered(true));
self.move_to(at);
self.event(Event::FilesDropped(files.to_vec()));
}
pub fn type_text(&mut self, text: &str) {
self.event(Event::Text(text.into()));
}
pub fn key(&mut self, written: &str) {
let Some((key, mods)) = parse_keys(written) else { panic!("{written:?} names no key") };
self.event(Event::Key(key, mods));
}
pub fn visible_access_nodes(&self) -> &[AccessNode] {
self.ui.visible_access_nodes()
}
pub fn access_nodes(&self) -> &[AccessNode] {
self.ui.access_nodes()
}
pub fn find(&self, role: Role, name: &str) -> &AccessNode {
&self.visible_access_nodes()[self.place_of(role, name)]
}
fn place_of(&self, role: Role, name: &str) -> usize {
let found = self.visible_access_nodes().iter().position(|node| node.role == role && node.name == name);
found.unwrap_or_else(|| panic!("nothing in the window is a {role:?} called {name:?}; what there is:\n{}", self.dump()))
}
pub fn has(&self, role: Role, name: &str) -> bool {
self.visible_access_nodes().iter().any(|node| node.role == role && node.name == name)
}
pub fn dump(&self) -> String {
let line = |node: &AccessNode| {
let value = if node.value.is_empty() { String::new() } else { format!(" = {:?}", node.value) };
let on = node.on.map_or("", |on| if on { " (on)" } else { " (off)" });
format!(" {:?} {:?}{value}{on}", node.role, node.name)
};
self.visible_access_nodes().iter().map(line).collect::<Vec<_>>().join("\n")
}
pub fn center_of(&self, role: Role, name: &str) -> Point {
let node = &self.visible_access_nodes()[self.place_of(role, name)];
let seen = node.seen.intersect(rect(0.0, 0.0, self.ui.size().w, self.ui.size().h));
if seen.is_empty() {
panic!("the {role:?} called {name:?} is not in view: it lies at {:?}", node.rect);
}
let middle = pt(seen.x + seen.w / 2.0, seen.y + seen.h / 2.0);
if self.over(node.at, middle).is_none() {
return middle;
}
let steps = [seen.w, seen.h].map(|side| (side as usize).clamp(1, 32));
let mut places: Vec<Point> =
(0..=steps[0]).flat_map(|x| (0..=steps[1]).map(move |y| (x, y))).map(|(x, y)| pt(seen.x + seen.w * x as f32 / steps[0] as f32, seen.y + seen.h * y as f32 / steps[1] as f32)).collect();
places.retain(|place| seen.contains(*place));
let far = |place: &Point| (place.x - middle.x).powi(2) + (place.y - middle.y).powi(2);
let free = places.iter().filter(|place| self.over(node.at, **place).is_none()).min_by(|a, b| far(a).total_cmp(&far(b)));
free.copied().unwrap_or_else(|| {
panic!("the {role:?} called {name:?} is covered where it shows, in {seen:?}: {} lies over it", self.over(node.at, middle).map_or(String::new(), |cover| self.named(cover)))
})
}
fn over(&self, of: u32, at: Point) -> Option<Id> {
let (tree, top) = (&self.ui.tree, self.ui.visible_boxes.hits.iter().rev().find(|(_, seen)| seen.contains(at))?.0);
let mine = |box_at: usize| box_at >= of as usize && box_at < tree.specs[of as usize].end as usize || box_at < of as usize && tree.specs[box_at].end > of;
let found = tree.specs.iter().position(|spec| spec.id == top);
found.is_none_or(|box_at| !mine(box_at)).then_some(top)
}
fn named(&self, id: Id) -> String {
let (tree, nodes) = (&self.ui.tree, self.access_nodes());
let Some(at) = tree.specs.iter().position(|spec| spec.id == id) else {
let bar = tree.specs.iter().find(|spec| [0, 1].iter().any(|axis| crate::paint::bar_id(spec.id, *axis) == id));
return bar.map_or(format!("a box that takes the pointer (id {id:x})"), |spec| format!("the scroll bar of the box {:x}", spec.id));
};
let around = nodes.iter().rev().find(|thing| thing.at as usize <= at && tree.specs[thing.at as usize].end as usize > at);
around.map_or(format!("a box that takes the pointer (id {id:x})"), |thing| format!("the {:?} called {:?}", thing.role, thing.name))
}
pub fn press(&mut self, role: Role, name: &str) {
let at = self.center_of(role, name);
self.click(at);
}
pub fn fill(&mut self, name: &str, text: &str) {
self.press(Role::TextBox, name);
self.key("Ctrl+A");
self.type_text(text);
}
pub fn save_png(&self, file: impl AsRef<Path>) {
let file = file.as_ref();
if let Some(folder) = file.parent() {
std::fs::create_dir_all(folder).unwrap_or_else(|why| panic!("{} could not be made: {why}", folder.display()));
}
std::fs::write(file, self.screen.to_png()).unwrap_or_else(|why| panic!("{} could not be written: {why}", file.display()));
}
pub fn looks_like(&self, file: impl AsRef<Path>) {
let file = file.as_ref();
let differing = file.with_extension("differs.png");
let Some((width, saved)) = std::fs::read(file).ok().and_then(|bytes| crate::png::decode(&bytes)) else {
return self.save_png(file);
};
let (_, now) = crate::png::decode(&self.screen.to_png()).expect("a picture of the library's own reads back");
if (width, saved.len()) == (self.screen.width, now.len()) && saved == now {
_ = std::fs::remove_file(&differing);
return;
}
self.save_png(&differing);
let size = |width: usize, pixels: &[u32]| format!("{width} by {}", pixels.len() / width.max(1));
if width != self.screen.width || saved.len() != now.len() {
panic!("the window is {}, the picture in {} {}; this one is in {}", size(self.screen.width, &now), file.display(), size(width, &saved), differing.display());
}
let count = saved.iter().zip(&now).filter(|(a, b)| a != b).count();
let [left, top, right, bottom] = differs(width, &saved, &now);
panic!("{count} pixels differ from {}, in {left}..{right} across and {top}..{bottom} down; this picture is in {}", file.display(), differing.display());
}
}
fn differs(width: usize, one: &[u32], other: &[u32]) -> [usize; 4] {
let places = one.iter().zip(other).enumerate().filter(|(_, (a, b))| a != b).map(|(at, _)| (at % width.max(1), at / width.max(1)));
places.fold([usize::MAX, usize::MAX, 0, 0], |[left, top, right, bottom], (x, y)| [left.min(x), top.min(y), right.max(x + 1), bottom.max(y + 1)])
}
#[cfg(test)]
mod tests {
use super::*;
use crate::geom::pt;
use crate::layout::Length;
use std::panic::{AssertUnwindSafe, catch_unwind};
#[derive(Default)]
struct Probe {
presses: u32,
doubles: u32,
forgotten: bool,
name: String,
wide: f32,
on: bool,
slid: f32,
rows: Vec<usize>,
careless: bool,
counted: u32,
}
fn probe(app: &mut Probe, ui: &mut Ui) {
let t = ui.theme;
ui.column().grow().pad(10.0).gap(8.0).open();
ui.row().gap(8.0).open();
let press = ui.button("Press");
(app.presses, app.doubles) = (app.presses + press.clicked as u32, app.doubles + press.double_clicked as u32);
ui.tooltip(&press, "Presses once");
if ui.context_menu(&press) {
app.forgotten |= ui.menu_item("Forget").clicked;
ui.close();
}
ui.switch(&mut app.on, "Slide");
app.slid = ui.animate(ui.id("slid"), if app.on { 200.0 } else { 0.0 }, Duration::from_millis(200));
ui.label(&format!("counted {}", app.counted));
ui.close();
ui.text_box(&mut app.name, "Name");
ui.row().h(Length::Px(20.0)).open();
ui.el().w(Length::Px(app.wide.max(40.0))).fill(t.accent).show();
ui.splitter(&mut app.wide, 40.0, 300.0);
ui.close();
app.rows = ui.list(1000, 20.0).collect();
for row in app.rows.clone() {
ui.label(&format!("row {row}"));
}
ui.close();
ui.close();
if ui.keys("Ctrl+K") {
ui.notice("Kept");
}
if app.careless && ui.pointer().is_some() {
app.counted += 1;
}
}
#[test]
fn things_are_found_by_what_a_screen_reader_is_told_and_pressed() {
let mut trial = Trial::new(Probe::default(), probe);
trial.press(Role::Button, "Press");
trial.press(Role::Button, "Press");
assert_eq!((trial.app.presses, trial.app.doubles), (2, 0), "two clicks in a row are two clicks");
let at = trial.center_of(Role::Button, "Press");
trial.double_click(at);
assert_eq!((trial.app.presses, trial.app.doubles), (4, 1));
trial.right_click(at);
trial.press(Role::MenuItem, "Forget");
assert!(trial.app.forgotten);
trial.press(Role::Switch, "Slide");
assert_eq!(trial.find(Role::Switch, "Slide").on, Some(true));
let missing = catch_unwind(AssertUnwindSafe(|| trial.press(Role::Button, "Nothing"))).unwrap_err();
let said = missing.downcast_ref::<String>().unwrap();
assert!(said.contains("a Button called \"Nothing\"") && said.contains(" Switch \"Slide\" (on)"), "{said}");
}
#[test]
fn time_passes_for_tool_tips_notices_and_glides() {
let mut trial = Trial::new(Probe::default(), probe);
let at = trial.center_of(Role::Button, "Press");
trial.move_to(at);
assert!(!trial.has(Role::Text, "Presses once"));
trial.wait(Duration::from_millis(600));
assert!(trial.has(Role::Text, "Presses once"), "the tool tip came once the pointer rested");
trial.key("Ctrl+K");
assert!(trial.has(Role::Text, "Kept"));
trial.wait(Duration::from_secs(5));
assert!(!trial.has(Role::Text, "Kept"), "and went by itself");
trial.press(Role::Switch, "Slide");
trial.wait(Duration::from_millis(60));
assert!(trial.app.slid > 0.0 && trial.app.slid < 200.0, "on its way: {}", trial.app.slid);
trial.wait(Duration::from_millis(300));
assert_eq!(trial.app.slid, 200.0);
}
#[test]
fn text_is_typed_keys_pressed_bars_dragged_and_lists_scrolled() {
let mut trial = Trial::new(Probe { wide: 40.0, ..Default::default() }, probe);
trial.fill("Name", "Ada");
trial.key("Home");
trial.type_text("X");
assert_eq!(trial.app.name, "XAda");
trial.fill("Name", "Grace");
assert_eq!(trial.find(Role::TextBox, "Name").value, "Grace", "filled anew");
let bar = 10.0 + 40.0 + 2.0;
let y = trial.find(Role::TextBox, "Name").rect.bottom() + 8.0 + 10.0;
trial.drag(pt(bar, y), pt(bar + 100.0, y));
assert_eq!(trial.app.wide, 140.0);
assert_eq!(trial.app.rows.first(), Some(&0));
trial.wheel(pt(300.0, 300.0), 0.0, 200.0);
assert_eq!(trial.app.rows.first(), Some(&10), "scrolled ten rows on");
assert!(!trial.has(Role::Text, "row 0") && trial.has(Role::Text, "row 10"));
assert_eq!((trial.find(Role::Text, "row 10").position, trial.find(Role::Text, "row 12").position), (Some([11, 1000]), Some([13, 1000])));
}
#[test]
fn the_window_is_any_size_at_any_scale() {
let mut trial = Trial::new(Probe::default(), probe);
assert_eq!((trial.screen.width, trial.screen.height), (640, 480));
trial.resize(300.0, 200.0, 2.0);
assert_eq!((trial.screen.width, trial.screen.height), (600, 400));
trial.press(Role::Button, "Press");
assert_eq!(trial.app.presses, 1, "places are in units, at any scale");
}
#[test]
fn pictures_are_saved_then_held_against_and_what_differs_is_saved() {
let folder = std::env::temp_dir().join(format!("taut-trial-pictures-{}", std::process::id()));
_ = std::fs::remove_dir_all(&folder);
let (file, differing) = (folder.join("probe.png"), folder.join("probe.differs.png"));
let mut trial = Trial::new(Probe::default(), probe);
trial.looks_like(&file);
assert!(file.is_file(), "saved the first time");
trial.looks_like(&file);
trial.press(Role::Switch, "Slide");
trial.wait(Duration::from_secs(1));
let failed = catch_unwind(AssertUnwindSafe(|| trial.looks_like(&file))).unwrap_err();
let said = failed.downcast_ref::<String>().unwrap();
assert!(said.contains("pixels differ") && differing.is_file(), "{said}");
std::fs::rename(&differing, &file).unwrap();
trial.looks_like(&file);
assert!(!differing.exists());
trial.resize(320.0, 240.0, 1.0);
let failed = catch_unwind(AssertUnwindSafe(|| trial.looks_like(&file))).unwrap_err();
assert!(failed.downcast_ref::<String>().unwrap().contains("the window is 320 by 240"));
_ = std::fs::remove_dir_all(&folder);
}
#[derive(Default)]
struct Groups {
pressed: Vec<String>,
notice: bool,
notice_over_all: bool,
}
fn groups(app: &mut Groups, ui: &mut Ui) {
use crate::layout::{Align, Flow};
let t = ui.theme;
ui.el().flow(Flow::Stack).grow().open();
ui.column().grow().pad(10.0).open();
ui.column().w(Length::Px(300.0)).h(Length::Px(200.0)).scroll().open();
for group in 1..=3 {
ui.column().open();
ui.row().h(Length::Px(30.0)).pad(4.0).fill(t.panel).sticky().open();
ui.label(&format!("Group {group}"));
ui.close();
for row in 1..=8 {
let name = format!("Row {group}.{row}");
if ui.button(&name).clicked {
app.pressed.push(name);
}
}
ui.close();
}
ui.close();
ui.close();
if app.notice {
let (at, wide) = if app.notice_over_all { (0.0, 400.0) } else { (150.0, 200.0) };
let notice = ui.column().place((Align::Start, Align::Start)).offset(at, 10.0).w(Length::Px(wide)).h(Length::Px(250.0)).fill(t.raised).sense().open();
ui.tell(¬ice, Role::Group, None, "Notice");
ui.label("Saved");
ui.close();
}
ui.close();
}
#[test]
fn a_heading_that_sticks_stays_at_the_top_until_the_next_one_comes() {
let mut trial = Trial::new(Groups::default(), groups);
let top = |trial: &Trial<Groups>, name: &str| trial.access_nodes().iter().find(|said| said.name == name).map(|said| said.rect.y).unwrap();
let (label, first, row) = (top(&trial, "Group 1"), top(&trial, "Row 1.1"), top(&trial, "Row 1.2") - top(&trial, "Row 1.1"));
assert_eq!(first, 10.0 + 30.0);
trial.wheel(pt(100.0, 100.0), 0.0, 40.0);
assert_eq!((top(&trial, "Group 1"), top(&trial, "Row 1.1")), (label, first - 40.0));
assert!(!trial.has(Role::Button, "Row 1.1") && trial.access_nodes().iter().any(|said| said.name == "Row 1.1" && !said.visible));
trial.press(Role::Button, "Row 1.2");
assert_eq!(trial.app.pressed, ["Row 1.2"]);
let group = 30.0 + 8.0 * row;
trial.wheel(pt(100.0, 100.0), 0.0, group - 40.0 - 10.0);
assert_eq!((top(&trial, "Group 1"), top(&trial, "Group 2")), (label - 20.0, label + 10.0));
trial.wheel(pt(100.0, 100.0), 0.0, 20.0);
assert_eq!((top(&trial, "Group 2"), trial.has(Role::Text, "Group 1")), (label, false));
trial.press(Role::Button, "Row 2.3");
trial.key("Up");
trial.key("Up");
let focused = trial.visible_access_nodes().iter().find(|said| said.focused).map(|said| (said.name.clone(), said.rect.y)).unwrap();
assert_eq!(focused, ("Row 2.1".to_string(), first));
}
#[test]
fn what_is_out_of_view_is_told_and_a_screen_reader_brings_it_into_view() {
let mut trial = Trial::new(Groups::default(), groups);
let told = |trial: &Trial<Groups>, name: &str| trial.access_nodes().iter().find(|said| said.name == name).map(|said| (said.visible, said.id)).unwrap();
assert_eq!((told(&trial, "Row 1.1").0, told(&trial, "Row 3.8").0, trial.access_nodes().len() > trial.visible_access_nodes().len()), (true, false, true));
assert!(!trial.has(Role::Button, "Row 3.8"));
trial.ui.show_for_reader(told(&trial, "Row 3.8").1);
trial.run();
assert!(told(&trial, "Row 3.8").0 && trial.has(Role::Button, "Row 3.8") && !trial.has(Role::Button, "Row 1.1"));
}
#[test]
fn a_press_goes_where_nothing_lies_over_the_thing() {
let mut trial = Trial::new(Groups { notice: true, ..Default::default() }, groups);
let row = trial.find(Role::Button, "Row 1.3").rect;
assert!(row.x + row.w / 2.0 > 150.0 && trial.center_of(Role::Button, "Row 1.3").x < 150.0);
trial.press(Role::Button, "Row 1.3");
assert_eq!(trial.app.pressed, ["Row 1.3"]);
trial.app.notice_over_all = true;
trial.run();
let failed = catch_unwind(AssertUnwindSafe(|| trial.press(Role::Button, "Row 1.3"))).unwrap_err();
let said = failed.downcast_ref::<String>().unwrap();
assert!(said.contains("covered") && said.contains("the Group called \"Notice\""), "{said}");
}
#[test]
#[should_panic(expected = "drawing only what changed")]
fn a_picture_left_stale_fails_the_step() {
let mut trial = Trial::new(Probe::default(), probe);
trial.screen.pixels[641 * 5] ^= 0x00ff_ffff; trial.press(Role::Button, "Press");
}
#[test]
#[should_panic(expected = "run again with nothing new")]
fn a_change_after_the_part_that_shows_it_fails_the_step() {
let mut trial = Trial::new(Probe { careless: true, ..Default::default() }, probe);
trial.press(Role::Button, "Press");
}
#[test]
#[should_panic(expected = "\"Ctrl+Hyper\" names no key")]
fn words_that_name_no_key_fail() {
Trial::new(Probe::default(), probe).key("Ctrl+Hyper");
}
#[test]
fn time_is_told_to_an_app_that_asks() {
fn clock(app: &mut Probe, now: Duration) {
app.counted = now.as_millis() as u32;
}
let mut trial = Trial::new(Probe::default(), probe);
trial.set_time(clock);
trial.wait(Duration::from_secs(2));
trial.run();
assert!(trial.has(Role::Text, "counted 2000"), "{}", trial.dump());
}
}