chiark / gitweb /
changelog: document further make-release changes
[otter.git] / apitest / at-bundles.rs
1 // Copyright 2020-2021 Ian Jackson and contributors to Otter
2 // SPDX-License-Identifier: AGPL-3.0-or-later
3 // There is NO WARRANTY.
4
5 use crate::*;
6
7 type Ctx = UsualCtx;
8
9 impl Ctx {
10   #[throws(Explode)]
11   fn bundles(&mut self) {
12     self.upload_and_check_bundle(
13       "test-bundle","lemon", "example-lemon","a lemon",
14       &mut |_|Ok(()))?;
15   }
16  
17   #[throws(Explode)]
18   fn big(&mut self) {
19     self.upload_and_check_bundle(
20       "big-bundle","duped-example", "chess-purple-cannon", "a purple cannon",
21       &mut |ctx|
22     {
23       ctx.otter_resetting(&ctx.ds().gss("reset modded-spec")?)?;
24
25       let alice = ctx.connect_player(&ctx.alice)?;
26       let pieces = alice.pieces::<PIA>()?;
27       dbgc!(&pieces);
28       for expect in &["a purple knight", "a yellow bishop"] {
29         let _: PIA = pieces.find_by_desc_glob(expect);
30       }
31
32       Ok(())
33     })?;
34   }
35  
36   #[throws(Explode)]
37   fn builtin_spec(&mut self) {
38     self.su().mgmt_conn.borrow_mut().alter_game(
39       vec![ MGI::ResetFromNamedSpec {
40         spec: "demo".to_owned(),
41       }],
42       None,
43     )?;
44   }
45  
46   #[throws(Explode)]
47   fn reset_with_bundles(&mut self) {
48     self.clear_reset_to_demo()?;
49
50     // check that the spec is not accessible now
51     let e = self.otter(
52       &G("reset demo-in-test-bundle")
53     ).unwrap_err();
54     let e: ExitStatusError = e.downcast().unwrap();
55     assert_eq!(e.0.code(), Some(12));
56
57     self.otter_resetting(
58       &G("reset demo-in-test-bundle @examples@/test-bundle.zip")
59     )?;
60
61     self.clear_reset_to_demo()?;
62   }
63 }
64
65 #[throws(Explode)]
66 fn tests(mut c: Ctx) {
67   test!(c, "bundles",                       c.bundles()                ?);
68   test!(c, "reset-with-bundles",            c.reset_with_bundles()     ?);
69   test!(c, "big",                           c.big()                    ?);
70   test!(c, "builtin-spec",                  c.builtin_spec()           ?);
71 }
72
73 #[throws(Explode)]
74 pub fn main() {
75   tests(Ctx::setup()?)?;
76 }