From b5340b75c6a72590d780d7d54b868cf138552b07 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 6 Jan 2021 01:14:13 +0000 Subject: [PATCH] landscape tests Signed-off-by: Ian Jackson --- Makefile | 15 ++++++++++++--- daemon/api.rs | 14 -------------- daemon/main.rs | 6 +++--- src/ui.rs | 23 +++++++++++++++++++++++ wdriver.rs | 27 ++++++++++++++++++++++----- wdriver/run1 | 13 +++++++++---- 6 files changed, 69 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index f364ac65..3d75fd93 100644 --- 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 diff --git a/daemon/api.rs b/daemon/api.rs index 2103d042..b5bee03e 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -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, diff --git a/daemon/main.rs b/daemon/main.rs index 36d731f8..e8bf5ba6 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -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("/")] #[throws(OER)] -fn loading_l(layout: AbbrevPresentationLayout, ia: PlayerQueryString) +fn loading_l(layout: Parse, ia: PlayerQueryString) -> Template { - loading(Some(layout.0), ia)? + loading(Some((layout.0).0), ia)? } #[throws(OE)] diff --git a/src/ui.rs b/src/ui.rs index 237afe60..398839ca 100644 --- 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", + })? + } +} diff --git a/wdriver.rs b/wdriver.rs index 11ca44c4..35d76aac 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -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 JustWarn for Result { #[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, + #[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; 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 diff --git a/wdriver/run1 b/wdriver/run1 index d2735dbe..771d8a36 100755 --- a/wdriver/run1 +++ b/wdriver/run1 @@ -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 -