Use main and test proc macro from ntex-macros

This commit is contained in:
Nikolay Kim 2021-02-24 13:25:22 +06:00
parent 0d9be13180
commit 819f5b2eaf
63 changed files with 297 additions and 414 deletions

View file

@ -4,7 +4,6 @@ members = [
"ntex-codec", "ntex-codec",
"ntex-router", "ntex-router",
"ntex-rt", "ntex-rt",
"ntex-rt-macros",
"ntex-service", "ntex-service",
"ntex-macros", "ntex-macros",
] ]
@ -15,5 +14,4 @@ ntex-codec = { path = "ntex-codec" }
ntex-router = { path = "ntex-router" } ntex-router = { path = "ntex-router" }
ntex-rt = { path = "ntex-rt" } ntex-rt = { path = "ntex-rt" }
ntex-service = { path = "ntex-service" } ntex-service = { path = "ntex-service" }
# ntex-macros = { path = "ntex-macros" } ntex-macros = { path = "ntex-macros" }
# ntex-rt-macros = { path = "ntex-rt-macros" }

View file

@ -1,5 +1,9 @@
# Changes # Changes
## [0.1.1] - 2021-02-25
* Move `main` and `test` macros from rt macros
## [0.1.0] - 2020-04-10 ## [0.1.0] - 2020-04-10
* Fork to ntex namespace * Fork to ntex namespace

View file

@ -16,5 +16,5 @@ syn = { version = "^1", features = ["full", "parsing"] }
proc-macro2 = "^1" proc-macro2 = "^1"
[dev-dependencies] [dev-dependencies]
ntex = "0.1.6" ntex = "0.3.1"
futures = "0.3.4" futures = "0.3.13"

View file

@ -1,5 +1,4 @@
#![recursion_limit = "512"] //! ntex macros module
//! web macros module
//! //!
//! Generators for routes //! Generators for routes
//! //!
@ -45,6 +44,7 @@ extern crate proc_macro;
mod route; mod route;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::quote;
use syn::parse_macro_input; use syn::parse_macro_input;
/// Creates route handler with `GET` method guard. /// Creates route handler with `GET` method guard.
@ -185,3 +185,97 @@ pub fn web_patch(args: TokenStream, input: TokenStream) -> TokenStream {
}; };
gen.generate() gen.generate()
} }
/// Marks async function to be executed by ntex system.
///
/// ## Usage
///
/// ```rust
/// #[ntex::main]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
#[proc_macro_attribute]
pub fn rt_main(_: TokenStream, item: TokenStream) -> TokenStream {
let mut input = syn::parse_macro_input!(item as syn::ItemFn);
let attrs = &input.attrs;
let vis = &input.vis;
let sig = &mut input.sig;
let body = &input.block;
let name = &sig.ident;
if sig.asyncness.is_none() {
return syn::Error::new_spanned(sig.fn_token, "only async fn is supported")
.to_compile_error()
.into();
}
sig.asyncness = None;
(quote! {
#(#attrs)*
#vis #sig {
ntex_rt::System::new(stringify!(#name))
.block_on(async move { #body })
}
})
.into()
}
/// Marks async test function to be executed by ntex runtime.
///
/// ## Usage
///
/// ```no_run
/// #[ntex::test]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
#[proc_macro_attribute]
pub fn rt_test(_: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
let ret = &input.sig.output;
let name = &input.sig.ident;
let body = &input.block;
let attrs = &input.attrs;
let mut has_test_attr = false;
for attr in attrs {
if attr.path.is_ident("test") {
has_test_attr = true;
}
}
if input.sig.asyncness.is_none() {
return syn::Error::new_spanned(
input.sig.fn_token,
format!("only async fn is supported, {}", input.sig.ident),
)
.to_compile_error()
.into();
}
let result = if has_test_attr {
quote! {
#(#attrs)*
fn #name() #ret {
ntex_rt::System::new("test")
.block_on(async { #body })
}
}
} else {
quote! {
#[test]
#(#attrs)*
fn #name() #ret {
ntex_rt::System::new("test")
.block_on(async { #body })
}
}
};
result.into()
}

View file

@ -1,20 +0,0 @@
[package]
name = "ntex-rt-macros"
version = "0.1.1"
authors = ["ntex contributors <team@ntex.rs>"]
description = "ntex runtime macros"
repository = "https://github.com/ntex-rs/ntex"
documentation = "https://docs.rs/ntex-rt-macros/"
categories = ["network-programming", "asynchronous"]
license = "MIT"
edition = "2018"
[lib]
proc-macro = true
[dependencies]
quote = "^1"
syn = { version = "^1", features = ["full"] }
[dev-dependencies]
ntex = { version = "0.3.0-b.1" }

View file

@ -1 +0,0 @@
../LICENSE

View file

@ -1,197 +0,0 @@
//! Macros for use with Tokio
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
/// Marks async function to be executed by ntex system.
///
/// ## Usage
///
/// ```rust
/// #[ntex::main]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
#[proc_macro_attribute]
#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
let mut input = syn::parse_macro_input!(item as syn::ItemFn);
let attrs = &input.attrs;
let vis = &input.vis;
let sig = &mut input.sig;
let body = &input.block;
let name = &sig.ident;
if sig.asyncness.is_none() {
return syn::Error::new_spanned(sig.fn_token, "only async fn is supported")
.to_compile_error()
.into();
}
sig.asyncness = None;
(quote! {
#(#attrs)*
#vis #sig {
ntex::rt::System::new(stringify!(#name))
.block_on(async move { #body })
}
})
.into()
}
/// Marks async test function to be executed by ntex runtime.
///
/// ## Usage
///
/// ```no_run
/// #[ntex::test]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
#[proc_macro_attribute]
pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
let ret = &input.sig.output;
let name = &input.sig.ident;
let body = &input.block;
let attrs = &input.attrs;
let mut has_test_attr = false;
for attr in attrs {
if attr.path.is_ident("test") {
has_test_attr = true;
}
}
if input.sig.asyncness.is_none() {
return syn::Error::new_spanned(
input.sig.fn_token,
format!("only async fn is supported, {}", input.sig.ident),
)
.to_compile_error()
.into();
}
let result = if has_test_attr {
quote! {
#(#attrs)*
fn #name() #ret {
ntex::rt::System::new("test")
.block_on(async { #body })
}
}
} else {
quote! {
#[test]
#(#attrs)*
fn #name() #ret {
ntex::rt::System::new("test")
.block_on(async { #body })
}
}
};
result.into()
}
/// Marks async function to be executed by ntex system.
///
/// ## Usage
///
/// ```rust
/// #[ntex::main]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
#[doc(hidden)]
#[proc_macro_attribute]
#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub fn rt_main(_: TokenStream, item: TokenStream) -> TokenStream {
let mut input = syn::parse_macro_input!(item as syn::ItemFn);
let attrs = &input.attrs;
let vis = &input.vis;
let sig = &mut input.sig;
let body = &input.block;
let name = &sig.ident;
if sig.asyncness.is_none() {
return syn::Error::new_spanned(sig.fn_token, "only async fn is supported")
.to_compile_error()
.into();
}
sig.asyncness = None;
(quote! {
#(#attrs)*
#vis #sig {
ntex_rt::System::new(stringify!(#name))
.block_on(async move { #body })
}
})
.into()
}
/// Marks async test function to be executed by ntex runtime.
///
/// ## Usage
///
/// ```no_run
/// #[ntex::test]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
#[doc(hidden)]
#[proc_macro_attribute]
pub fn rt_test(_: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
let ret = &input.sig.output;
let name = &input.sig.ident;
let body = &input.block;
let attrs = &input.attrs;
let mut has_test_attr = false;
for attr in attrs {
if attr.path.is_ident("test") {
has_test_attr = true;
}
}
if input.sig.asyncness.is_none() {
return syn::Error::new_spanned(
input.sig.fn_token,
format!("only async fn is supported, {}", input.sig.ident),
)
.to_compile_error()
.into();
}
let result = if has_test_attr {
quote! {
#(#attrs)*
fn #name() #ret {
ntex_rt::System::new("test")
.block_on(async { #body })
}
}
} else {
quote! {
#[test]
#(#attrs)*
fn #name() #ret {
ntex_rt::System::new("test")
.block_on(async { #body })
}
}
};
result.into()
}

View file

@ -1,5 +1,9 @@
# Changes # Changes
## [0.2.1] - 2021-02-25
* Drop macros
## [0.2.0] - 2021-02-23 ## [0.2.0] - 2021-02-23
* Migrate to tokio 1.x * Migrate to tokio 1.x

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ntex-rt" name = "ntex-rt"
version = "0.2.0" version = "0.2.1"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]
description = "ntex runtime" description = "ntex runtime"
keywords = ["network", "framework", "async", "futures"] keywords = ["network", "framework", "async", "futures"]
@ -16,6 +16,5 @@ name = "ntex_rt"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
ntex-rt-macros = "0.1.1"
futures = "0.3.13" futures = "0.3.13"
tokio = { version = "1", default-features=false, features = ["rt", "net", "time", "signal"] } tokio = { version = "1", default-features=false, features = ["rt", "net", "time", "signal"] }

View file

@ -11,9 +11,6 @@ pub use self::builder::{Builder, SystemRunner};
pub use self::runtime::Runtime; pub use self::runtime::Runtime;
pub use self::system::System; pub use self::system::System;
#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub use ntex_rt_macros::{rt_main as main, rt_test as test};
/// Spawn a future on the current thread. This does not create a new Arbiter /// Spawn a future on the current thread. This does not create a new Arbiter
/// or Arbiter address, it is simply a helper for spawning futures on the current /// or Arbiter address, it is simply a helper for spawning futures on the current
/// thread. /// thread.

View file

@ -4,6 +4,8 @@
* Re-export various types * Re-export various types
* Use `main` and `test` proc macro from ntex-macros
## [0.3.1] - 2021-02-24 ## [0.3.1] - 2021-02-24
* server: Make TestServer::connect() async * server: Make TestServer::connect() async

View file

@ -37,11 +37,10 @@ cookie = ["coo-kie", "coo-kie/percent-encode"]
[dependencies] [dependencies]
ntex-codec = "0.4.0" ntex-codec = "0.4.0"
ntex-rt = "0.2.0" ntex-rt = "0.2.1"
ntex-rt-macros = "0.1.1"
ntex-router = "0.4.0" ntex-router = "0.4.0"
ntex-service = "0.1.5" ntex-service = "0.1.5"
ntex-macros = "0.1" ntex-macros = "0.1.1"
base64 = "0.13" base64 = "0.13"
bitflags = "1.2.1" bitflags = "1.2.1"

View file

@ -102,7 +102,7 @@ mod tests {
use super::*; use super::*;
use futures::future::lazy; use futures::future::lazy;
#[ntex_rt::test] #[crate::rt_test]
#[allow(clippy::unit_cmp)] #[allow(clippy::unit_cmp)]
async fn test_condition() { async fn test_condition() {
let cond = Condition::new(); let cond = Condition::new();
@ -130,7 +130,7 @@ mod tests {
assert_eq!(waiter2.await, ()); assert_eq!(waiter2.await, ());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_condition_poll() { async fn test_condition_poll() {
let cond = Condition::new(); let cond = Condition::new();
let waiter = cond.wait(); let waiter = cond.wait();

View file

@ -236,7 +236,7 @@ mod tests {
use futures::future::lazy; use futures::future::lazy;
use futures::{Sink, Stream, StreamExt}; use futures::{Sink, Stream, StreamExt};
#[ntex_rt::test] #[crate::rt_test]
async fn test_mpsc() { async fn test_mpsc() {
let (tx, mut rx) = channel(); let (tx, mut rx) = channel();
assert!(format!("{:?}", tx).contains("Sender")); assert!(format!("{:?}", tx).contains("Sender"));
@ -285,7 +285,7 @@ mod tests {
assert_eq!(err.into_inner(), "test"); assert_eq!(err.into_inner(), "test");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_sink() { async fn test_sink() {
let (mut tx, mut rx) = channel(); let (mut tx, mut rx) = channel();
lazy(|cx| { lazy(|cx| {
@ -299,7 +299,7 @@ mod tests {
assert_eq!(rx.next().await, None); assert_eq!(rx.next().await, None);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_close() { async fn test_close() {
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
assert!(!tx.is_closed()); assert!(!tx.is_closed());

View file

@ -107,7 +107,7 @@ mod tests {
use super::*; use super::*;
use futures::future::lazy; use futures::future::lazy;
#[ntex_rt::test] #[crate::rt_test]
async fn test_oneshot() { async fn test_oneshot() {
let (tx, rx) = channel(); let (tx, rx) = channel();
tx.send("test").unwrap(); tx.send("test").unwrap();

View file

@ -181,7 +181,7 @@ mod tests {
use super::*; use super::*;
use futures::future::lazy; use futures::future::lazy;
#[ntex_rt::test] #[crate::rt_test]
async fn test_pool() { async fn test_pool() {
let p = new(); let p = new();
let (tx, rx) = p.channel(); let (tx, rx) = p.channel();

View file

@ -119,7 +119,7 @@ mod tests {
use super::*; use super::*;
use crate::service::{Service, ServiceFactory}; use crate::service::{Service, ServiceFactory};
#[ntex_rt::test] #[crate::rt_test]
async fn test_openssl_connect() { async fn test_openssl_connect() {
let server = crate::server::test_server(|| { let server = crate::server::test_server(|| {
crate::fn_service(|_| async { Ok::<_, ()>(()) }) crate::fn_service(|_| async { Ok::<_, ()>(()) })

View file

@ -141,7 +141,7 @@ mod tests {
use super::*; use super::*;
#[ntex_rt::test] #[crate::rt_test]
async fn resolver() { async fn resolver() {
let resolver = Resolver::new(DnsResolver::tokio_from_system_conf().unwrap()); let resolver = Resolver::new(DnsResolver::tokio_from_system_conf().unwrap());
assert!(format!("{:?}", resolver).contains("Resolver")); assert!(format!("{:?}", resolver).contains("Resolver"));

View file

@ -116,7 +116,7 @@ mod tests {
use super::*; use super::*;
use crate::service::{Service, ServiceFactory}; use crate::service::{Service, ServiceFactory};
#[ntex_rt::test] #[crate::rt_test]
async fn test_rustls_connect() { async fn test_rustls_connect() {
let server = crate::server::test_server(|| { let server = crate::server::test_server(|| {
crate::fn_service(|_| async { Ok::<_, ()>(()) }) crate::fn_service(|_| async { Ok::<_, ()>(()) })

View file

@ -217,7 +217,7 @@ impl<T: Address> Future for TcpConnectorResponse<T> {
mod tests { mod tests {
use super::*; use super::*;
#[ntex_rt::test] #[crate::rt_test]
async fn test_connect() { async fn test_connect() {
let server = crate::server::test_server(|| { let server = crate::server::test_server(|| {
crate::fn_service(|_| async { Ok::<_, ()>(()) }) crate::fn_service(|_| async { Ok::<_, ()>(()) })

View file

@ -540,7 +540,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_basic() { async fn test_basic() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(1024); client.remote_buffer_cap(1024);
@ -567,7 +567,7 @@ mod tests {
assert!(client.is_server_dropped()); assert!(client.is_server_dropped());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_sink() { async fn test_sink() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(1024); client.remote_buffer_cap(1024);
@ -600,7 +600,7 @@ mod tests {
assert!(client.is_server_dropped()); assert!(client.is_server_dropped());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_err_in_service() { async fn test_err_in_service() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(0); client.remote_buffer_cap(0);
@ -639,7 +639,7 @@ mod tests {
assert!(client.is_server_dropped()); assert!(client.is_server_dropped());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_write_backpressure() { async fn test_write_backpressure() {
let (client, server) = Io::create(); let (client, server) = Io::create();
// do not allow to write to socket // do not allow to write to socket
@ -704,7 +704,7 @@ mod tests {
assert_eq!(&data.lock().unwrap().borrow()[..], &[0, 1, 2]); assert_eq!(&data.lock().unwrap().borrow()[..], &[0, 1, 2]);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_keepalive() { async fn test_keepalive() {
let (client, server) = Io::create(); let (client, server) = Io::create();
// do not allow to write to socket // do not allow to write to socket

View file

@ -634,7 +634,7 @@ mod tests {
const BIN: &[u8] = b"GET /test HTTP/1\r\n\r\n"; const BIN: &[u8] = b"GET /test HTTP/1\r\n\r\n";
const TEXT: &str = "GET /test HTTP/1\r\n\r\n"; const TEXT: &str = "GET /test HTTP/1\r\n\r\n";
#[ntex_rt::test] #[crate::rt_test]
async fn test_utils() { async fn test_utils() {
let (client, mut server) = Io::create(); let (client, mut server) = Io::create();
client.remote_buffer_cap(1024); client.remote_buffer_cap(1024);

View file

@ -538,7 +538,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_static_str() { async fn test_static_str() {
assert_eq!(Body::from("").size(), BodySize::Sized(0)); assert_eq!(Body::from("").size(), BodySize::Sized(0));
assert_eq!(Body::from("test").size(), BodySize::Sized(4)); assert_eq!(Body::from("test").size(), BodySize::Sized(4));
@ -556,7 +556,7 @@ mod tests {
assert!(poll_fn(|cx| "".poll_next_chunk(cx)).await.is_none()); assert!(poll_fn(|cx| "".poll_next_chunk(cx)).await.is_none());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_static_bytes() { async fn test_static_bytes() {
assert_eq!(Body::from(b"test".as_ref()).size(), BodySize::Sized(4)); assert_eq!(Body::from(b"test".as_ref()).size(), BodySize::Sized(4));
assert_eq!(Body::from(b"test".as_ref()).get_ref(), b"test"); assert_eq!(Body::from(b"test".as_ref()).get_ref(), b"test");
@ -578,7 +578,7 @@ mod tests {
assert!(poll_fn(|cx| (&b""[..]).poll_next_chunk(cx)).await.is_none()); assert!(poll_fn(|cx| (&b""[..]).poll_next_chunk(cx)).await.is_none());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_vec() { async fn test_vec() {
assert_eq!(Body::from(Vec::from("test")).size(), BodySize::Sized(4)); assert_eq!(Body::from(Vec::from("test")).size(), BodySize::Sized(4));
assert_eq!(Body::from(Vec::from("test")).get_ref(), b"test"); assert_eq!(Body::from(Vec::from("test")).get_ref(), b"test");
@ -603,7 +603,7 @@ mod tests {
.is_none()); .is_none());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_bytes() { async fn test_bytes() {
let mut b = Bytes::from("test"); let mut b = Bytes::from("test");
assert_eq!(Body::from(b.clone()).size(), BodySize::Sized(4)); assert_eq!(Body::from(b.clone()).size(), BodySize::Sized(4));
@ -617,7 +617,7 @@ mod tests {
assert!(poll_fn(|cx| b.poll_next_chunk(cx)).await.is_none(),); assert!(poll_fn(|cx| b.poll_next_chunk(cx)).await.is_none(),);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_bytes_mut() { async fn test_bytes_mut() {
let mut b = BytesMut::from("test"); let mut b = BytesMut::from("test");
assert_eq!(Body::from(b.clone()).size(), BodySize::Sized(4)); assert_eq!(Body::from(b.clone()).size(), BodySize::Sized(4));
@ -631,7 +631,7 @@ mod tests {
assert!(poll_fn(|cx| b.poll_next_chunk(cx)).await.is_none(),); assert!(poll_fn(|cx| b.poll_next_chunk(cx)).await.is_none(),);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_string() { async fn test_string() {
let mut b = "test".to_owned(); let mut b = "test".to_owned();
assert_eq!(Body::from(b.clone()).size(), BodySize::Sized(4)); assert_eq!(Body::from(b.clone()).size(), BodySize::Sized(4));
@ -647,20 +647,20 @@ mod tests {
assert!(poll_fn(|cx| b.poll_next_chunk(cx)).await.is_none(),); assert!(poll_fn(|cx| b.poll_next_chunk(cx)).await.is_none(),);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_unit() { async fn test_unit() {
assert_eq!(().size(), BodySize::Empty); assert_eq!(().size(), BodySize::Empty);
assert!(poll_fn(|cx| ().poll_next_chunk(cx)).await.is_none()); assert!(poll_fn(|cx| ().poll_next_chunk(cx)).await.is_none());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_box() { async fn test_box() {
let mut val = Box::new(()); let mut val = Box::new(());
assert_eq!(val.size(), BodySize::Empty); assert_eq!(val.size(), BodySize::Empty);
assert!(poll_fn(|cx| val.poll_next_chunk(cx)).await.is_none()); assert!(poll_fn(|cx| val.poll_next_chunk(cx)).await.is_none());
} }
#[ntex_rt::test] #[crate::rt_test]
#[allow(clippy::eq_op)] #[allow(clippy::eq_op)]
async fn test_body_eq() { async fn test_body_eq() {
assert!(Body::None == Body::None); assert!(Body::None == Body::None);
@ -674,14 +674,14 @@ mod tests {
assert!(Body::Bytes(Bytes::from_static(b"1")) != Body::None); assert!(Body::Bytes(Bytes::from_static(b"1")) != Body::None);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_body_debug() { async fn test_body_debug() {
assert!(format!("{:?}", Body::None).contains("Body::None")); assert!(format!("{:?}", Body::None).contains("Body::None"));
assert!(format!("{:?}", Body::Empty).contains("Body::Empty")); assert!(format!("{:?}", Body::Empty).contains("Body::Empty"));
assert!(format!("{:?}", Body::Bytes(Bytes::from_static(b"1"))).contains('1')); assert!(format!("{:?}", Body::Bytes(Bytes::from_static(b"1"))).contains('1'));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_serde_json() { async fn test_serde_json() {
use serde_json::json; use serde_json::json;
assert_eq!( assert_eq!(
@ -694,7 +694,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn body_stream() { async fn body_stream() {
let st = BodyStream::new(stream::once(ok::<_, io::Error>(Bytes::from("1")))); let st = BodyStream::new(stream::once(ok::<_, io::Error>(Bytes::from("1"))));
let body: Body = st.into(); let body: Body = st.into();
@ -705,7 +705,7 @@ mod tests {
assert!(res.as_ref().is_some()); assert!(res.as_ref().is_some());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn body_skips_empty_chunks() { async fn body_skips_empty_chunks() {
let mut body = BodyStream::new(stream::iter( let mut body = BodyStream::new(stream::iter(
["1", "", "2"] ["1", "", "2"]
@ -722,7 +722,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn sized_skips_empty_chunks() { async fn sized_skips_empty_chunks() {
let mut body = SizedStream::new( let mut body = SizedStream::new(
2, 2,

View file

@ -146,7 +146,7 @@ impl ClientBuilder {
mod tests { mod tests {
use super::*; use super::*;
#[ntex_rt::test] #[crate::rt_test]
async fn basics() { async fn basics() {
let builder = ClientBuilder::new() let builder = ClientBuilder::new()
.disable_timeout() .disable_timeout()
@ -158,7 +158,7 @@ mod tests {
assert_eq!(builder.max_redirects, 10); assert_eq!(builder.max_redirects, 10);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn client_basic_auth() { async fn client_basic_auth() {
let client = ClientBuilder::new().basic_auth("username", Some("password")); let client = ClientBuilder::new().basic_auth("username", Some("password"));
assert_eq!( assert_eq!(
@ -185,7 +185,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn client_bearer_auth() { async fn client_bearer_auth() {
let client = ClientBuilder::new().bearer_auth("someS3cr3tAutht0k3n"); let client = ClientBuilder::new().bearer_auth("someS3cr3tAutht0k3n");
assert_eq!( assert_eq!(

View file

@ -369,7 +369,7 @@ mod tests {
use super::*; use super::*;
use futures::future::lazy; use futures::future::lazy;
#[ntex_rt::test] #[crate::rt_test]
async fn test_readiness() { async fn test_readiness() {
let conn = Connector::default().finish(); let conn = Connector::default().finish();
assert!(lazy(|cx| conn.poll_ready(cx).is_ready()).await); assert!(lazy(|cx| conn.poll_ready(cx).is_ready()).await);

View file

@ -613,7 +613,7 @@ mod tests {
use crate::service::fn_service; use crate::service::fn_service;
use crate::testing::Io; use crate::testing::Io;
#[ntex_rt::test] #[crate::rt_test]
async fn test_basics() { async fn test_basics() {
let store = Rc::new(RefCell::new(Vec::new())); let store = Rc::new(RefCell::new(Vec::new()));
let store2 = store.clone(); let store2 = store.clone();

View file

@ -574,7 +574,7 @@ mod tests {
use super::*; use super::*;
use crate::http::client::Client; use crate::http::client::Client;
#[ntex_rt::test] #[crate::rt_test]
async fn test_debug() { async fn test_debug() {
let request = Client::new().get("/").header("x-test", "111"); let request = Client::new().get("/").header("x-test", "111");
let repr = format!("{:?}", request); let repr = format!("{:?}", request);
@ -582,7 +582,7 @@ mod tests {
assert!(repr.contains("x-test")); assert!(repr.contains("x-test"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_basics() { async fn test_basics() {
let mut req = Client::new() let mut req = Client::new()
.put("/") .put("/")
@ -611,7 +611,7 @@ mod tests {
let _ = req.send_body(""); let _ = req.send_body("");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_client_header() { async fn test_client_header() {
let req = Client::build() let req = Client::build()
.header(header::CONTENT_TYPE, "111") .header(header::CONTENT_TYPE, "111")
@ -629,7 +629,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_client_header_override() { async fn test_client_header_override() {
let req = Client::build() let req = Client::build()
.header(header::CONTENT_TYPE, "111") .header(header::CONTENT_TYPE, "111")
@ -648,7 +648,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn client_basic_auth() { async fn client_basic_auth() {
let req = Client::new() let req = Client::new()
.get("/") .get("/")
@ -675,7 +675,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn client_bearer_auth() { async fn client_bearer_auth() {
let req = Client::new().get("/").bearer_auth("someS3cr3tAutht0k3n"); let req = Client::new().get("/").bearer_auth("someS3cr3tAutht0k3n");
assert_eq!( assert_eq!(
@ -689,7 +689,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn client_query() { async fn client_query() {
let req = Client::new() let req = Client::new()
.get("/") .get("/")

View file

@ -356,7 +356,7 @@ mod tests {
use crate::http::client::test::TestResponse; use crate::http::client::test::TestResponse;
use crate::http::header; use crate::http::header;
#[ntex_rt::test] #[crate::rt_test]
async fn test_body() { async fn test_body() {
let mut req = TestResponse::with_header(header::CONTENT_LENGTH, "xxxx").finish(); let mut req = TestResponse::with_header(header::CONTENT_LENGTH, "xxxx").finish();
match req.body().await.err().unwrap() { match req.body().await.err().unwrap() {
@ -404,7 +404,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_json_body() { async fn test_json_body() {
let mut req = TestResponse::default().finish(); let mut req = TestResponse::default().finish();
let json = JsonBody::<MyObject>::new(&mut req).await; let json = JsonBody::<MyObject>::new(&mut req).await;

View file

@ -473,7 +473,7 @@ mod tests {
use super::*; use super::*;
use crate::http::client::Client; use crate::http::client::Client;
#[ntex_rt::test] #[crate::rt_test]
async fn test_debug() { async fn test_debug() {
let request = Client::new().ws("/").header("x-test", "111"); let request = Client::new().ws("/").header("x-test", "111");
let repr = format!("{:?}", request); let repr = format!("{:?}", request);
@ -481,7 +481,7 @@ mod tests {
assert!(repr.contains("x-test")); assert!(repr.contains("x-test"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_header_override() { async fn test_header_override() {
let req = Client::build() let req = Client::build()
.header(header::CONTENT_TYPE, "111") .header(header::CONTENT_TYPE, "111")
@ -500,7 +500,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn basic_auth() { async fn basic_auth() {
let req = Client::new() let req = Client::new()
.ws("/") .ws("/")
@ -527,7 +527,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn bearer_auth() { async fn bearer_auth() {
let req = Client::new().ws("/").bearer_auth("someS3cr3tAutht0k3n"); let req = Client::new().ws("/").bearer_auth("someS3cr3tAutht0k3n");
assert_eq!( assert_eq!(
@ -543,7 +543,7 @@ mod tests {
} }
#[cfg(feature = "cookie")] #[cfg(feature = "cookie")]
#[ntex_rt::test] #[crate::rt_test]
async fn basics() { async fn basics() {
let req = Client::new() let req = Client::new()
.ws("http://localhost/") .ws("http://localhost/")

View file

@ -243,7 +243,7 @@ impl DateService {
mod tests { mod tests {
use super::*; use super::*;
#[ntex_rt::test] #[crate::rt_test]
async fn test_date() { async fn test_date() {
let date = DateService::default(); let date = DateService::default();
let mut buf1 = BytesMut::with_capacity(DATE_VALUE_LENGTH_HDR); let mut buf1 = BytesMut::with_capacity(DATE_VALUE_LENGTH_HDR);

View file

@ -728,7 +728,7 @@ mod tests {
decoder.decode(buf).unwrap().unwrap() decoder.decode(buf).unwrap().unwrap()
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_req_parse_err() { async fn test_req_parse_err() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(1024); client.remote_buffer_cap(1024);
@ -750,7 +750,7 @@ mod tests {
assert!(h1.inner.state.is_io_err()); assert!(h1.inner.state.is_io_err());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_pipeline() { async fn test_pipeline() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(4096); client.remote_buffer_cap(4096);
@ -776,7 +776,7 @@ mod tests {
assert!(client.is_server_dropped()); assert!(client.is_server_dropped());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_pipeline_with_payload() { async fn test_pipeline_with_payload() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(4096); client.remote_buffer_cap(4096);
@ -806,7 +806,7 @@ mod tests {
assert!(client.is_server_dropped()); assert!(client.is_server_dropped());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_pipeline_with_delay() { async fn test_pipeline_with_delay() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(4096); client.remote_buffer_cap(4096);
@ -844,7 +844,7 @@ mod tests {
assert!(client.is_server_dropped()); assert!(client.is_server_dropped());
} }
#[ntex_rt::test] #[crate::rt_test]
/// if socket is disconnected, h1 dispatcher does not process any data /// if socket is disconnected, h1 dispatcher does not process any data
// /// h1 dispatcher still processes all incoming requests // /// h1 dispatcher still processes all incoming requests
// /// but it does not write any data to socket // /// but it does not write any data to socket
@ -870,7 +870,7 @@ mod tests {
assert_eq!(num.load(Ordering::Relaxed), 0); assert_eq!(num.load(Ordering::Relaxed), 0);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_read_large_message() { async fn test_read_large_message() {
let (client, server) = Io::create(); let (client, server) = Io::create();
client.remote_buffer_cap(4096); client.remote_buffer_cap(4096);
@ -896,7 +896,7 @@ mod tests {
assert_eq!(load(&mut decoder, &mut buf).status, StatusCode::BAD_REQUEST); assert_eq!(load(&mut decoder, &mut buf).status, StatusCode::BAD_REQUEST);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_read_backpressure() { async fn test_read_backpressure() {
let mark = Arc::new(AtomicBool::new(false)); let mark = Arc::new(AtomicBool::new(false));
let mark2 = mark.clone(); let mark2 = mark.clone();
@ -932,7 +932,7 @@ mod tests {
assert!(mark.load(Ordering::Relaxed)); assert!(mark.load(Ordering::Relaxed));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_write_backpressure() { async fn test_write_backpressure() {
let num = Arc::new(AtomicUsize::new(0)); let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone(); let num2 = num.clone();
@ -989,7 +989,7 @@ mod tests {
assert_eq!(num.load(Ordering::Relaxed), 65_536 * 2); assert_eq!(num.load(Ordering::Relaxed), 65_536 * 2);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_disconnect_during_response_body_pending() { async fn test_disconnect_during_response_body_pending() {
struct Stream(bool); struct Stream(bool);

View file

@ -211,7 +211,7 @@ mod tests {
use super::*; use super::*;
use futures::future::poll_fn; use futures::future::poll_fn;
#[ntex_rt::test] #[crate::rt_test]
async fn test_unread_data() { async fn test_unread_data() {
let (_, mut payload) = Payload::create(false); let (_, mut payload) = Payload::create(false);

View file

@ -27,7 +27,11 @@ extern crate log;
#[macro_use] #[macro_use]
extern crate derive_more; extern crate derive_more;
pub use ntex_rt_macros::{main, test}; #[cfg(not(test))] // Work around for rust-lang/rust#62127
pub use ntex_macros::{rt_main as main, rt_test as test};
#[cfg(test)]
pub(crate) use ntex_macros::rt_test;
pub mod channel; pub mod channel;
pub mod connect; pub mod connect;

View file

@ -517,7 +517,7 @@ mod tests {
use crate::service::fn_service; use crate::service::fn_service;
#[cfg(unix)] #[cfg(unix)]
#[ntex_rt::test] #[crate::rt_test]
async fn test_signals() { async fn test_signals() {
use futures::future::ok; use futures::future::ok;
use std::sync::mpsc; use std::sync::mpsc;

View file

@ -573,7 +573,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
#[allow(clippy::mutex_atomic)] #[allow(clippy::mutex_atomic)]
async fn basics() { async fn basics() {
let (_tx1, rx1) = unbounded(); let (_tx1, rx1) = unbounded();

View file

@ -331,7 +331,7 @@ impl AsyncWrite for Io {
mod tests { mod tests {
use super::*; use super::*;
#[ntex_rt::test] #[crate::rt_test]
async fn basic() { async fn basic() {
let (client, server) = Io::create(); let (client, server) = Io::create();
assert_eq!(client.tp, Type::Client); assert_eq!(client.tp, Type::Client);

View file

@ -271,7 +271,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_transform() { async fn test_transform() {
let inner = Rc::new(Inner { let inner = Rc::new(Inner {
ready: Cell::new(false), ready: Cell::new(false),
@ -319,7 +319,7 @@ mod tests {
assert!(lazy(|cx| srv.poll_shutdown(cx, false)).await.is_ready()); assert!(lazy(|cx| srv.poll_shutdown(cx, false)).await.is_ready());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_newtransform() { async fn test_newtransform() {
let inner = Rc::new(Inner { let inner = Rc::new(Inner {
ready: Cell::new(false), ready: Cell::new(false),

View file

@ -146,7 +146,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_transform() { async fn test_transform() {
let wait_time = Duration::from_millis(50); let wait_time = Duration::from_millis(50);
@ -162,7 +162,7 @@ mod tests {
assert!(lazy(|cx| srv.poll_shutdown(cx, false)).await.is_ready()); assert!(lazy(|cx| srv.poll_shutdown(cx, false)).await.is_ready());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_newtransform() { async fn test_newtransform() {
let wait_time = Duration::from_millis(50); let wait_time = Duration::from_millis(50);

View file

@ -153,7 +153,7 @@ mod tests {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
struct TestErr; struct TestErr;
#[ntex_rt::test] #[crate::rt_test]
async fn test_ka() { async fn test_ka() {
let factory = KeepAlive::new( let factory = KeepAlive::new(
Duration::from_millis(100), Duration::from_millis(100),

View file

@ -166,7 +166,7 @@ mod tests {
use crate::rt::time::delay_for; use crate::rt::time::delay_for;
use crate::ws; use crate::ws;
#[ntex_rt::test] #[crate::rt_test]
async fn test_basic() { async fn test_basic() {
let counter = Rc::new(Cell::new(0)); let counter = Rc::new(Cell::new(0));
let counter2 = counter.clone(); let counter2 = counter.clone();

View file

@ -163,7 +163,7 @@ mod tests {
use futures::future::lazy; use futures::future::lazy;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
#[ntex_rt::test] #[crate::rt_test]
async fn low_res_timee() { async fn low_res_timee() {
let f = LowResTime::default(); let f = LowResTime::default();
let srv = f.new_service(()).await.unwrap(); let srv = f.new_service(()).await.unwrap();
@ -174,7 +174,7 @@ mod tests {
/// State Under Test: Two calls of `SystemTimeService::now()` return the same value if they are done within resolution interval of `SystemTimeService`. /// State Under Test: Two calls of `SystemTimeService::now()` return the same value if they are done within resolution interval of `SystemTimeService`.
/// ///
/// Expected Behavior: Two back-to-back calls of `SystemTimeService::now()` return the same value. /// Expected Behavior: Two back-to-back calls of `SystemTimeService::now()` return the same value.
#[ntex_rt::test] #[crate::rt_test]
async fn system_time_service_time_does_not_immediately_change() { async fn system_time_service_time_does_not_immediately_change() {
let resolution = Duration::from_millis(50); let resolution = Duration::from_millis(50);
@ -185,7 +185,7 @@ mod tests {
/// State Under Test: Two calls of `LowResTimeService::now()` return the same value if they are done within resolution interval of `SystemTimeService`. /// State Under Test: Two calls of `LowResTimeService::now()` return the same value if they are done within resolution interval of `SystemTimeService`.
/// ///
/// Expected Behavior: Two back-to-back calls of `LowResTimeService::now()` return the same value. /// Expected Behavior: Two back-to-back calls of `LowResTimeService::now()` return the same value.
#[ntex_rt::test] #[crate::rt_test]
async fn lowres_time_service_time_does_not_immediately_change() { async fn lowres_time_service_time_does_not_immediately_change() {
let resolution = Duration::from_millis(50); let resolution = Duration::from_millis(50);
let time_service = LowResTimeService::with(resolution); let time_service = LowResTimeService::with(resolution);
@ -196,7 +196,7 @@ mod tests {
/// ///
/// Expected Behavior: Two calls of `LowResTimeService::now()` made in subsequent resolution interval return different values /// Expected Behavior: Two calls of `LowResTimeService::now()` made in subsequent resolution interval return different values
/// and second value is greater than the first one at least by a resolution interval. /// and second value is greater than the first one at least by a resolution interval.
#[ntex_rt::test] #[crate::rt_test]
async fn system_time_service_time_updates_after_resolution_interval() { async fn system_time_service_time_updates_after_resolution_interval() {
let resolution = Duration::from_millis(100); let resolution = Duration::from_millis(100);
let wait_time = Duration::from_millis(300); let wait_time = Duration::from_millis(300);
@ -222,7 +222,7 @@ mod tests {
/// ///
/// Expected Behavior: Two calls of `LowResTimeService::now()` made in subsequent resolution interval return different values /// Expected Behavior: Two calls of `LowResTimeService::now()` made in subsequent resolution interval return different values
/// and second value is greater than the first one at least by a resolution interval. /// and second value is greater than the first one at least by a resolution interval.
#[ntex_rt::test] #[crate::rt_test]
async fn lowres_time_service_time_updates_after_resolution_interval() { async fn lowres_time_service_time_updates_after_resolution_interval() {
let resolution = Duration::from_millis(100); let resolution = Duration::from_millis(100);
let wait_time = Duration::from_millis(300); let wait_time = Duration::from_millis(300);

View file

@ -261,7 +261,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_success() { async fn test_success() {
let resolution = Duration::from_millis(100); let resolution = Duration::from_millis(100);
let wait_time = Duration::from_millis(50); let wait_time = Duration::from_millis(50);
@ -275,7 +275,7 @@ mod tests {
.is_pending()); .is_pending());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_zero() { async fn test_zero() {
let wait_time = Duration::from_millis(50); let wait_time = Duration::from_millis(50);
let resolution = Duration::from_millis(0); let resolution = Duration::from_millis(0);
@ -285,7 +285,7 @@ mod tests {
assert!(lazy(|cx| timeout.poll_ready(cx)).await.is_ready()); assert!(lazy(|cx| timeout.poll_ready(cx)).await.is_ready());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_timeout() { async fn test_timeout() {
let resolution = Duration::from_millis(100); let resolution = Duration::from_millis(100);
let wait_time = Duration::from_millis(500); let wait_time = Duration::from_millis(500);
@ -294,7 +294,7 @@ mod tests {
assert_eq!(timeout.call(()).await, Err(TimeoutError::Timeout)); assert_eq!(timeout.call(()).await, Err(TimeoutError::Timeout));
} }
#[ntex_rt::test] #[crate::rt_test]
#[allow(clippy::redundant_clone)] #[allow(clippy::redundant_clone)]
async fn test_timeout_newservice() { async fn test_timeout_newservice() {
let resolution = Duration::from_millis(100); let resolution = Duration::from_millis(100);

View file

@ -369,7 +369,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_variant() { async fn test_variant() {
let factory = variant(fn_factory(|| ok::<_, ()>(Srv1))) let factory = variant(fn_factory(|| ok::<_, ()>(Srv1)))
.and(fn_factory(|| ok::<_, ()>(Srv2))) .and(fn_factory(|| ok::<_, ()>(Srv2)))

View file

@ -546,7 +546,7 @@ mod tests {
use crate::web::{self, DefaultError, HttpRequest, HttpResponse}; use crate::web::{self, DefaultError, HttpRequest, HttpResponse};
use crate::Service; use crate::Service;
#[ntex_rt::test] #[crate::rt_test]
async fn test_default_resource() { async fn test_default_resource() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -592,7 +592,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::CREATED); assert_eq!(resp.status(), StatusCode::CREATED);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_data_factory() { async fn test_data_factory() {
let srv = init_service( let srv = init_service(
App::new().data_factory(|| ok::<_, ()>(10usize)).service( App::new().data_factory(|| ok::<_, ()>(10usize)).service(
@ -617,7 +617,7 @@ mod tests {
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR); assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_extension() { async fn test_extension() {
let srv = init_service(App::new().app_data(10usize).service( let srv = init_service(App::new().app_data(10usize).service(
web::resource("/").to(|req: HttpRequest| async move { web::resource("/").to(|req: HttpRequest| async move {
@ -631,7 +631,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_wrap() { async fn test_wrap() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -651,7 +651,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_router_wrap() { async fn test_router_wrap() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -671,7 +671,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_wrap_fn() { async fn test_wrap_fn() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -698,7 +698,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_router_wrap_fn() { async fn test_router_wrap_fn() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -725,7 +725,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_case_insensitive_router() { async fn test_case_insensitive_router() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -742,7 +742,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_external_resource() { async fn test_external_resource() {
let srv = init_service( let srv = init_service(
App::new() App::new()

View file

@ -364,7 +364,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_drop_data() { async fn test_drop_data() {
let data = Arc::new(AtomicBool::new(false)); let data = Arc::new(AtomicBool::new(false));

View file

@ -136,7 +136,7 @@ mod tests {
use crate::web::{self, App, HttpRequest, HttpResponse}; use crate::web::{self, App, HttpRequest, HttpResponse};
use crate::Service; use crate::Service;
#[ntex_rt::test] #[crate::rt_test]
async fn test_configure_data() { async fn test_configure_data() {
let cfg = |cfg: &mut ServiceConfig<_>| { let cfg = |cfg: &mut ServiceConfig<_>| {
cfg.data(10usize); cfg.data(10usize);
@ -154,7 +154,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_configure_external_resource() { async fn test_configure_external_resource() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -182,7 +182,7 @@ mod tests {
assert_eq!(body, Bytes::from_static(b"https://youtube.com/watch/12345")); assert_eq!(body, Bytes::from_static(b"https://youtube.com/watch/12345"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_configure_service() { async fn test_configure_service() {
let srv = init_service(App::new().configure(|cfg| { let srv = init_service(App::new().configure(|cfg| {
cfg.service( cfg.service(

View file

@ -272,7 +272,7 @@ mod tests {
hello: String, hello: String,
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_option() { async fn test_option() {
let (req, mut pl) = TestRequest::with_header( let (req, mut pl) = TestRequest::with_header(
header::CONTENT_TYPE, header::CONTENT_TYPE,
@ -318,7 +318,7 @@ mod tests {
assert_eq!(r, None); assert_eq!(r, None);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_result() { async fn test_result() {
let (req, mut pl) = TestRequest::with_header( let (req, mut pl) = TestRequest::with_header(
header::CONTENT_TYPE, header::CONTENT_TYPE,

View file

@ -466,7 +466,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_data() { async fn test_data() {
let srv = init_service(App::new().app_data(10usize).service( let srv = init_service(App::new().app_data(10usize).service(
web::resource("/").to(|req: HttpRequest| { web::resource("/").to(|req: HttpRequest| {
@ -499,7 +499,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::BAD_REQUEST); assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_extensions_dropped() { async fn test_extensions_dropped() {
struct Tracker { struct Tracker {
dropped: bool, dropped: bool,

View file

@ -174,7 +174,7 @@ mod tests {
use crate::web::test::{ok_service, TestRequest}; use crate::web::test::{ok_service, TestRequest};
use crate::web::{DefaultError, Error, HttpResponse}; use crate::web::{DefaultError, Error, HttpResponse};
#[ntex_rt::test] #[crate::rt_test]
async fn test_default_headers() { async fn test_default_headers() {
let mw = DefaultHeaders::new() let mw = DefaultHeaders::new()
.header(CONTENT_TYPE, "0001") .header(CONTENT_TYPE, "0001")
@ -205,7 +205,7 @@ mod tests {
assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0002"); assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0002");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_content_type() { async fn test_content_type() {
let srv = |req: WebRequest<DefaultError>| { let srv = |req: WebRequest<DefaultError>| {
ok::<_, Error>(req.into_response(HttpResponse::Ok().finish())) ok::<_, Error>(req.into_response(HttpResponse::Ok().finish()))

View file

@ -479,7 +479,7 @@ mod tests {
use crate::web::test::{self, TestRequest}; use crate::web::test::{self, TestRequest};
use crate::web::{DefaultError, Error}; use crate::web::{DefaultError, Error};
#[ntex_rt::test] #[crate::rt_test]
async fn test_logger() { async fn test_logger() {
let srv = |req: WebRequest<DefaultError>| { let srv = |req: WebRequest<DefaultError>| {
ok::<_, Error>( ok::<_, Error>(
@ -518,7 +518,7 @@ mod tests {
assert_eq!(body, Bytes::from_static(b"TEST")); assert_eq!(body, Bytes::from_static(b"TEST"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_url_path() { async fn test_url_path() {
let mut format = Format::new("%T %U"); let mut format = Format::new("%T %U");
let req = TestRequest::with_header( let req = TestRequest::with_header(
@ -548,7 +548,7 @@ mod tests {
assert!(s.contains("/test/route/yeah")); assert!(s.contains("/test/route/yeah"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_default_format() { async fn test_default_format() {
let mut format = Format::default(); let mut format = Format::default();
@ -581,7 +581,7 @@ mod tests {
assert!(s.contains("ACTIX-WEB")); assert!(s.contains("ACTIX-WEB"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_request_time_format() { async fn test_request_time_format() {
let mut format = Format::new("%t"); let mut format = Format::new("%t");
let req = TestRequest::default().to_srv_request(); let req = TestRequest::default().to_srv_request();

View file

@ -545,7 +545,7 @@ mod tests {
use crate::web::{self, guard, App, DefaultError, HttpResponse}; use crate::web::{self, guard, App, DefaultError, HttpResponse};
use crate::Service; use crate::Service;
#[ntex_rt::test] #[crate::rt_test]
async fn test_middleware() { async fn test_middleware() {
let srv = let srv =
init_service( init_service(
@ -569,7 +569,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_middleware_fn() { async fn test_middleware_fn() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -599,7 +599,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_to() { async fn test_to() {
let srv = let srv =
init_service(App::new().service(web::resource("/test").to(|| async { init_service(App::new().service(web::resource("/test").to(|| async {
@ -612,7 +612,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_pattern() { async fn test_pattern() {
let srv = init_service(App::new().service( let srv = init_service(App::new().service(
web::resource(["/test", "/test2"]).to(|| async { HttpResponse::Ok() }), web::resource(["/test", "/test2"]).to(|| async { HttpResponse::Ok() }),
@ -626,7 +626,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_default_resource() { async fn test_default_resource() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -671,7 +671,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::BAD_REQUEST); assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_resource_guards() { async fn test_resource_guards() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -712,7 +712,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NO_CONTENT); assert_eq!(resp.status(), StatusCode::NO_CONTENT);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_data() { async fn test_data() {
let srv = init_service( let srv = init_service(
App::new() App::new()

View file

@ -414,7 +414,7 @@ pub(crate) mod tests {
responder responder
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_either_responder() { async fn test_either_responder() {
let srv = init_service(web::App::new().service( let srv = init_service(web::App::new().service(
web::resource("/index.html").to(|req: HttpRequest| async move { web::resource("/index.html").to(|req: HttpRequest| async move {
@ -436,7 +436,7 @@ pub(crate) mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_option_responder() { async fn test_option_responder() {
let srv = init_service( let srv = init_service(
web::App::new() web::App::new()
@ -463,7 +463,7 @@ pub(crate) mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_responder() { async fn test_responder() {
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();
@ -527,7 +527,7 @@ pub(crate) mod tests {
assert_eq!(resp.status(), StatusCode::BAD_REQUEST); assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_result_responder() { async fn test_result_responder() {
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();
@ -553,7 +553,7 @@ pub(crate) mod tests {
assert_eq!(res.status(), StatusCode::BAD_REQUEST); assert_eq!(res.status(), StatusCode::BAD_REQUEST);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_custom_responder() { async fn test_custom_responder() {
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();
let res = responder("test".to_string()) let res = responder("test".to_string())
@ -576,7 +576,7 @@ pub(crate) mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_tuple_responder_with_status_code() { async fn test_tuple_responder_with_status_code() {
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();
let res = Responder::<DefaultError>::respond_to( let res = Responder::<DefaultError>::respond_to(

View file

@ -294,7 +294,7 @@ mod tests {
name: String, name: String,
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_route() { async fn test_route() {
let srv = init_service( let srv = init_service(
App::new() App::new()

View file

@ -616,7 +616,7 @@ mod tests {
use crate::web::DefaultError; use crate::web::DefaultError;
use crate::web::{self, guard, App, HttpRequest, HttpResponse}; use crate::web::{self, guard, App, HttpRequest, HttpResponse};
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope() { async fn test_scope() {
let srv = let srv =
init_service(App::new().service( init_service(App::new().service(
@ -635,7 +635,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NOT_FOUND); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_root() { async fn test_scope_root() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -657,7 +657,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::CREATED); assert_eq!(resp.status(), StatusCode::CREATED);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_root2() { async fn test_scope_root2() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -676,7 +676,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_root3() { async fn test_scope_root3() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -695,7 +695,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_route() { async fn test_scope_route() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -723,7 +723,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NOT_FOUND); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_route_without_leading_slash() { async fn test_scope_route_without_leading_slash() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -753,7 +753,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_guard() { async fn test_scope_guard() {
let srv = let srv =
init_service(App::new().service( init_service(App::new().service(
@ -776,7 +776,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_variable_segment() { async fn test_scope_variable_segment() {
let srv = init_service(App::new().service(web::scope("/ab-{project}").service( let srv = init_service(App::new().service(web::scope("/ab-{project}").service(
web::resource("/path1").to(|r: HttpRequest| async move { web::resource("/path1").to(|r: HttpRequest| async move {
@ -800,7 +800,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NOT_FOUND); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_nested_scope() { async fn test_nested_scope() {
let srv = init_service(App::new().service(web::scope("/app").service( let srv = init_service(App::new().service(web::scope("/app").service(
web::scope("/t1").service( web::scope("/t1").service(
@ -814,7 +814,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::CREATED); assert_eq!(resp.status(), StatusCode::CREATED);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_nested_scope_no_slash() { async fn test_nested_scope_no_slash() {
let srv = init_service(App::new().service(web::scope("/app").service( let srv = init_service(App::new().service(web::scope("/app").service(
web::scope("t1").service( web::scope("t1").service(
@ -828,7 +828,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::CREATED); assert_eq!(resp.status(), StatusCode::CREATED);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_nested_scope_root() { async fn test_nested_scope_root() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -852,7 +852,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::CREATED); assert_eq!(resp.status(), StatusCode::CREATED);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_nested_scope_filter() { async fn test_nested_scope_filter() {
let srv = let srv =
init_service(App::new().service(web::scope("/app").service( init_service(App::new().service(web::scope("/app").service(
@ -875,7 +875,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_nested_scope_with_variable_segment() { async fn test_nested_scope_with_variable_segment() {
let srv = init_service(App::new().service(web::scope("/app").service( let srv = init_service(App::new().service(web::scope("/app").service(
web::scope("/{project_id}").service(web::resource("/path1").to( web::scope("/{project_id}").service(web::resource("/path1").to(
@ -897,7 +897,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_nested2_scope_with_variable_segment() { async fn test_nested2_scope_with_variable_segment() {
let srv = init_service(App::new().service(web::scope("/app").service( let srv = init_service(App::new().service(web::scope("/app").service(
web::scope("/{project}").service(web::scope("/{id}").service( web::scope("/{project}").service(web::scope("/{id}").service(
@ -926,7 +926,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NOT_FOUND); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_default_resource() { async fn test_default_resource() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -948,7 +948,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NOT_FOUND); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_default_resource_propagation() { async fn test_default_resource_propagation() {
let srv = init_service( let srv = init_service(
App::new() App::new()
@ -975,7 +975,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_middleware() { async fn test_middleware() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -1001,7 +1001,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_middleware_fn() { async fn test_middleware_fn() {
let srv = init_service( let srv = init_service(
App::new().service( App::new().service(
@ -1029,7 +1029,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_override_data() { async fn test_override_data() {
let srv = init_service(App::new().data(1usize).service( let srv = init_service(App::new().data(1usize).service(
web::scope("app").data(10usize).route( web::scope("app").data(10usize).route(
@ -1047,7 +1047,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_override_app_data() { async fn test_override_app_data() {
let srv = init_service( let srv = init_service(
App::new().app_data(web::types::Data::new(1usize)).service( App::new().app_data(web::types::Data::new(1usize)).service(
@ -1069,7 +1069,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_config() { async fn test_scope_config() {
let srv = init_service(App::new().service(web::scope("/app").configure(|s| { let srv = init_service(App::new().service(web::scope("/app").configure(|s| {
s.data("teat"); s.data("teat");
@ -1082,7 +1082,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_scope_config_2() { async fn test_scope_config_2() {
let srv = init_service(App::new().service(web::scope("/app").configure(|s| { let srv = init_service(App::new().service(web::scope("/app").configure(|s| {
s.service(web::scope("/v1").configure(|s| { s.service(web::scope("/v1").configure(|s| {
@ -1096,7 +1096,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_url_for_external() { async fn test_url_for_external() {
let srv = init_service(App::new().service(web::scope("/app").configure(|s| { let srv = init_service(App::new().service(web::scope("/app").configure(|s| {
s.service(web::scope("/v1").configure(|s| { s.service(web::scope("/v1").configure(|s| {
@ -1123,7 +1123,7 @@ mod tests {
assert_eq!(body, &b"https://youtube.com/watch/xxxxxx"[..]); assert_eq!(body, &b"https://youtube.com/watch/xxxxxx"[..]);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_url_for_nested() { async fn test_url_for_nested() {
let srv = init_service(App::new().service(web::scope("/a").service( let srv = init_service(App::new().service(web::scope("/a").service(
web::scope("/b").service(web::resource("/c/{stuff}").name("c").route( web::scope("/b").service(web::resource("/c/{stuff}").name("c").route(

View file

@ -394,7 +394,7 @@ mod tests {
assert!(WebRequest::<DefaultError>::from_request(r).is_err()); assert!(WebRequest::<DefaultError>::from_request(r).is_err());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_service() { async fn test_service() {
let srv = init_service(App::new().service( let srv = init_service(App::new().service(
web::service("/test").name("test").finish( web::service("/test").name("test").finish(
@ -423,7 +423,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NOT_FOUND); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_multi() { async fn test_multi() {
let srv = init_service(App::new().service([ let srv = init_service(App::new().service([
web::resource("/test1").to(|| async { HttpResponse::Ok() }), web::resource("/test1").to(|| async { HttpResponse::Ok() }),

View file

@ -975,7 +975,7 @@ mod tests {
use crate::http::HttpMessage; use crate::http::HttpMessage;
use crate::web::{self, App, HttpResponse}; use crate::web::{self, App, HttpResponse};
#[ntex_rt::test] #[crate::rt_test]
async fn test_basics() { async fn test_basics() {
let req = TestRequest::with_header(header::CONTENT_TYPE, "application/json") let req = TestRequest::with_header(header::CONTENT_TYPE, "application/json")
.version(Version::HTTP_2) .version(Version::HTTP_2)
@ -998,7 +998,7 @@ mod tests {
assert_eq!(format!("{:?}", StreamType::Tcp), "StreamType::Tcp"); assert_eq!(format!("{:?}", StreamType::Tcp), "StreamType::Tcp");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_request_methods() { async fn test_request_methods() {
let app = init_service( let app = init_service(
App::new().service( App::new().service(
@ -1036,7 +1036,7 @@ mod tests {
assert_eq!(result, Bytes::from_static(b"delete!")); assert_eq!(result, Bytes::from_static(b"delete!"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_response() { async fn test_response() {
let app = let app =
init_service(App::new().service(web::resource("/index.html").route( init_service(App::new().service(web::resource("/index.html").route(
@ -1059,7 +1059,7 @@ mod tests {
name: String, name: String,
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_response_json() { async fn test_response_json() {
let app = init_service(App::new().service(web::resource("/people").route( let app = init_service(App::new().service(web::resource("/people").route(
web::post().to(|person: web::types::Json<Person>| async { web::post().to(|person: web::types::Json<Person>| async {
@ -1080,7 +1080,7 @@ mod tests {
assert_eq!(&result.id, "12345"); assert_eq!(&result.id, "12345");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_request_response_form() { async fn test_request_response_form() {
let app = init_service(App::new().service(web::resource("/people").route( let app = init_service(App::new().service(web::resource("/people").route(
web::post().to(|person: web::types::Form<Person>| async { web::post().to(|person: web::types::Form<Person>| async {
@ -1106,7 +1106,7 @@ mod tests {
assert_eq!(&result.name, "User name"); assert_eq!(&result.name, "User name");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_request_response_json() { async fn test_request_response_json() {
let app = init_service(App::new().service(web::resource("/people").route( let app = init_service(App::new().service(web::resource("/people").route(
web::post().to(|person: web::types::Json<Person>| async { web::post().to(|person: web::types::Json<Person>| async {
@ -1132,7 +1132,7 @@ mod tests {
assert_eq!(&result.name, "User name"); assert_eq!(&result.name, "User name");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_async_with_block() { async fn test_async_with_block() {
async fn async_with_block() -> Result<HttpResponse, Infallible> { async fn async_with_block() -> Result<HttpResponse, Infallible> {
let res = web::block(move || Some(4usize).ok_or("wrong")).await; let res = web::block(move || Some(4usize).ok_or("wrong")).await;
@ -1156,7 +1156,7 @@ mod tests {
assert!(res.status().is_success()); assert!(res.status().is_success());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_server_data() { async fn test_server_data() {
async fn handler(data: web::types::Data<usize>) -> crate::http::ResponseBuilder { async fn handler(data: web::types::Data<usize>) -> crate::http::ResponseBuilder {
assert_eq!(**data, 10); assert_eq!(**data, 10);
@ -1173,7 +1173,7 @@ mod tests {
assert!(res.status().is_success()); assert!(res.status().is_success());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_test_methods() { async fn test_test_methods() {
let srv = server(|| { let srv = server(|| {
App::new().service( App::new().service(
@ -1212,7 +1212,7 @@ mod tests {
assert_eq!(srv.load_body(res).await.unwrap(), Bytes::new()); assert_eq!(srv.load_body(res).await.unwrap(), Bytes::new());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_h2_tcp() { async fn test_h2_tcp() {
let srv = server_with(TestServerConfig::default().h2(), || { let srv = server_with(TestServerConfig::default().h2(), || {
App::new().service( App::new().service(

View file

@ -139,7 +139,7 @@ mod tests {
use crate::web::{self, App, HttpResponse}; use crate::web::{self, App, HttpResponse};
use crate::Service; use crate::Service;
#[ntex_rt::test] #[crate::rt_test]
async fn test_data_extractor() { async fn test_data_extractor() {
let srv = init_service(App::new().data("TEST".to_string()).service( let srv = init_service(App::new().data("TEST".to_string()).service(
web::resource("/").to(|data: web::types::Data<String>| async move { web::resource("/").to(|data: web::types::Data<String>| async move {
@ -165,7 +165,7 @@ mod tests {
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR); assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_app_data_extractor() { async fn test_app_data_extractor() {
let srv = init_service( let srv = init_service(
App::new().app_data(Data::new(10usize)).service( App::new().app_data(Data::new(10usize)).service(
@ -191,7 +191,7 @@ mod tests {
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR); assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_route_data_extractor() { async fn test_route_data_extractor() {
let srv = let srv =
init_service(App::new().service(web::resource("/").data(10usize).route( init_service(App::new().service(web::resource("/").data(10usize).route(
@ -217,7 +217,7 @@ mod tests {
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR); assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_override_data() { async fn test_override_data() {
let srv = init_service(App::new().data(1usize).service( let srv = init_service(App::new().data(1usize).service(
web::resource("/").data(10usize).route(web::get().to( web::resource("/").data(10usize).route(web::get().to(
@ -235,7 +235,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_data_drop() { async fn test_data_drop() {
struct TestData(Arc<AtomicUsize>); struct TestData(Arc<AtomicUsize>);

View file

@ -396,7 +396,7 @@ mod tests {
assert!(format!("{}", f).contains("test")); assert!(format!("{}", f).contains("test"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_form() { async fn test_form() {
let (req, mut pl) = let (req, mut pl) =
TestRequest::with_header(CONTENT_TYPE, "application/x-www-form-urlencoded") TestRequest::with_header(CONTENT_TYPE, "application/x-www-form-urlencoded")
@ -422,7 +422,7 @@ mod tests {
assert!(eq(res.err().unwrap(), UrlencodedError::UnknownLength)); assert!(eq(res.err().unwrap(), UrlencodedError::UnknownLength));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_urlencoded_error() { async fn test_urlencoded_error() {
let (req, mut pl) = let (req, mut pl) =
TestRequest::with_header(CONTENT_TYPE, "application/x-www-form-urlencoded") TestRequest::with_header(CONTENT_TYPE, "application/x-www-form-urlencoded")
@ -448,7 +448,7 @@ mod tests {
assert!(eq(info.err().unwrap(), UrlencodedError::ContentType)); assert!(eq(info.err().unwrap(), UrlencodedError::ContentType));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_urlencoded() { async fn test_urlencoded() {
let (req, mut pl) = let (req, mut pl) =
TestRequest::with_header(CONTENT_TYPE, "application/x-www-form-urlencoded") TestRequest::with_header(CONTENT_TYPE, "application/x-www-form-urlencoded")
@ -500,7 +500,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_responder() { async fn test_responder() {
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();

View file

@ -423,7 +423,7 @@ mod tests {
assert!(format!("{}", j).contains("test")); assert!(format!("{}", j).contains("test"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_responder() { async fn test_responder() {
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();
@ -440,7 +440,7 @@ mod tests {
assert_eq!(resp.body().get_ref(), b"{\"name\":\"test\"}"); assert_eq!(resp.body().get_ref(), b"{\"name\":\"test\"}");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_extract() { async fn test_extract() {
let (req, mut pl) = TestRequest::default() let (req, mut pl) = TestRequest::default()
.header( .header(
@ -481,7 +481,7 @@ mod tests {
.contains("Json payload size is bigger than allowed")); .contains("Json payload size is bigger than allowed"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_json_body() { async fn test_json_body() {
let (req, mut pl) = TestRequest::default().to_http_parts(); let (req, mut pl) = TestRequest::default().to_http_parts();
let json = JsonBody::<MyObject>::new(&req, &mut pl, None).await; let json = JsonBody::<MyObject>::new(&req, &mut pl, None).await;
@ -533,7 +533,7 @@ mod tests {
); );
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_with_json_and_bad_content_type() { async fn test_with_json_and_bad_content_type() {
let (req, mut pl) = TestRequest::with_header( let (req, mut pl) = TestRequest::with_header(
header::CONTENT_TYPE, header::CONTENT_TYPE,
@ -551,7 +551,7 @@ mod tests {
assert!(s.is_err()) assert!(s.is_err())
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_with_json_and_good_custom_content_type() { async fn test_with_json_and_good_custom_content_type() {
let (req, mut pl) = TestRequest::with_header( let (req, mut pl) = TestRequest::with_header(
header::CONTENT_TYPE, header::CONTENT_TYPE,
@ -571,7 +571,7 @@ mod tests {
assert!(s.is_ok()) assert!(s.is_ok())
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_with_json_and_bad_custom_content_type() { async fn test_with_json_and_bad_custom_content_type() {
let (req, mut pl) = TestRequest::with_header( let (req, mut pl) = TestRequest::with_header(
header::CONTENT_TYPE, header::CONTENT_TYPE,

View file

@ -199,7 +199,7 @@ mod tests {
value: u32, value: u32,
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_extract_path_single() { async fn test_extract_path_single() {
let mut router = Router::<usize>::build(); let mut router = Router::<usize>::build();
router.path("/{value}/", 10).0.set_id(0); router.path("/{value}/", 10).0.set_id(0);
@ -213,7 +213,7 @@ mod tests {
assert!(from_request::<Path<MyStruct>>(&req, &mut pl).await.is_err()); assert!(from_request::<Path<MyStruct>>(&req, &mut pl).await.is_err());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_tuple_extract() { async fn test_tuple_extract() {
let mut router = Router::<usize>::build(); let mut router = Router::<usize>::build();
router.path("/{key}/{value}/", 10).0.set_id(0); router.path("/{key}/{value}/", 10).0.set_id(0);
@ -242,7 +242,7 @@ mod tests {
from_request::<()>(&req, &mut pl).await.unwrap(); from_request::<()>(&req, &mut pl).await.unwrap();
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_request_extract() { async fn test_request_extract() {
let mut router = Router::<usize>::build(); let mut router = Router::<usize>::build();
router.path("/{key}/{value}/", 10).0.set_id(0); router.path("/{key}/{value}/", 10).0.set_id(0);

View file

@ -424,7 +424,7 @@ mod tests {
use crate::http::header; use crate::http::header;
use crate::web::test::{from_request, TestRequest}; use crate::web::test::{from_request, TestRequest};
#[ntex_rt::test] #[crate::rt_test]
async fn test_payload_config() { async fn test_payload_config() {
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();
let cfg = PayloadConfig::default().mimetype(mime::APPLICATION_JSON); let cfg = PayloadConfig::default().mimetype(mime::APPLICATION_JSON);
@ -442,7 +442,7 @@ mod tests {
assert!(cfg.check_mimetype(&req).is_ok()); assert!(cfg.check_mimetype(&req).is_ok());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_payload() { async fn test_payload() {
let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "11") let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "11")
.set_payload(Bytes::from_static(b"hello=world")) .set_payload(Bytes::from_static(b"hello=world"))
@ -456,7 +456,7 @@ mod tests {
assert_eq!(b, Bytes::from_static(b"hello=world")); assert_eq!(b, Bytes::from_static(b"hello=world"));
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_bytes() { async fn test_bytes() {
let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "11") let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "11")
.set_payload(Bytes::from_static(b"hello=world")) .set_payload(Bytes::from_static(b"hello=world"))
@ -472,7 +472,7 @@ mod tests {
assert!(from_request::<Bytes>(&req, &mut pl).await.is_err()); assert!(from_request::<Bytes>(&req, &mut pl).await.is_err());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_string() { async fn test_string() {
let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "11") let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "11")
.set_payload(Bytes::from_static(b"hello=world")) .set_payload(Bytes::from_static(b"hello=world"))
@ -495,7 +495,7 @@ mod tests {
assert!(from_request::<String>(&req, &mut pl).await.is_err()); assert!(from_request::<String>(&req, &mut pl).await.is_err());
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_message_body() { async fn test_message_body() {
let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "xxxx") let (req, mut pl) = TestRequest::with_header(header::CONTENT_LENGTH, "xxxx")
.to_srv_request() .to_srv_request()

View file

@ -164,7 +164,7 @@ mod tests {
id: String, id: String,
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_service_request_extract() { async fn test_service_request_extract() {
let req = TestRequest::with_uri("/name/user1/").to_srv_request(); let req = TestRequest::with_uri("/name/user1/").to_srv_request();
assert!(Query::<Id>::from_query(&req.query_string()).is_err()); assert!(Query::<Id>::from_query(&req.query_string()).is_err());
@ -180,7 +180,7 @@ mod tests {
assert_eq!(s.id, "test1"); assert_eq!(s.id, "test1");
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_request_extract() { async fn test_request_extract() {
let req = TestRequest::with_uri("/name/user1/").to_srv_request(); let req = TestRequest::with_uri("/name/user1/").to_srv_request();
let (req, mut pl) = req.into_parts(); let (req, mut pl) = req.into_parts();

View file

@ -182,7 +182,7 @@ mod tests {
use super::*; use super::*;
use crate::channel::mpsc; use crate::channel::mpsc;
#[ntex_rt::test] #[crate::rt_test]
async fn test_decoder() { async fn test_decoder() {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let mut decoder = StreamDecoder::new(rx); let mut decoder = StreamDecoder::new(rx);
@ -209,7 +209,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[crate::rt_test]
async fn test_encoder() { async fn test_encoder() {
let (tx, mut rx) = mpsc::channel(); let (tx, mut rx) = mpsc::channel();
let mut encoder = StreamEncoder::new(tx); let mut encoder = StreamEncoder::new(tx);