diff --git a/.travis.yml b/.travis.yml index d0e0544..bdbaca4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ addons: rust: - nightly -- beta - stable install: @@ -24,15 +23,21 @@ before_script: - cargo clean script: - # Test examples in README. - - cargo build --tests && rustdoc --test README.md -L target/debug/deps + # Build without unstable flag + - cargo build + + # Test examples in README. + - rustdoc --test README.md -L target/debug -L target/debug/deps + + # Check with unstable flag + - cargo check --features unstable # Run tests, uploading results to codecov.. # hpack tests are _super_ slow in coverage, so skip them here. - - cargo tarpaulin --out Xml -- --skip hpack + - cargo tarpaulin --features unstable --out Xml -- --skip hpack # Test _only_ hpack. - - cargo test -- hpack + - cargo test --lib -- hpack after_success: - bash <(curl -Ls https://codecov.io/bash) diff --git a/Cargo.toml b/Cargo.toml index ec99924..c9120fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,14 +36,7 @@ string = { git = "https://github.com/carllerche/string" } ordermap = "0.2" [dev-dependencies] - -# Support code for tests. Ideally this wouldn't be released to crates.io, but -# until rust-lang/cargo#4466 is resolved, we just have to publish this junk crate. -# -# The dependency is set on a fixed version as the `h2-test-support` offers no -# guarantees of backwards compatibility across minor versions. The version of -# `h2-test-support` should always match the current version of `h2`. -h2-test-support = { version = "= 0.1.0", path = "tests/support" } +mock-io = { git = "https://github.com/carllerche/mock-io", branch = "experiments" } # Fuzzing quickcheck = "0.4.1" diff --git a/tests/client_request.rs b/tests/client_request.rs index 25a5290..2f3bffe 100644 --- a/tests/client_request.rs +++ b/tests/client_request.rs @@ -1,8 +1,8 @@ #[macro_use] extern crate log; -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; #[test] fn handshake() { diff --git a/tests/codec_read.rs b/tests/codec_read.rs index c69ee5c..5aebced 100644 --- a/tests/codec_read.rs +++ b/tests/codec_read.rs @@ -1,6 +1,6 @@ #[macro_use] -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; use std::error::Error; diff --git a/tests/flow_control.rs b/tests/flow_control.rs index 5a0b25f..6c7ec83 100644 --- a/tests/flow_control.rs +++ b/tests/flow_control.rs @@ -1,6 +1,6 @@ #[macro_use] -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; // In this case, the stream & connection both have capacity, but capacity is not // explicitly requested. diff --git a/tests/ping_pong.rs b/tests/ping_pong.rs index f15dd17..9436f6c 100644 --- a/tests/ping_pong.rs +++ b/tests/ping_pong.rs @@ -1,6 +1,6 @@ #[macro_use] -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; #[test] fn recv_single_ping() { diff --git a/tests/prioritization.rs b/tests/prioritization.rs index 1e5c66c..761484f 100644 --- a/tests/prioritization.rs +++ b/tests/prioritization.rs @@ -1,6 +1,6 @@ #[macro_use] -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; #[test] fn single_stream_send_large_body() { diff --git a/tests/push_promise.rs b/tests/push_promise.rs index 526baf6..2d6d1d5 100644 --- a/tests/push_promise.rs +++ b/tests/push_promise.rs @@ -1,5 +1,5 @@ -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; #[test] fn recv_push_works() { diff --git a/tests/server.rs b/tests/server.rs index ce2c9e2..f7181e3 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1,5 +1,5 @@ -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; const SETTINGS: &'static [u8] = &[0, 0, 0, 4, 0, 0, 0, 0, 0]; const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0]; diff --git a/tests/stream_states.rs b/tests/stream_states.rs index b00b5b8..e62bfcd 100644 --- a/tests/stream_states.rs +++ b/tests/stream_states.rs @@ -1,8 +1,8 @@ #[macro_use] extern crate log; -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; #[test] fn send_recv_headers_only() { diff --git a/tests/support/Cargo.toml b/tests/support/Cargo.toml deleted file mode 100644 index 82d5fcb..0000000 --- a/tests/support/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "h2-test-support" -version = "0.1.0" -authors = ["Carl Lerche "] - -[dependencies] -futures = "0.1" -tokio-io = "0.1" -bytes = "0.4" -http = { git = "https://github.com/carllerche/http" } -env_logger = "0.4" - -mock-io = { git = "https://github.com/carllerche/mock-io", branch = "experiments" } - -[dependencies.h2] -path = "../.." -features = ["unstable"] diff --git a/tests/support/README.md b/tests/support/README.md deleted file mode 100644 index 811e449..0000000 --- a/tests/support/README.md +++ /dev/null @@ -1,3 +0,0 @@ -**This is not a real crate** - -You should not use this crate, it only exists to work around cargo limitations. diff --git a/tests/support/src/assert.rs b/tests/support/assert.rs similarity index 100% rename from tests/support/src/assert.rs rename to tests/support/assert.rs diff --git a/tests/support/src/frames.rs b/tests/support/frames.rs similarity index 100% rename from tests/support/src/frames.rs rename to tests/support/frames.rs diff --git a/tests/support/src/future_ext.rs b/tests/support/future_ext.rs similarity index 100% rename from tests/support/src/future_ext.rs rename to tests/support/future_ext.rs diff --git a/tests/support/src/mock.rs b/tests/support/mock.rs similarity index 100% rename from tests/support/src/mock.rs rename to tests/support/mock.rs diff --git a/tests/support/mod.rs b/tests/support/mod.rs new file mode 100644 index 0000000..8353070 --- /dev/null +++ b/tests/support/mod.rs @@ -0,0 +1,58 @@ +//! Utilities to support tests. + +pub extern crate bytes; +pub extern crate env_logger; +pub extern crate futures; +pub extern crate h2; +pub extern crate http; +pub extern crate mock_io; +pub extern crate tokio_io; + +// Kind of annoying, but we can't use macros from crates that aren't specified +// at the root. +macro_rules! try_ready { + ($e:expr) => ({ + use $crate::support::futures::Async; + match $e { + Ok(Async::Ready(t)) => t, + Ok(Async::NotReady) => return Ok(Async::NotReady), + Err(e) => return Err(From::from(e)), + } + }) +} + +macro_rules! try_nb { + ($e:expr) => ({ + use $crate::support::futures::Async; + use ::std::io::ErrorKind::WouldBlock; + + match $e { + Ok(t) => t, + Err(ref e) if e.kind() == WouldBlock => { + return Ok(Async::NotReady) + } + Err(e) => return Err(e.into()), + } + }) +} + +#[macro_use] +mod assert; + +#[macro_use] +pub mod raw; + +pub mod frames; +pub mod prelude; +pub mod mock; +pub mod util; + +mod future_ext; + +pub use self::future_ext::{FutureExt, Unwrap}; + +// This is our test Codec type +pub type Codec = h2::Codec>; + +// This is the frame type that is sent +pub type SendFrame = h2::frame::Frame<::std::io::Cursor<::bytes::Bytes>>; diff --git a/tests/support/src/prelude.rs b/tests/support/prelude.rs similarity index 97% rename from tests/support/src/prelude.rs rename to tests/support/prelude.rs index 57ab475..92821ca 100644 --- a/tests/support/src/prelude.rs +++ b/tests/support/prelude.rs @@ -26,7 +26,7 @@ pub use super::{bytes, env_logger, futures, http, mock_io, tokio_io}; pub use self::futures::{Future, Sink, Stream}; // And our Future extensions -pub use future_ext::{FutureExt, Unwrap}; +pub use super::future_ext::{FutureExt, Unwrap}; // Re-export HTTP types pub use self::http::{HeaderMap, Method, Request, Response, StatusCode}; diff --git a/tests/support/src/raw.rs b/tests/support/raw.rs similarity index 81% rename from tests/support/src/raw.rs rename to tests/support/raw.rs index fbaa109..31dece6 100644 --- a/tests/support/src/raw.rs +++ b/tests/support/raw.rs @@ -7,19 +7,19 @@ macro_rules! raw_codec { $fn:ident => [$($chunk:expr,)+]; )* ) => {{ - let mut b = $crate::mock_io::Builder::new(); + let mut b = $crate::support::mock_io::Builder::new(); $({ let mut chunk = vec![]; $( - $crate::raw::Chunk::push(&$chunk, &mut chunk); + $crate::support::raw::Chunk::push(&$chunk, &mut chunk); )+ b.$fn(&chunk[..]); })* - $crate::Codec::new(b.build()) + $crate::support::Codec::new(b.build()) }} } diff --git a/tests/support/src/lib.rs b/tests/support/src/lib.rs deleted file mode 100644 index be80b42..0000000 --- a/tests/support/src/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! Utilities to support tests. - -pub extern crate bytes; -pub extern crate h2; -pub extern crate http; - -#[macro_use] -pub extern crate tokio_io; - -pub extern crate env_logger; -#[macro_use] -pub extern crate futures; -pub extern crate mock_io; - -#[macro_use] -mod assert; - -#[macro_use] -pub mod raw; - -pub mod frames; -pub mod prelude; -pub mod mock; -pub mod util; - -mod future_ext; - -pub use future_ext::{FutureExt, Unwrap}; - -// This is our test Codec type -pub type Codec = h2::Codec>; - -// This is the frame type that is sent -pub type SendFrame = h2::frame::Frame<::std::io::Cursor<::bytes::Bytes>>; diff --git a/tests/support/src/util.rs b/tests/support/util.rs similarity index 100% rename from tests/support/src/util.rs rename to tests/support/util.rs diff --git a/tests/trailers.rs b/tests/trailers.rs index 223e47c..237d0b8 100644 --- a/tests/trailers.rs +++ b/tests/trailers.rs @@ -1,8 +1,8 @@ #[macro_use] extern crate log; -extern crate h2_test_support; -use h2_test_support::prelude::*; +pub mod support; +use support::prelude::*; #[test] fn recv_trailers_only() {