chiark / gitweb /
apitest: Move setup code to apitest/main
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 17:19:55 +0000 (18:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 17:19:55 +0000 (18:19 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/at-otter.rs
apitest/main.rs

index fb1843d4f35a8013ced67fff5a80ac9593644bed..fd30821d339ce93e2f5f9230405daccec9c24920 100644 (file)
@@ -247,17 +247,5 @@ fn tests(mut c: Ctx) {
 
 #[throws(Explode)]
 pub fn main() {
-  let (opts, _instance, su) = setup_core(
-    &[module_path!()],
-  )?;
-  let spec = su.ds.game_spec_data()?;
-  let mut mc = su.mgmt_conn();
-  let [alice, bob]: [Player; 2] =
-    su.ds.setup_static_users(&mut mc, default())?
-    .into_iter().map(|sus| Player { nick: sus.nick, url: sus.url })
-    .collect::<ArrayVec<_>>().into_inner().unwrap();
-  drop(mc);
-
-  let su_rc = Rc::new(RefCell::new(su));
-  tests(Ctx { opts, spec, su_rc, alice, bob, prctx: default() })?;
+  tests(UsualCtx::setup()?)?;
 }
index 98afbb66892a6ae4430f722ec44441e6019e54c9..4657999e4241825884c3b1a54c906d2ee28c73cf 100644 (file)
@@ -540,6 +540,25 @@ impl UsualCtx {
   }
 }
 
+impl UsualCtx {
+  #[throws(AE)]
+  pub fn setup() -> Self {
+    let (opts, _instance, su) = setup_core(
+      &[module_path!()],
+    )?;
+    let spec = su.ds.game_spec_data()?;
+    let mut mc = su.mgmt_conn();
+    let [alice, bob]: [Player; 2] =
+      su.ds.setup_static_users(&mut mc, default())?
+      .into_iter().map(|sus| Player { nick: sus.nick, url: sus.url })
+      .collect::<ArrayVec<_>>().into_inner().unwrap();
+    drop(mc);
+
+    let su_rc = Rc::new(RefCell::new(su));
+    UsualCtx { opts, spec, su_rc, alice, bob, prctx: default() }
+  }
+}
+
 portmanteau_has!("at-otter.rs",   at_otter);
 portmanteau_has!("at-bundles.rs", at_bundles);