base: Allow the test target to be compiled on WASM

master
Damir Jelić 2021-03-30 13:05:45 +02:00
parent 02b44ca9ba
commit 74274e6dcb
2 changed files with 24 additions and 5 deletions

View File

@ -54,17 +54,15 @@ features = ["sync", "fs"]
[dev-dependencies] [dev-dependencies]
matrix-sdk-test = { version = "0.2.0", path = "../matrix_sdk_test" } matrix-sdk-test = { version = "0.2.0", path = "../matrix_sdk_test" }
http = "0.2.3" http = "0.2.3"
tracing-subscriber = "0.2.15"
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { version = "1.1.0", default-features = false, features = ["rt-multi-thread", "macros"] }
tempfile = "3.2.0" tempfile = "3.2.0"
mockito = "0.29.0"
rustyline = "7.1.0" rustyline = "7.1.0"
rustyline-derive = "0.4.0" rustyline-derive = "0.4.0"
atty = "0.2.14" atty = "0.2.14"
clap = "2.33.3" clap = "2.33.3"
syntect = "4.5.0" syntect = "4.5.0"
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { version = "1.1.0", default-features = false, features = ["rt-multi-thread", "macros"] }
[target.'cfg(target_arch = "wasm32")'.dev-dependencies] [target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.19" wasm-bindgen-test = "0.3.19"

View File

@ -3,8 +3,11 @@ use std::{convert::TryFrom, fmt::Debug, sync::Arc};
use futures::executor::block_on; use futures::executor::block_on;
use serde::Serialize; use serde::Serialize;
#[cfg(not(target_arch = "wasm32"))]
use atty::Stream; use atty::Stream;
#[cfg(not(target_arch = "wasm32"))]
use clap::{App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches, SubCommand}; use clap::{App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches, SubCommand};
#[cfg(not(target_arch = "wasm32"))]
use rustyline::{ use rustyline::{
completion::{Completer, Pair}, completion::{Completer, Pair},
error::ReadlineError, error::ReadlineError,
@ -13,8 +16,10 @@ use rustyline::{
validate::{MatchingBracketValidator, Validator}, validate::{MatchingBracketValidator, Validator},
CompletionType, Config, Context, EditMode, Editor, OutputStreamType, CompletionType, Config, Context, EditMode, Editor, OutputStreamType,
}; };
#[cfg(not(target_arch = "wasm32"))]
use rustyline_derive::Helper; use rustyline_derive::Helper;
#[cfg(not(target_arch = "wasm32"))]
use syntect::{ use syntect::{
dumps::from_binary, dumps::from_binary,
easy::HighlightLines, easy::HighlightLines,
@ -30,12 +35,14 @@ use matrix_sdk_base::{
}; };
#[derive(Clone)] #[derive(Clone)]
#[cfg(not(target_arch = "wasm32"))]
struct Inspector { struct Inspector {
store: Store, store: Store,
printer: Printer, printer: Printer,
} }
#[derive(Helper)] #[derive(Helper)]
#[cfg(not(target_arch = "wasm32"))]
struct InspectorHelper { struct InspectorHelper {
store: Store, store: Store,
_highlighter: MatchingBracketHighlighter, _highlighter: MatchingBracketHighlighter,
@ -43,6 +50,7 @@ struct InspectorHelper {
_hinter: HistoryHinter, _hinter: HistoryHinter,
} }
#[cfg(not(target_arch = "wasm32"))]
impl InspectorHelper { impl InspectorHelper {
const EVENT_TYPES: &'static [&'static str] = &[ const EVENT_TYPES: &'static [&'static str] = &[
"m.room.aliases", "m.room.aliases",
@ -105,6 +113,7 @@ impl InspectorHelper {
} }
} }
#[cfg(not(target_arch = "wasm32"))]
impl Completer for InspectorHelper { impl Completer for InspectorHelper {
type Candidate = Pair; type Candidate = Pair;
@ -181,15 +190,19 @@ impl Completer for InspectorHelper {
} }
} }
#[cfg(not(target_arch = "wasm32"))]
impl Hinter for InspectorHelper { impl Hinter for InspectorHelper {
type Hint = String; type Hint = String;
} }
#[cfg(not(target_arch = "wasm32"))]
impl Highlighter for InspectorHelper {} impl Highlighter for InspectorHelper {}
#[cfg(not(target_arch = "wasm32"))]
impl Validator for InspectorHelper {} impl Validator for InspectorHelper {}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[cfg(not(target_arch = "wasm32"))]
struct Printer { struct Printer {
ps: Arc<SyntaxSet>, ps: Arc<SyntaxSet>,
ts: Arc<ThemeSet>, ts: Arc<ThemeSet>,
@ -197,6 +210,7 @@ struct Printer {
color: bool, color: bool,
} }
#[cfg(not(target_arch = "wasm32"))]
impl Printer { impl Printer {
fn new(json: bool, color: bool) -> Self { fn new(json: bool, color: bool) -> Self {
let syntax_set: SyntaxSet = from_binary(include_bytes!("./syntaxes.bin")); let syntax_set: SyntaxSet = from_binary(include_bytes!("./syntaxes.bin"));
@ -244,6 +258,7 @@ impl Printer {
} }
} }
#[cfg(not(target_arch = "wasm32"))]
impl Inspector { impl Inspector {
fn new(database_path: &str, json: bool, color: bool) -> Self { fn new(database_path: &str, json: bool, color: bool) -> Self {
let printer = Printer::new(json, color); let printer = Printer::new(json, color);
@ -388,6 +403,7 @@ impl Inspector {
} }
} }
#[cfg(not(target_arch = "wasm32"))]
fn main() { fn main() {
let argparse = Argparse::new("state-inspector") let argparse = Argparse::new("state-inspector")
.global_setting(ArgParseSettings::DisableVersion) .global_setting(ArgParseSettings::DisableVersion)
@ -431,3 +447,8 @@ fn main() {
block_on(inspector.run(matches)); block_on(inspector.run(matches));
} }
} }
#[cfg(target_arch = "wasm32")]
fn main() {
panic!("This example doesn't run on WASM");
}