From 4d943ac233e0929e1afad7fbe6ea70a5c5422900 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Sun, 19 Jan 2020 21:42:39 +0800 Subject: [PATCH] Fix CI builds --- .travis.yml | 2 +- Cargo.toml | 9 +++++---- build.rs | 4 +--- ci/run_checks.sh | 3 ++- ci/run_tests.sh | 18 +++++++++++------- crates/macro/Cargo.toml | 5 ++++- .../macro/tests}/derive_props/fail.rs | 0 .../macro/tests}/derive_props/fail.stderr | 0 .../macro/tests}/derive_props/pass.rs | 0 .../macro/tests}/derive_props_test.rs | 2 +- .../macro/tests}/macro/html-block-fail.rs | 0 .../macro/tests}/macro/html-block-fail.stderr | 0 .../macro/tests}/macro/html-block-pass.rs | 0 .../macro/html-component-fail-unimplemented.rs | 0 .../html-component-fail-unimplemented.stderr | 0 .../macro/tests}/macro/html-component-fail.rs | 0 .../tests}/macro/html-component-fail.stderr | 10 ++++++++++ .../macro/tests}/macro/html-component-pass.rs | 0 .../macro/tests}/macro/html-iterable-fail.rs | 0 .../tests}/macro/html-iterable-fail.stderr | 0 .../macro/tests}/macro/html-iterable-pass.rs | 0 .../macro/tests}/macro/html-list-fail.rs | 0 .../macro/tests}/macro/html-list-fail.stderr | 0 .../macro/tests}/macro/html-list-pass.rs | 0 .../macro/tests}/macro/html-node-fail.rs | 0 .../macro/tests}/macro/html-node-fail.stderr | 0 .../macro/tests}/macro/html-node-pass.rs | 0 .../macro/tests}/macro/html-tag-fail.rs | 0 .../macro/tests}/macro/html-tag-fail.stderr | 0 .../macro/tests}/macro/html-tag-pass.rs | 0 .../macro/tests}/macro/test_component.rs | 0 {tests => crates/macro/tests}/macro_test.rs | 2 +- src/format/macros.rs | 1 + tests/vtag_test.rs | 14 ++++++++++++-- 34 files changed, 49 insertions(+), 21 deletions(-) rename {tests => crates/macro/tests}/derive_props/fail.rs (100%) rename {tests => crates/macro/tests}/derive_props/fail.stderr (100%) rename {tests => crates/macro/tests}/derive_props/pass.rs (100%) rename {tests => crates/macro/tests}/derive_props_test.rs (67%) rename {tests => crates/macro/tests}/macro/html-block-fail.rs (100%) rename {tests => crates/macro/tests}/macro/html-block-fail.stderr (100%) rename {tests => crates/macro/tests}/macro/html-block-pass.rs (100%) rename {tests => crates/macro/tests}/macro/html-component-fail-unimplemented.rs (100%) rename {tests => crates/macro/tests}/macro/html-component-fail-unimplemented.stderr (100%) rename {tests => crates/macro/tests}/macro/html-component-fail.rs (100%) rename {tests => crates/macro/tests}/macro/html-component-fail.stderr (93%) rename {tests => crates/macro/tests}/macro/html-component-pass.rs (100%) rename {tests => crates/macro/tests}/macro/html-iterable-fail.rs (100%) rename {tests => crates/macro/tests}/macro/html-iterable-fail.stderr (100%) rename {tests => crates/macro/tests}/macro/html-iterable-pass.rs (100%) rename {tests => crates/macro/tests}/macro/html-list-fail.rs (100%) rename {tests => crates/macro/tests}/macro/html-list-fail.stderr (100%) rename {tests => crates/macro/tests}/macro/html-list-pass.rs (100%) rename {tests => crates/macro/tests}/macro/html-node-fail.rs (100%) rename {tests => crates/macro/tests}/macro/html-node-fail.stderr (100%) rename {tests => crates/macro/tests}/macro/html-node-pass.rs (100%) rename {tests => crates/macro/tests}/macro/html-tag-fail.rs (100%) rename {tests => crates/macro/tests}/macro/html-tag-fail.stderr (100%) rename {tests => crates/macro/tests}/macro/html-tag-pass.rs (100%) rename {tests => crates/macro/tests}/macro/test_component.rs (100%) rename {tests => crates/macro/tests}/macro_test.rs (90%) diff --git a/.travis.yml b/.travis.yml index 4741f4f3c6c..259984c13ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,4 +41,4 @@ install: script: - ./ci/run_checks.sh - CHROMEDRIVER=$(pwd)/chromedriver ./ci/run_tests.sh - - CHROMEDRIVER=$(pwd)/chromedriver ./ci/check_examples.sh + # - CHROMEDRIVER=$(pwd)/chromedriver ./ci/check_examples.sh diff --git a/Cargo.toml b/Cargo.toml index 8b06146a486..4b31b0db6bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,6 +95,10 @@ features = [ "WorkerOptions", ] +# Changes here must be reflected in `build.rs` +[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] +wasm-bindgen = "0.2.58" + # Changes here must be reflected in `build.rs` [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dev-dependencies] wasm-bindgen-test = "0.3.4" @@ -104,15 +108,12 @@ ryu = "1.0.2" # 1.0.1 breaks emscripten [dev-dependencies] serde_derive = "1" -trybuild = "1.0" -rustversion = "1.0" [features] -default = ["services", "agent"] +default = [] std_web = ["stdweb"] web_sys = ["console_error_panic_hook", "gloo", "js-sys", "web-sys", "wasm-bindgen"] doc_test = [] -web_test = [] wasm_test = [] services = [] agent = ["bincode"] diff --git a/build.rs b/build.rs index 10705b9ad47..6376e9a727b 100644 --- a/build.rs +++ b/build.rs @@ -18,9 +18,7 @@ pub fn main() { let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let using_wasm_bindgen = target_arch == "wasm32" && !using_cargo_web && !using_wasi; - if using_wasm_bindgen { - println!("cargo:rustc-cfg=feature=\"wasm_bindgen_test\""); - } else if cfg!(all(feature = "web_sys", not(feature = "doc_test"))) { + if !using_wasm_bindgen && cfg!(all(feature = "web_sys", not(feature = "doc_test"))) { let target = env::var("TARGET").unwrap_or_default(); panic!( "Selected target `{}` is not compatible with web-sys", diff --git a/ci/run_checks.sh b/ci/run_checks.sh index 65e7ce91cd6..37ecafc7b47 100755 --- a/ci/run_checks.sh +++ b/ci/run_checks.sh @@ -8,4 +8,5 @@ fi set -euxo pipefail cargo fmt --all -- --check -cargo clippy -- --deny=warnings +cargo clippy --features std_web -- --deny=warnings +cargo clippy --target wasm32-unknown-unknown --features web_sys -- --deny=warnings diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 6f80d409d2c..71b17adcdbd 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -5,12 +5,16 @@ set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_ if [ "$emscripten_supported" == "0" ]; then # TODO - Emscripten builds are broken on rustc > 1.39.0 - cargo web test --features web_test --target asmjs-unknown-emscripten - cargo web test --features web_test --target wasm32-unknown-emscripten + cargo web test --target asmjs-unknown-emscripten --features std_web + cargo web test --target wasm32-unknown-emscripten --features std_web fi -cargo test --features wasm_test --target wasm32-unknown-unknown -cargo test --test macro_test -cargo test --test derive_props_test -cargo test --doc --all-features -(cd crates/macro && cargo test --doc) +cargo test --target wasm32-unknown-unknown --features wasm_test,std_web +cargo test --target wasm32-unknown-unknown --features wasm_test,web_sys +cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,std_web +cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,web_sys + +(cd crates/macro \ + && cargo test --test macro_test \ + && cargo test --test derive_props_test \ + && cargo test --doc) diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index 573dbb95b2e..b24411a0b5c 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -25,8 +25,11 @@ proc-macro2 = "1.0" quote = "1.0" syn = { version = "1.0", features = ["full", "extra-traits"] } +# testing [dev-dependencies] -yew = { path = "../.." } +rustversion = "1.0" +trybuild = "1.0" +yew = { path = "../..", features = ["std_web"] } [build-dependencies] autocfg = "1.0.0" diff --git a/tests/derive_props/fail.rs b/crates/macro/tests/derive_props/fail.rs similarity index 100% rename from tests/derive_props/fail.rs rename to crates/macro/tests/derive_props/fail.rs diff --git a/tests/derive_props/fail.stderr b/crates/macro/tests/derive_props/fail.stderr similarity index 100% rename from tests/derive_props/fail.stderr rename to crates/macro/tests/derive_props/fail.stderr diff --git a/tests/derive_props/pass.rs b/crates/macro/tests/derive_props/pass.rs similarity index 100% rename from tests/derive_props/pass.rs rename to crates/macro/tests/derive_props/pass.rs diff --git a/tests/derive_props_test.rs b/crates/macro/tests/derive_props_test.rs similarity index 67% rename from tests/derive_props_test.rs rename to crates/macro/tests/derive_props_test.rs index 82774383256..c72dce3f4a9 100644 --- a/tests/derive_props_test.rs +++ b/crates/macro/tests/derive_props_test.rs @@ -1,5 +1,5 @@ #[allow(dead_code)] -#[rustversion::attr(stable(1.40.0), cfg_attr(not(feature = "web_test"), test))] +#[rustversion::attr(stable(1.40.0), test)] fn tests() { let t = trybuild::TestCases::new(); t.pass("tests/derive_props/pass.rs"); diff --git a/tests/macro/html-block-fail.rs b/crates/macro/tests/macro/html-block-fail.rs similarity index 100% rename from tests/macro/html-block-fail.rs rename to crates/macro/tests/macro/html-block-fail.rs diff --git a/tests/macro/html-block-fail.stderr b/crates/macro/tests/macro/html-block-fail.stderr similarity index 100% rename from tests/macro/html-block-fail.stderr rename to crates/macro/tests/macro/html-block-fail.stderr diff --git a/tests/macro/html-block-pass.rs b/crates/macro/tests/macro/html-block-pass.rs similarity index 100% rename from tests/macro/html-block-pass.rs rename to crates/macro/tests/macro/html-block-pass.rs diff --git a/tests/macro/html-component-fail-unimplemented.rs b/crates/macro/tests/macro/html-component-fail-unimplemented.rs similarity index 100% rename from tests/macro/html-component-fail-unimplemented.rs rename to crates/macro/tests/macro/html-component-fail-unimplemented.rs diff --git a/tests/macro/html-component-fail-unimplemented.stderr b/crates/macro/tests/macro/html-component-fail-unimplemented.stderr similarity index 100% rename from tests/macro/html-component-fail-unimplemented.stderr rename to crates/macro/tests/macro/html-component-fail-unimplemented.stderr diff --git a/tests/macro/html-component-fail.rs b/crates/macro/tests/macro/html-component-fail.rs similarity index 100% rename from tests/macro/html-component-fail.rs rename to crates/macro/tests/macro/html-component-fail.rs diff --git a/tests/macro/html-component-fail.stderr b/crates/macro/tests/macro/html-component-fail.stderr similarity index 93% rename from tests/macro/html-component-fail.stderr rename to crates/macro/tests/macro/html-component-fail.stderr index 11fbdc5a112..cfd9c2bd9d1 100644 --- a/tests/macro/html-component-fail.stderr +++ b/crates/macro/tests/macro/html-component-fail.stderr @@ -188,6 +188,10 @@ error[E0599]: no method named `string` found for type `ChildPropertiesBuilder }; | ^^^^^^ method not found in `ChildPropertiesBuilder` + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `string`, perhaps you need to implement it: + candidate #1: `proc_macro::bridge::server::Literal` error[E0599]: no method named `children` found for type `ChildPropertiesBuilder` in the current scope --> $DIR/html-component-fail.rs:76:5 @@ -209,6 +213,9 @@ error[E0599]: no method named `build` found for type `ChildContainerPropertiesBu 78 | html! { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `ChildContainerPropertiesBuilder` | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `build`, perhaps you need to implement it: + candidate #1: `proc_macro::bridge::server::TokenStreamBuilder` = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error[E0599]: no method named `build` found for type `ChildContainerPropertiesBuilder` in the current scope @@ -220,6 +227,9 @@ error[E0599]: no method named `build` found for type `ChildContainerPropertiesBu 79 | html! { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `ChildContainerPropertiesBuilder` | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `build`, perhaps you need to implement it: + candidate #1: `proc_macro::bridge::server::TokenStreamBuilder` = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error[E0277]: the trait bound `yew::virtual_dom::vcomp::VChild: std::convert::From<&str>` is not satisfied diff --git a/tests/macro/html-component-pass.rs b/crates/macro/tests/macro/html-component-pass.rs similarity index 100% rename from tests/macro/html-component-pass.rs rename to crates/macro/tests/macro/html-component-pass.rs diff --git a/tests/macro/html-iterable-fail.rs b/crates/macro/tests/macro/html-iterable-fail.rs similarity index 100% rename from tests/macro/html-iterable-fail.rs rename to crates/macro/tests/macro/html-iterable-fail.rs diff --git a/tests/macro/html-iterable-fail.stderr b/crates/macro/tests/macro/html-iterable-fail.stderr similarity index 100% rename from tests/macro/html-iterable-fail.stderr rename to crates/macro/tests/macro/html-iterable-fail.stderr diff --git a/tests/macro/html-iterable-pass.rs b/crates/macro/tests/macro/html-iterable-pass.rs similarity index 100% rename from tests/macro/html-iterable-pass.rs rename to crates/macro/tests/macro/html-iterable-pass.rs diff --git a/tests/macro/html-list-fail.rs b/crates/macro/tests/macro/html-list-fail.rs similarity index 100% rename from tests/macro/html-list-fail.rs rename to crates/macro/tests/macro/html-list-fail.rs diff --git a/tests/macro/html-list-fail.stderr b/crates/macro/tests/macro/html-list-fail.stderr similarity index 100% rename from tests/macro/html-list-fail.stderr rename to crates/macro/tests/macro/html-list-fail.stderr diff --git a/tests/macro/html-list-pass.rs b/crates/macro/tests/macro/html-list-pass.rs similarity index 100% rename from tests/macro/html-list-pass.rs rename to crates/macro/tests/macro/html-list-pass.rs diff --git a/tests/macro/html-node-fail.rs b/crates/macro/tests/macro/html-node-fail.rs similarity index 100% rename from tests/macro/html-node-fail.rs rename to crates/macro/tests/macro/html-node-fail.rs diff --git a/tests/macro/html-node-fail.stderr b/crates/macro/tests/macro/html-node-fail.stderr similarity index 100% rename from tests/macro/html-node-fail.stderr rename to crates/macro/tests/macro/html-node-fail.stderr diff --git a/tests/macro/html-node-pass.rs b/crates/macro/tests/macro/html-node-pass.rs similarity index 100% rename from tests/macro/html-node-pass.rs rename to crates/macro/tests/macro/html-node-pass.rs diff --git a/tests/macro/html-tag-fail.rs b/crates/macro/tests/macro/html-tag-fail.rs similarity index 100% rename from tests/macro/html-tag-fail.rs rename to crates/macro/tests/macro/html-tag-fail.rs diff --git a/tests/macro/html-tag-fail.stderr b/crates/macro/tests/macro/html-tag-fail.stderr similarity index 100% rename from tests/macro/html-tag-fail.stderr rename to crates/macro/tests/macro/html-tag-fail.stderr diff --git a/tests/macro/html-tag-pass.rs b/crates/macro/tests/macro/html-tag-pass.rs similarity index 100% rename from tests/macro/html-tag-pass.rs rename to crates/macro/tests/macro/html-tag-pass.rs diff --git a/tests/macro/test_component.rs b/crates/macro/tests/macro/test_component.rs similarity index 100% rename from tests/macro/test_component.rs rename to crates/macro/tests/macro/test_component.rs diff --git a/tests/macro_test.rs b/crates/macro/tests/macro_test.rs similarity index 90% rename from tests/macro_test.rs rename to crates/macro/tests/macro_test.rs index de35457c04e..1dc131b3124 100644 --- a/tests/macro_test.rs +++ b/crates/macro/tests/macro_test.rs @@ -1,5 +1,5 @@ #[allow(dead_code)] -#[rustversion::attr(stable(1.40.0), cfg_attr(not(feature = "web_test"), test))] +#[rustversion::attr(stable(1.40.0), test)] fn tests() { let t = trybuild::TestCases::new(); diff --git a/src/format/macros.rs b/src/format/macros.rs index f782dfa4fa4..ab7116cfa39 100644 --- a/src/format/macros.rs +++ b/src/format/macros.rs @@ -53,6 +53,7 @@ macro_rules! binary_format { }; } +#[cfg(any(feature = "bincode", feature = "cbor", feature = "msgpack"))] macro_rules! text_format_is_an_error { ($type:ident) => { use $crate::format::FormatError; diff --git a/tests/vtag_test.rs b/tests/vtag_test.rs index 94c6b687cb2..8b5daf35ce2 100644 --- a/tests/vtag_test.rs +++ b/tests/vtag_test.rs @@ -1,4 +1,6 @@ #![recursion_limit = "128"] + +#[cfg(feature = "std_web")] use stdweb::web::{document, IElement}; #[cfg(feature = "wasm_test")] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; @@ -270,8 +272,16 @@ fn assert_namespace(vtag: &VTag, namespace: &'static str) { #[test] fn supports_svg() { - let div_el = document().create_element("div").unwrap(); - let svg_el = document().create_element_ns(SVG_NAMESPACE, "svg").unwrap(); + #[cfg(feature = "std_web")] + let document = document(); + #[cfg(feature = "web_sys")] + let document = web_sys::window().unwrap().document().unwrap(); + + let div_el = document.create_element("div").unwrap(); + let namespace = SVG_NAMESPACE; + #[cfg(feature = "web_sys")] + let namespace = Some(namespace); + let svg_el = document.create_element_ns(namespace, "svg").unwrap(); let mut g_node = html! { }; let path_node = html! { };