chiark / gitweb /
jstest: lower: Honour OTTER_JST_LOWER_ONLY
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 10 Jul 2021 12:11:19 +0000 (13:11 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 10 Jul 2021 12:11:38 +0000 (13:11 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
jstest/jst-lower.rs

index d463a85a3512c6505bb6c334c14847882f5e11e3..c4dbd8e67e3f7fb2c09392cba8d70f7ca9d8905f 100644 (file)
@@ -39,6 +39,7 @@ pub struct StartPiece {
 #[derive(Debug,Clone,Default)]
 pub struct Tests {
   tests: IndexMap<String, Test>,
+  only: Option<String>,
 }
 
 #[derive(Debug,Clone,Default)]
@@ -228,9 +229,13 @@ impl TestsAccumulator {
       .open(&opts.script)?;
     let script = BufWriter::new(script);
 
+    let mut tests: Tests = default();
+    if let Some(only) = env::var_os("OTTER_JST_LOWER_ONLY") {
+      tests.only = Some(only.into_string().unwrap())
+    }
+
     TestsAccumulator {
-      tests: default(),
-      script, tera,
+      tests, script, tera,
     }
   }
 
@@ -244,6 +249,10 @@ impl TestsAccumulator {
   pub fn add_test<T>(&mut self, name: &str,
                      pieces: Vec<StartPieceSpec>,
                      targets: Vec<T>) where T: TryInto<Vpid> + Copy + Debug {
+    if let Some(only) = &self.tests.only {
+      if name != only { return; }
+    }
+
     let mut zm = ZCoord::default().clone_mut();
     let pieces: IndexMap<Vpid,StartPiece> = pieces.into_iter().map(
       |StartPieceSpec { id, pinned, moveable }| {
@@ -278,6 +287,18 @@ impl TestsAccumulator {
   }
 }
 
+impl Tests {
+  #[throws(AE)]
+  fn finish(self) {
+    match self.only {
+      None => { },
+      Some(only) => {
+        throw!(anyhow!("tests limited to {}, treating as failure", &only))
+      }
+    }
+  }
+}
+
 #[throws(Explode)]
 fn main() {
   let opts = Opts::from_args();
@@ -330,6 +351,8 @@ fn main() {
   for test in tests.tests.values() {
     test.check()?;
   }
+
+  tests.finish()?;
 }
 
 static TEMPLATE: &'static str = r#"