chiark / gitweb /
wdt: conflict test actually tests, and passes, yay!
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 29 Jan 2021 23:22:00 +0000 (23:22 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 30 Jan 2021 00:39:31 +0000 (00:39 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
wdriver/wdt-simple.rs

index 01aed1359c2dac466b5a0e774427219fc1fee8d6..9f44d45555cf43d48130f0e1c3c357eb505e2921 100644 (file)
@@ -218,12 +218,18 @@ impl Ctx {
     nix::sys::signal::kill(pid, nix::sys::signal::SIGCONT)?;
 
     #[derive(Debug)]
-    struct Got {
+    struct Got<'s> {
+      side: &'s Side<'s>,
+      yes: bool,
       now: Pos,
       log: Vec<String>,
       held: Option<String>,
       client: String,
     }
+    impl<'s> Deref for Got<'s> {
+      type Target = Side<'s>;
+      fn deref<'t>(&'t self) -> &'t Side<'s> { &self.side }
+    }
 
     let gots = sides.iter().map(|side|{
       let mut w = su.w(side.window)?;
@@ -243,15 +249,24 @@ impl Ctx {
 
       let held = w.piece_held(&pc)?;
       let client = w.client()?;
+      let yes = held.as_ref() == Some(&client);
 
-      Ok::<_,AE>(Got { now, log, held, client })
+      Ok::<_,AE>(Got { side, now, log, held, client, yes })
     }).collect::<Result<Vec<_>,AE>>()?;
 
-    dbg!(gots);
-/*
-    let yesno = izip!(&sides, &gots).map(|side, got|{
-      let yn = 
-    }).collect::<Result<Vec<_>,AE>>.context("compare")?;*/
+    dbg!(&gots);
+
+    let y = gots.iter().filter(|got|  got.yes).next().expect("y");
+    let n = gots.iter().filter(|got| !got.yes).next().expect("n");
+    ensure_eq!(y.now, y.try_end);
+    ensure_eq!(n.now, y.try_end);
+    ensure_eq!(n.now, y.try_end);
+    ensure_eq!(n.held, y.held);
+
+    for got in &gots {
+      let conflict = got.log.iter().any(|m| m.starts_with("Conflict!"));
+      ensure_eq!(conflict, !got.yes);
+    }
   }
 }