1use std::cell::RefCell;
11use std::future::Future;
12use std::pin::Pin;
13use std::rc::Rc;
14use std::task::{Context, Poll};
15
16use day_core::conformance::{
17 Case, Drive, DriveBackend, DriveOp, Fail, NativeExpect, OpFuture, TestKind,
18};
19use serde::{Deserialize, Serialize};
20
21use crate::{Reply, Step, b64encode, next_capture_revision};
22
23pub use day_script_protocol::ShotPolicy;
24
25#[derive(Clone, Debug, Serialize, Deserialize)]
27pub struct Outcome {
28 pub name: String,
29 pub kind: String,
30 pub verdict: String,
32 #[serde(default, skip_serializing_if = "Option::is_none")]
33 pub message: Option<String>,
34 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub reason: Option<String>,
36 pub ms: u64,
37 pub proves: Vec<String>,
38 #[serde(default)]
40 pub shots: Vec<String>,
41 #[serde(default, skip_serializing_if = "Vec::is_empty")]
44 pub native_unread: Vec<String>,
45}
46
47#[derive(Clone, Debug, Serialize, Deserialize)]
49pub struct Shot {
50 pub test: String,
51 pub name: String,
52 pub png_base64: String,
53}
54
55#[derive(Clone, Debug, Default, Serialize, Deserialize)]
57pub struct RunReport {
58 pub tests: Vec<Outcome>,
59 #[serde(default)]
60 pub shots: Vec<Shot>,
61 #[serde(default)]
64 pub caps: std::collections::BTreeMap<String, String>,
65}
66
67struct Run {
68 report: RunReport,
69 done: bool,
70}
71
72thread_local! {
73 static RUN: RefCell<Option<Rc<RefCell<Run>>>> = const { RefCell::new(None) };
74}
75
76pub fn listing() -> Result<serde_json::Value, String> {
82 day_core::conformance::validate_registry()?;
83 let cases = day_core::conformance::cases();
84 Ok(serde_json::Value::Array(
85 cases
86 .iter()
87 .map(|c| {
88 serde_json::json!({
89 "name": c.name(),
90 "kind": kind_name(c.kind()),
91 "proves": c.proves_keys(),
92 "requires": c.requirements().iter().map(|r| format!("{r:?}")).collect::<Vec<_>>(),
93 })
94 })
95 .collect(),
96 ))
97}
98
99pub fn run_tests(
108 filter: &[String],
109 shots: ShotPolicy,
110 case_timeout_secs: Option<f64>,
111) -> Result<Reply, Reply> {
112 day_core::conformance::validate_registry().map_err(|e| Reply::fail(e, false))?;
113 let run = RUN.with(|r| r.borrow().clone());
114 match run {
115 None => {
116 start(filter.to_vec(), shots, case_timeout_secs);
117 Err(Reply::fail("tests running", true))
118 }
119 Some(run) => {
120 if !run.borrow().done {
121 return Err(Reply::fail("tests running", true));
122 }
123 RUN.with(|r| *r.borrow_mut() = None);
124 let report = std::mem::take(&mut run.borrow_mut().report);
125 let data = serde_json::to_value(&report)
126 .map_err(|e| Reply::fail(format!("test report: {e}"), false))?;
127 Ok(Reply {
128 data: Some(data),
129 ..Reply::ok()
130 })
131 }
132 }
133}
134
135fn kind_name(kind: TestKind) -> &'static str {
136 match kind {
137 TestKind::Gui => "gui",
138 TestKind::Headless => "headless",
139 }
140}
141
142fn matches(filter: &[String], name: &str) -> bool {
143 filter.is_empty() || filter.iter().any(|f| glob(f, name))
144}
145
146fn glob(pattern: &str, name: &str) -> bool {
148 let mut parts = pattern.split('*');
149 let Some(first) = parts.next() else {
150 return pattern == name;
151 };
152 if !pattern.contains('*') {
153 return pattern == name;
154 }
155 if !name.starts_with(first) {
156 return false;
157 }
158 let mut rest = &name[first.len()..];
159 let parts: Vec<&str> = parts.collect();
160 for (i, part) in parts.iter().enumerate() {
161 if part.is_empty() {
162 continue;
163 }
164 let last = i + 1 == parts.len() && !pattern.ends_with('*');
165 if last {
166 return rest.ends_with(part);
167 }
168 match rest.find(part) {
169 Some(at) => rest = &rest[at + part.len()..],
170 None => return false,
171 }
172 }
173 true
174}
175
176const DEFAULT_CASE_TIMEOUT_SECS: f64 = 30.0;
178
179fn start(filter: Vec<String>, policy: ShotPolicy, case_timeout_secs: Option<f64>) {
180 let run = Rc::new(RefCell::new(Run {
181 report: RunReport::default(),
182 done: false,
183 }));
184 run.borrow_mut().report.caps = day_spec::Cap::ALL
185 .iter()
186 .map(|cap| {
187 let answer = match day_core::capability(*cap) {
188 day_spec::Support::Native => "N",
189 day_spec::Support::Emulated => "E",
190 day_spec::Support::Unsupported => "-",
191 };
192 (format!("{cap:?}"), answer.to_owned())
193 })
194 .collect();
195 RUN.with(|r| *r.borrow_mut() = Some(run.clone()));
196 day_core::conformance::set_intercepting_urls(true);
198 day_core::task(async move {
199 let cases: Vec<Case> = day_core::conformance::cases()
200 .into_iter()
201 .filter(|c| matches(&filter, c.name()))
202 .collect();
203 let mut gui = false;
204 for (i, case) in cases.iter().enumerate() {
205 let mut shots = Vec::new();
206 let twin = cases
209 .iter()
210 .enumerate()
211 .any(|(j, c)| j != i && c.name() == case.name());
212 let outcome = if twin {
213 let mut o = outcome_for(case);
214 o.verdict = "fail".into();
215 o.message = Some(format!(
216 "two #[day::test] functions are named {}; rename one",
217 case.name()
218 ));
219 o
220 } else {
221 gui |= case.kind() == TestKind::Gui;
222 run_case(case, policy, case_timeout_secs, &mut shots).await
223 };
224 let mut run = run.borrow_mut();
225 run.report.shots.extend(shots);
226 run.report.tests.push(outcome);
227 }
228 if gui {
230 day_core::conformance::clear_active();
231 }
232 day_core::conformance::set_intercepting_urls(false);
233 run.borrow_mut().done = true;
234 });
235}
236
237fn outcome_for(case: &Case) -> Outcome {
238 Outcome {
239 name: case.name().to_owned(),
240 kind: kind_name(case.kind()).to_owned(),
241 verdict: "pass".into(),
242 message: None,
243 reason: None,
244 ms: 0,
245 proves: case.proves_keys().to_vec(),
246 shots: Vec::new(),
247 native_unread: Vec::new(),
248 }
249}
250
251async fn run_case(
252 case: &Case,
253 policy: ShotPolicy,
254 run_timeout_secs: Option<f64>,
255 shots: &mut Vec<Shot>,
256) -> Outcome {
257 let started = Stopwatch::start();
258 let mut outcome = outcome_for(case);
259 if let Some(cap) = case
262 .requirements()
263 .iter()
264 .find(|c| day_core::capability(**c) == day_spec::Support::Unsupported)
265 {
266 outcome.verdict = "skip".into();
267 outcome.reason = Some(format!("Cap::{cap:?} is Unsupported on this toolkit"));
268 return outcome;
269 }
270 if let Some(what) = case.missing_support() {
271 outcome.verdict = "skip".into();
272 outcome.reason = Some(format!("{what} is Unsupported on this toolkit"));
273 return outcome;
274 }
275 let backend = Rc::new(Engine {
276 shots: Rc::new(RefCell::new(Vec::new())),
277 unread: Rc::new(RefCell::new(Vec::new())),
278 });
279 let drive = Drive::new(backend.clone());
280 let limit = match run_timeout_secs {
283 Some(t) if t <= 0.0 => None,
284 run => Some(
285 case.timeout_secs()
286 .or(run)
287 .unwrap_or(DEFAULT_CASE_TIMEOUT_SECS),
288 ),
289 };
290 let body = {
291 let (case, drive) = (case.clone(), drive.clone());
292 async move {
293 if case.kind() == TestKind::Gui {
294 if !day_core::conformance::set_active(case.clone()) {
297 return Err(Fail(
298 "the app shows no test host: root its test build in \
299 `day::test_host(..)` (docs/testing.md)"
300 .into(),
301 ));
302 }
303 day_reactive::flush_sync();
304 drive.wait_idle().await?;
305 if let Some(message) = day_core::conformance::take_page_panic() {
306 return Err(Fail(format!("the page panicked: {message}")));
307 }
308 for name in case.shots() {
309 drive.shot(name).await?;
310 }
311 }
312 case.run_body(drive).await
313 }
314 };
315 let result = Guarded::new(Box::pin(body), limit).await;
316 let placeholders = day_spec::placeholder::seen();
319 if let Some(kind) = case.proves_keys().iter().find_map(|k| {
320 k.strip_prefix("kind:")
321 .filter(|kind| placeholders.iter().any(|seen| seen == kind))
322 }) {
323 outcome.verdict = "skip".into();
324 outcome.reason = Some(format!("no {kind} renderer on this toolkit"));
325 outcome.ms = started.elapsed_ms();
326 return outcome;
327 }
328 if let Err(Fail(message)) = &result {
329 outcome.verdict = "fail".into();
330 outcome.message = Some(message.clone());
331 if policy != ShotPolicy::Never {
332 let _ = drive.shot("failed").await;
334 }
335 }
336 outcome.ms = started.elapsed_ms();
337 outcome.native_unread = std::mem::take(&mut *backend.unread.borrow_mut());
338 outcome.native_unread.dedup();
339 let keep = match policy {
340 ShotPolicy::Never => false,
341 ShotPolicy::OnFailure => result.is_err(),
342 ShotPolicy::Always => true,
343 };
344 if keep {
345 for (name, png) in backend.shots.borrow_mut().drain(..) {
346 outcome.shots.push(name.clone());
347 shots.push(Shot {
348 test: case.name().to_owned(),
349 name,
350 png_base64: b64encode(&png),
351 });
352 }
353 }
354 outcome
355}
356
357struct Guarded {
363 body: Pin<Box<dyn Future<Output = Result<(), Fail>>>>,
364 limit: Option<(f64, Pin<Box<day_core::Sleep>>)>,
365}
366
367impl Guarded {
368 fn new(body: Pin<Box<dyn Future<Output = Result<(), Fail>>>>, secs: Option<f64>) -> Self {
369 Guarded {
370 body,
371 limit: secs.map(|s| (s, Box::pin(day_core::sleep((s * 1000.0) as u32)))),
372 }
373 }
374}
375
376impl Future for Guarded {
377 type Output = Result<(), Fail>;
378
379 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
380 let this = &mut *self;
381 let polled =
382 std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| this.body.as_mut().poll(cx)));
383 match polled {
384 Ok(Poll::Ready(result)) => return Poll::Ready(result),
385 Err(payload) => {
386 let message = day_core::conformance::panic_message(payload.as_ref());
387 return Poll::Ready(Err(Fail(format!("panicked: {message}"))));
388 }
389 Ok(Poll::Pending) => {}
390 }
391 if let Some((secs, timer)) = &mut this.limit
392 && timer.as_mut().poll(cx).is_ready()
393 {
394 return Poll::Ready(Err(Fail(format!("timed out after {secs} s"))));
395 }
396 Poll::Pending
397 }
398}
399
400struct Engine {
408 shots: Rc<RefCell<Vec<Capture>>>,
409 unread: Rc<RefCell<Vec<String>>>,
411}
412
413type Capture = (String, Vec<u8>);
415
416impl DriveBackend for Engine {
417 fn run(&self, op: DriveOp) -> OpFuture {
418 let (shots, unread) = (self.shots.clone(), self.unread.clone());
419 Box::pin(async move {
420 if let DriveOp::Pause(secs) = op {
421 day_core::sleep((secs * 1000.0) as u32).await;
422 return Ok(());
423 }
424 run_step(&op, &shots, &unread).await?;
425 if let Some(native) = native_follow_up(&op) {
426 run_step(&native, &shots, &unread).await?;
427 }
428 Ok(())
429 })
430 }
431}
432
433fn native_follow_up(op: &DriveOp) -> Option<DriveOp> {
435 let (id, expect) = match op {
436 DriveOp::AssertText(id, text) => (
437 id,
438 NativeExpect {
439 text: Some(text.clone()),
440 ..Default::default()
441 },
442 ),
443 DriveOp::AssertValue(id, value) => (
444 id,
445 NativeExpect {
446 number: Some(*value),
447 ..Default::default()
448 },
449 ),
450 DriveOp::AssertOn(id, on) => (
451 id,
452 NativeExpect {
453 checked: Some(*on),
454 ..Default::default()
455 },
456 ),
457 _ => return None,
458 };
459 Some(DriveOp::AssertNative(id.clone(), expect))
460}
461
462async fn run_step(
464 op: &DriveOp,
465 shots: &Rc<RefCell<Vec<Capture>>>,
466 unread: &Rc<RefCell<Vec<String>>>,
467) -> Result<(), Fail> {
468 let step = step_for(op)?;
469 let clock = Stopwatch::start();
474 let mut waited_ms = 0u32;
475 let budget_ms = (crate::DEFAULT_TIMEOUT_SECS * 1000.0) as u32;
476 let revision = next_capture_revision();
479 loop {
480 let reply = crate::exec(step.clone(), revision);
481 if reply.ok {
482 if let (DriveOp::Shot(name), Some(png)) = (op, &reply.png_base64) {
483 shots
484 .borrow_mut()
485 .push((name.clone(), crate::b64decode(png)));
486 }
487 let checked = match op {
488 DriveOp::AssertNative(id, _)
489 | DriveOp::AssertFrame(id, _)
490 | DriveOp::SamplePixel(id, ..) => Some(id),
491 _ => None,
492 };
493 if let (Some(id), Some(data)) = (checked, &reply.data) {
494 let fields = data.get("unread").and_then(|u| u.as_array());
495 for f in fields.into_iter().flatten().filter_map(|f| f.as_str()) {
496 unread.borrow_mut().push(format!("{id} {f}"));
497 }
498 }
499 return Ok(());
500 }
501 let message = reply.error.unwrap_or_else(|| "failed".into());
502 let elapsed_ms = u32::try_from(clock.elapsed_ms()).unwrap_or(u32::MAX);
503 if !reply.retryable || waited_ms.max(elapsed_ms) >= budget_ms {
504 return Err(Fail(format!("{}: {message}", op_name(op))));
505 }
506 let wait = if reply.capture_pending {
507 16
508 } else {
509 crate::RETRY_MS
510 };
511 waited_ms += wait;
512 day_core::sleep(wait).await;
513 }
514}
515
516fn op_name(op: &DriveOp) -> String {
517 match op {
518 DriveOp::Tap(id) | DriveOp::TapAt(id, ..) => format!("tap {id}"),
519 DriveOp::Input(id, _) => format!("input {id}"),
520 DriveOp::Toggle(id, _) => format!("toggle {id}"),
521 DriveOp::SetValue(id, _) => format!("set_value {id}"),
522 DriveOp::Select(id, _) => format!("select {id}"),
523 DriveOp::Focus(id) => format!("focus {id}"),
524 DriveOp::Submit(id) => format!("submit {id}"),
525 DriveOp::Navigate(route) => format!("navigate {route}"),
526 DriveOp::WaitIdle => "wait_idle".into(),
527 DriveOp::Pause(_) => "pause".into(),
528 DriveOp::Shot(name) => format!("shot {name}"),
529 DriveOp::AssertText(id, _) => format!("assert_text {id}"),
530 DriveOp::AssertVisible(id) => format!("assert_visible {id}"),
531 DriveOp::AssertMissing(id) => format!("assert_missing {id}"),
532 DriveOp::AssertHidden(id) => format!("assert_hidden {id}"),
533 DriveOp::Hover(id, _) | DriveOp::HoverLeave(id) => format!("hover {id}"),
534 DriveOp::Pan(id, ..) => format!("pan {id}"),
535 DriveOp::Pinch(id, _) => format!("pinch {id}"),
536 DriveOp::Rotate(id, _) => format!("rotate {id}"),
537 DriveOp::Drag(id, ..) => format!("drag {id}"),
538 DriveOp::Key(_, key) => format!("key {key}"),
539 DriveOp::AssertAnnounced(text) => format!("assert_announced {text}"),
540 DriveOp::AssertValue(id, _) | DriveOp::AssertOn(id, _) => format!("assert_value {id}"),
541 DriveOp::AssertFocused(id, _) => format!("assert_focused {id}"),
542 DriveOp::AssertRoute(route) => format!("assert_route {route}"),
543 DriveOp::A11yAudit(_) => "a11y_audit".into(),
544 DriveOp::AssertNative(id, _) => format!("assert_native {id}"),
545 DriveOp::AssertFrame(id, _) => format!("assert_frame {id}"),
546 DriveOp::SamplePixel(id, ..) => format!("sample_pixel {id}"),
547 DriveOp::AssertOpenedUrl(url) => format!("assert_opened_url {url}"),
548 DriveOp::Activate(id, _) => format!("activate {id}"),
549 DriveOp::Reorder(id, ..) => format!("reorder {id}"),
550 DriveOp::DeleteRow(id, _) => format!("delete_row {id}"),
551 DriveOp::SwipeRow(id, ..) => format!("swipe_row {id}"),
552 DriveOp::ScrollTo(id, _) => format!("scroll_to {id}"),
553 DriveOp::Expand(id, row, _) => format!("expand {id} {row}"),
554 DriveOp::NavBack => "nav_back".into(),
555 DriveOp::TreeMove(id, row, ..) => format!("tree_move {id} {row}"),
556 DriveOp::ContextMenu(id, item) => format!("context_menu {id} {item}"),
557 DriveOp::Menu(item) => format!("menu {item}"),
558 DriveOp::ToolbarPress(item) | DriveOp::ToolbarToggle(item, _) => format!("toolbar {item}"),
559 DriveOp::DialogScripted(_) => "dialog_mode".into(),
560 DriveOp::AssertPresented(_) => "assert_presented".into(),
561 DriveOp::Respond(_) | DriveOp::RespondText(_) => "respond".into(),
562 }
563}
564
565fn step_for(op: &DriveOp) -> Result<Step, Fail> {
568 use serde_json::json;
569 let v = match op {
570 DriveOp::Tap(id) => json!({"op": "tap", "id": id}),
571 DriveOp::Input(id, text) => json!({"op": "input", "id": id, "text": text}),
572 DriveOp::Toggle(id, on) => json!({"op": "toggle", "id": id, "value": on}),
573 DriveOp::SetValue(id, value) => json!({"op": "set_value", "id": id, "value": value}),
574 DriveOp::Select(id, index) => json!({"op": "select", "id": id, "index": index}),
575 DriveOp::Focus(id) => json!({"op": "focus", "id": id}),
576 DriveOp::Submit(id) => json!({"op": "submit", "id": id}),
577 DriveOp::Navigate(route) => json!({"op": "navigate", "route": route}),
578 DriveOp::WaitIdle => json!({"op": "wait_idle"}),
579 DriveOp::Pause(secs) => json!({"op": "pause", "secs": secs}),
580 DriveOp::Shot(name) => json!({"op": "screenshot", "name": name, "in_process": true}),
581 DriveOp::AssertText(id, text) => json!({"op": "assert_text", "id": id, "text": text}),
582 DriveOp::AssertVisible(id) => json!({"op": "assert_visible", "id": id}),
583 DriveOp::AssertMissing(id) => json!({"op": "assert_missing", "id": id}),
584 DriveOp::AssertHidden(id) => json!({"op": "assert_hidden", "id": id}),
585 DriveOp::Hover(id, at) => json!({"op": "hover", "id": id, "at": at.map(|(x, y)| [x, y])}),
586 DriveOp::HoverLeave(id) => json!({"op": "hover", "id": id, "leave": true}),
587 DriveOp::Pan(id, dx, dy) => json!({"op": "pan", "id": id, "by": [dx, dy]}),
588 DriveOp::Pinch(id, scale) => json!({"op": "pinch", "id": id, "scale": scale}),
589 DriveOp::Rotate(id, rotation) => {
590 json!({"op": "rotate", "id": id, "rotation": rotation})
591 }
592 DriveOp::Drag(id, (fx, fy), (tx, ty)) => {
593 json!({"op": "drag", "id": id, "from": [fx, fy], "to": [tx, ty]})
594 }
595 DriveOp::TapAt(id, x, y) => json!({"op": "tap", "id": id, "at": [x, y]}),
596 DriveOp::Key(id, key) => json!({"op": "key", "id": id, "key": key}),
597 DriveOp::AssertAnnounced(text) => json!({"op": "assert_announced", "text": text}),
598 DriveOp::AssertValue(id, value) => json!({"op": "assert_value", "id": id, "value": value}),
599 DriveOp::AssertOn(id, on) => json!({"op": "assert_value", "id": id, "value": on}),
600 DriveOp::AssertFocused(id, focused) => {
601 json!({"op": "assert_focused", "id": id, "focused": focused})
602 }
603 DriveOp::AssertRoute(route) => json!({"op": "assert_route", "route": route}),
604 DriveOp::A11yAudit(id) => json!({"op": "a11y_audit", "id": id}),
605 DriveOp::AssertNative(id, e) => json!({
606 "op": "assert_native", "id": id, "text": e.text, "number": e.number,
607 "checked": e.checked, "enabled": e.enabled, "visible": e.visible,
608 }),
609 DriveOp::AssertFrame(id, f) => json!({
610 "op": "assert_frame", "id": id, "width": f.width, "height": f.height,
611 "x": f.x, "y": f.y, "relative_to": f.relative_to, "tolerance": f.tolerance,
612 }),
613 DriveOp::SamplePixel(id, x, y, color) => {
614 json!({"op": "sample_pixel", "id": id, "x": x, "y": y, "color": color})
615 }
616 DriveOp::AssertOpenedUrl(url) => json!({"op": "assert_opened_url", "url": url}),
617 DriveOp::Activate(id, index) => json!({"op": "activate", "id": id, "index": index}),
618 DriveOp::Reorder(id, from, to) => {
619 json!({"op": "reorder", "id": id, "from": from, "to": to})
620 }
621 DriveOp::DeleteRow(id, row) => json!({"op": "delete_row", "id": id, "row": row}),
622 DriveOp::SwipeRow(id, row, leading, action) => json!({
623 "op": "swipe_row", "id": id, "row": row, "action": action,
624 "edge": if *leading { "leading" } else { "trailing" },
625 }),
626 DriveOp::ScrollTo(id, edge) => json!({"op": "scroll_to", "id": id, "edge": edge}),
627 DriveOp::Expand(id, row, expanded) => {
628 json!({"op": "expand", "id": id, "row": row, "expanded": expanded})
629 }
630 DriveOp::NavBack => json!({"op": "nav_back"}),
631 DriveOp::TreeMove(id, row, parent, index) => json!({
632 "op": "tree_move", "id": id, "row": row, "parent": parent, "index": index,
633 }),
634 DriveOp::ContextMenu(id, item) => json!({"op": "context_menu", "id": id, "item": item}),
635 DriveOp::Menu(item) => json!({"op": "menu", "id": item}),
636 DriveOp::ToolbarPress(item) => json!({"op": "toolbar", "item": item}),
637 DriveOp::ToolbarToggle(item, on) => json!({"op": "toolbar", "item": item, "on": on}),
638 DriveOp::DialogScripted(scripted) => json!({
639 "op": "dialog_mode", "mode": if *scripted { "scripted" } else { "native" },
640 }),
641 DriveOp::AssertPresented(title) => json!({"op": "assert_presented", "title": title}),
642 DriveOp::Respond(Some(button)) => json!({"op": "respond", "button": button}),
643 DriveOp::Respond(None) => json!({"op": "respond", "dismiss": true}),
644 DriveOp::RespondText(text) => json!({"op": "respond", "text": text}),
645 };
646 serde_json::from_value(v).map_err(|e| Fail(format!("{}: {e}", op_name(op))))
647}
648
649struct Stopwatch {
652 #[cfg(not(target_arch = "wasm32"))]
653 started: std::time::Instant,
654}
655
656impl Stopwatch {
657 fn start() -> Self {
658 Stopwatch {
659 #[cfg(not(target_arch = "wasm32"))]
660 started: std::time::Instant::now(),
661 }
662 }
663 #[cfg_attr(
664 target_arch = "wasm32",
665 expect(
666 clippy::unused_self,
667 reason = "wasm has no clock; the native arm reads the start time"
668 )
669 )]
670 fn elapsed_ms(&self) -> u64 {
671 #[cfg(not(target_arch = "wasm32"))]
672 {
673 self.started.elapsed().as_millis() as u64
674 }
675 #[cfg(target_arch = "wasm32")]
676 {
677 0
678 }
679 }
680}
681
682#[cfg(test)]
683mod tests {
684 use super::glob;
685
686 #[test]
687 fn globs_match_prefixes_suffixes_and_middles() {
688 assert!(glob("button-*", "button-status"));
689 assert!(glob("*-status", "button-status"));
690 assert!(glob("button*status", "button-status"));
691 assert!(glob("*", "anything"));
692 assert!(glob("button-status", "button-status"));
693 assert!(!glob("button-*", "slider-range"));
694 assert!(!glob("button", "button-status"));
695 }
696}