chiark / gitweb /
landscape tests
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 6 Jan 2021 01:14:13 +0000 (01:14 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 6 Jan 2021 01:14:17 +0000 (01:14 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Makefile
daemon/api.rs
daemon/main.rs
src/ui.rs
wdriver.rs
wdriver/run1

index f364ac65b49c09f32f7d6fdccd1d3c2fd2ba0cc9..3d75fd9307c3e7ce6570c261f5f165da2c293544 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -261,13 +261,22 @@ libraries: $(LIBRARY_FILES)
 
 WDT_TESTS := $(basename $(notdir $(wildcard wdriver/wdt-*.rs)))
 
-wdt:   $(foreach f, $(WDT_TESTS), stamp/$f.check)
+WDT_LANDSCAPE_TESTS = wdt-altergame
 
-stamp/wdt-%.check:     wdriver/run1 stamp/cargo.debug stamp/cargo-wdt.debug \
-                       $(FILEASSETS) templates/script.js $(LIBRARY_FILES)
+wdt:   $(foreach f, $(WDT_TESTS), stamp/$f.check) \
+       $(foreach f, $(WDT_LANDSCAPE_TESTS), stamp/$f.lcheck) \
+
+WDT_DEPS =     wdriver/run1 stamp/cargo.debug stamp/cargo-wdt.debug \
+               $(FILEASSETS) templates/script.js $(LIBRARY_FILES)
+
+stamp/wdt-%.check:     $(WDT_DEPS)
        $(NAILING_CARGO_JUST_RUN) $(abspath $<) $(basename $(notdir $@))
        $(stamp)
 
+stamp/wdt-%.lcheck:    $(WDT_DEPS)
+       $(NAILING_CARGO_JUST_RUN) $(abspath $<) $(basename $(notdir $@)) --as-if=lwdt-$* --layout=Landscape
+       $(stamp)
+
 #---------- deployment ----------
 
 DEPLOY_USER=ian@login.chiark.greenend.org.uk
index 2103d042b8091fb028d41b873597ba6afdeeb74f..b5bee03eff6f2c91c516c082e713ba396ffead0d 100644 (file)
@@ -8,20 +8,6 @@ type WRC = WhatResponseToClientOp;
 
 type PL = PresentationLayout;
 
-pub struct AbbrevPresentationLayout(pub PresentationLayout);
-
-impl<'r> FromParam<'r> for AbbrevPresentationLayout {
-  type Error = ();
-  #[throws(Self::Error)]
-  fn from_param(param: &'r RawStr) -> Self {
-    AbbrevPresentationLayout(match param.as_str() {
-      "p" => PL::Portrait,
-      "l" => PL::Landscape,
-      _ => throw!(())
-    })
-  }
-}
-
 #[derive(Clone,Debug)]
 pub struct InstanceAccess<'i, Id> {
   pub raw_token: &'i RawTokenVal,
index 36d731f8238a7868bf4d3e8da34b95941b26e091..e8bf5ba61f25064841cb7ac27e78772f3b95586c 100644 (file)
@@ -23,7 +23,7 @@ pub use rocket_contrib::templates::tera::{self, Value};
 pub use rocket_contrib::templates::Engines;
 pub use rocket_contrib::templates::Template;
 
-pub use crate::api::{AbbrevPresentationLayout, InstanceAccess};
+pub use crate::api::InstanceAccess;
 pub use crate::api::{OnlineErrorResponse};
 pub use crate::cmdlistener::*;
 
@@ -98,9 +98,9 @@ fn loading_p(ia: PlayerQueryString) -> Template {
 }
 #[get("/<layout>")]
 #[throws(OER)]
-fn loading_l(layout: AbbrevPresentationLayout, ia: PlayerQueryString)
+fn loading_l(layout: Parse<AbbrevPresentationLayout>, ia: PlayerQueryString)
              -> Template {
-  loading(Some(layout.0), ia)?
+  loading(Some((layout.0).0), ia)?
 }
 
 #[throws(OE)]
index 237afe6099d5bd5e16ab8cd70cfa2049489863a2..398839cafb3e7cbeccd2509ab7b5d2c759c63afe 100644 (file)
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -31,3 +31,26 @@ impl Default for PresentationLayout {
   fn default() -> Self { PL::Portrait }
 }
 
+pub struct AbbrevPresentationLayout(pub PresentationLayout);
+
+impl FromStr for AbbrevPresentationLayout {
+  type Err = ();
+  #[throws(Self::Err)]
+  fn from_str(s: &str) -> Self {
+    AbbrevPresentationLayout(match s {
+      "p" => PL::Portrait,
+      "l" => PL::Landscape,
+      _ => throw!(())
+    })
+  }
+}
+
+impl Display for AbbrevPresentationLayout {
+  #[throws(fmt::Error)]
+  fn fmt(&self, f: &mut fmt::Formatter) {
+    f.write_str(match self.0 {
+      PL::Portrait => "p",
+      PL::Landscape => "l",
+    })?
+  }
+}
index 11ca44c4893b3700028014f1340a8a09c24e2b5b..35d76aac0f950785b499e82b86de42f21347d64e 100644 (file)
@@ -51,6 +51,7 @@ pub use otter::gamestate::{self, Generation};
 pub use otter::global::InstanceName;
 pub use otter::mgmtchannel::MgmtChannel;
 pub use otter::spec::{Coord, Pos, PosC};
+pub use otter::ui::{AbbrevPresentationLayout, PresentationLayout};
 
 pub type T4d = t4::WebDriver;
 pub type WDE = t4::error::WebDriverError;
@@ -108,16 +109,22 @@ impl<T> JustWarn<T> for Result<T,AE> {
 
 #[derive(Debug,Clone)]
 #[derive(StructOpt)]
-struct Opts {
+pub struct Opts {
   #[structopt(long="--no-bwrap")]
   no_bwrap: bool,
 
   #[structopt(long="--tmp-dir", default_value="tmp")]
   tmp_dir: String,
 
+  #[structopt(long="--as-if")]
+  as_if: Option<String>,
+
   #[structopt(long="--pause", default_value="0ms")]
   pause: humantime::Duration,
 
+  #[structopt(long="--layout", default_value="Portrait")]
+  layout: PresentationLayout,
+
   #[structopt(long="--geckodriver-args", default_value="")]
   geckodriver_args: String,
 }
@@ -132,6 +139,7 @@ type WindowState = Option<String>;
 pub struct Setup {
   pub ds: DirSubst,
   pub mgmt_conn: MgmtChannel,
+  pub opts: Opts,
   driver: T4d,
   current_window: WindowState,
   screenshot_count: ScreenShotCount,
@@ -358,7 +366,7 @@ fn reinvoke_via_bwrap(_opts: &Opts, current_exe: &str) -> Void {
 }
 
 #[throws(AE)]
-fn prepare_tmpdir(opts: &Opts, current_exe: &str) -> DirSubst {
+fn prepare_tmpdir<'x>(opts: &'x Opts, mut current_exe: &'x str) -> DirSubst {
   #[throws(AE)]
   fn getcwd() -> String {
     env::current_dir()
@@ -368,6 +376,10 @@ fn prepare_tmpdir(opts: &Opts, current_exe: &str) -> DirSubst {
       .to_owned()
   }
 
+  if let Some(as_if) = &opts.as_if {
+    current_exe = as_if;
+  }
+
   let start_dir = getcwd()
     .context("canonicalise our invocation directory (getcwd)")?;
 
@@ -1082,6 +1094,7 @@ pub fn setup(exe_module_path: &str) -> (Setup, Instance) {
     ds,
     mgmt_conn,
     driver,
+    opts,
     screenshot_count,
     current_window: None,
     windows_squirreled,
@@ -1099,15 +1112,19 @@ impl Setup {
     fn mk(su: &mut Setup, instance: &Instance, u: StaticUser) -> Window {
       let nick: &str = u.into();
       let token = u.get_str("Token").expect("StaticUser missing Token");
-      let subst = su.ds.also([("nick",  nick),
-                              ("token", token)].iter());
+      let pl = AbbrevPresentationLayout(su.opts.layout).to_string();
+      let subst = su.ds.also([
+        ("nick",  nick),
+        ("token", token),
+        ("pl",    &pl),
+      ].iter());
       su.ds.otter(&subst
                   .ss("--super                          \
                        --account server:@nick@       \
                        --fixed-token @token@         \
                        join-game server::dummy")?)?;
       let w = su.new_window(instance, nick)?;
-      let url = subst.subst("@url@/?@token@")?;
+      let url = subst.subst("@url@/@pl@?@token@")?;
       su.w(&w)?.get(url)?;
       su.w(&w)?.screenshot("initial")?;
       w
index d2735dbe1590ba8d18225113783a34cfc0880727..771d8a369a62ddb04e2672fa85cda738e6a4875f 100755 (executable)
@@ -1,15 +1,20 @@
 #!/bin/bash
 set -e
 
-tname="$1";
+tname="$1"; shift;
 mkdir -p tmp
 
-target/debug/"$tname" 2>&1 | ts -s %.s >tmp/"$tname".log
+lname="$tname"
+case "$1" in
+--as-if=*)     lname="${1#--as-if}";;
+esac
+lname="$lname.log"
+
+target/debug/"$tname" "$@" 2>&1 | ts -s %.s >tmp/"$lname"
 case "${PIPESTATUS[*]}" in
 "0 0") exit 0;
 esac
 
- <tmp/"$tname".log \
- tail -40
+tail -40 <tmp/"$lname"
 
 exit 1