fix runtime macros

This commit is contained in:
Nikolay Kim 2021-02-24 13:58:41 +06:00
parent 2d8ce48456
commit 055bd730d4
17 changed files with 43 additions and 39 deletions

View file

@ -1,5 +1,9 @@
# Changes # Changes
## [0.1.2] - 2021-02-25
* Export runtime from ntex crate
## [0.1.1] - 2021-02-25 ## [0.1.1] - 2021-02-25
* Move `main` and `test` macros from rt macros * Move `main` and `test` macros from rt macros

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ntex-macros" name = "ntex-macros"
version = "0.1.1" version = "0.1.2"
description = "ntex proc macros" description = "ntex proc macros"
readme = "README.md" readme = "README.md"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]

View file

@ -216,7 +216,7 @@ pub fn rt_main(_: TokenStream, item: TokenStream) -> TokenStream {
(quote! { (quote! {
#(#attrs)* #(#attrs)*
#vis #sig { #vis #sig {
ntex_rt::System::new(stringify!(#name)) ntex::rt::System::new(stringify!(#name))
.block_on(async move { #body }) .block_on(async move { #body })
} }
}) })
@ -262,7 +262,7 @@ pub fn rt_test(_: TokenStream, item: TokenStream) -> TokenStream {
quote! { quote! {
#(#attrs)* #(#attrs)*
fn #name() #ret { fn #name() #ret {
ntex_rt::System::new("test") ntex::rt::System::new("test")
.block_on(async { #body }) .block_on(async { #body })
} }
} }
@ -271,7 +271,7 @@ pub fn rt_test(_: TokenStream, item: TokenStream) -> TokenStream {
#[test] #[test]
#(#attrs)* #(#attrs)*
fn #name() #ret { fn #name() #ret {
ntex_rt::System::new("test") ntex::rt::System::new("test")
.block_on(async { #body }) .block_on(async { #body })
} }
} }

View file

@ -20,4 +20,4 @@ futures-util = "0.3.13"
pin-project-lite = "0.2.4" pin-project-lite = "0.2.4"
[dev-dependencies] [dev-dependencies]
ntex-rt = "0.2" ntex = "0.3.1"

View file

@ -317,7 +317,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn test_poll_ready() { async fn test_poll_ready() {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let srv = pipeline(Srv1(cnt.clone())) let srv = pipeline(Srv1(cnt.clone()))
@ -331,7 +331,7 @@ mod tests {
assert_eq!(res, Poll::Ready(())); assert_eq!(res, Poll::Ready(()));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_call() { async fn test_call() {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let srv = pipeline(Srv1(cnt.clone())).and_then(Srv2(cnt)); let srv = pipeline(Srv1(cnt.clone())).and_then(Srv2(cnt));
@ -340,7 +340,7 @@ mod tests {
assert_eq!(res.unwrap(), ("srv1", "srv2")); assert_eq!(res.unwrap(), ("srv1", "srv2"));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_factory() { async fn test_factory() {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let cnt2 = cnt.clone(); let cnt2 = cnt.clone();

View file

@ -315,7 +315,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn test_service() { async fn test_service() {
let srv = pipeline(ok) let srv = pipeline(ok)
.and_then_apply_fn(Srv, |req: &'static str, s| { .and_then_apply_fn(Srv, |req: &'static str, s| {
@ -333,7 +333,7 @@ mod tests {
assert_eq!(res, Poll::Ready(())); assert_eq!(res, Poll::Ready(()));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_service_factory() { async fn test_service_factory() {
let new_srv = pipeline_factory(|| ok::<_, ()>(fn_service(ok))) let new_srv = pipeline_factory(|| ok::<_, ()>(fn_service(ok)))
.and_then_apply_fn( .and_then_apply_fn(

View file

@ -239,7 +239,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn test_call() { async fn test_call() {
let srv = pipeline( let srv = pipeline(
apply_fn(Srv, |req: &'static str, srv| { apply_fn(Srv, |req: &'static str, srv| {
@ -263,7 +263,7 @@ mod tests {
assert_eq!(res.unwrap(), ("srv", ())); assert_eq!(res.unwrap(), ("srv", ()));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_new_service() { async fn test_new_service() {
let new_srv = pipeline_factory( let new_srv = pipeline_factory(
apply_fn_factory( apply_fn_factory(

View file

@ -236,7 +236,7 @@ mod tests {
use super::*; use super::*;
use crate::{fn_service, Service}; use crate::{fn_service, Service};
#[ntex_rt::test] #[ntex::test]
async fn test_apply() { async fn test_apply() {
let item = Rc::new(Cell::new(10usize)); let item = Rc::new(Cell::new(10usize));
let item2 = item.clone(); let item2 = item.clone();
@ -263,7 +263,7 @@ mod tests {
assert_eq!(item.get(), 11); assert_eq!(item.get(), 11);
} }
#[ntex_rt::test] #[ntex::test]
async fn test_apply_factory() { async fn test_apply_factory() {
let item = Rc::new(Cell::new(10usize)); let item = Rc::new(Cell::new(10usize));
let item2 = item.clone(); let item2 = item.clone();

View file

@ -48,7 +48,7 @@ where
/// } /// }
/// } /// }
/// ///
/// #[ntex_rt::main] /// #[ntex::main]
/// async fn main() -> io::Result<()> { /// async fn main() -> io::Result<()> {
/// // Create service factory that produces `div` services /// // Create service factory that produces `div` services
/// let factory = fn_factory(|| { /// let factory = fn_factory(|| {
@ -90,7 +90,7 @@ where
/// use ntex_service::{fn_factory_with_config, fn_service, Service, ServiceFactory}; /// use ntex_service::{fn_factory_with_config, fn_service, Service, ServiceFactory};
/// use futures_util::future::ok; /// use futures_util::future::ok;
/// ///
/// #[ntex_rt::main] /// #[ntex::main]
/// async fn main() -> io::Result<()> { /// async fn main() -> io::Result<()> {
/// // Create service factory. factory uses config argument for /// // Create service factory. factory uses config argument for
/// // services it generates. /// // services it generates.
@ -452,7 +452,7 @@ mod tests {
use super::*; use super::*;
use crate::{Service, ServiceFactory}; use crate::{Service, ServiceFactory};
#[ntex_rt::test] #[ntex::test]
async fn test_fn_service() { async fn test_fn_service() {
let new_srv = fn_service(|()| ok::<_, ()>("srv")).clone(); let new_srv = fn_service(|()| ok::<_, ()>("srv")).clone();
@ -468,7 +468,7 @@ mod tests {
assert_eq!(res.unwrap(), "srv"); assert_eq!(res.unwrap(), "srv");
} }
#[ntex_rt::test] #[ntex::test]
async fn test_fn_mut_service() { async fn test_fn_mut_service() {
let srv = fn_mut_service(|()| ok::<_, ()>("srv")).clone(); let srv = fn_mut_service(|()| ok::<_, ()>("srv")).clone();
@ -478,7 +478,7 @@ mod tests {
assert_eq!(res.unwrap(), "srv"); assert_eq!(res.unwrap(), "srv");
} }
#[ntex_rt::test] #[ntex::test]
async fn test_fn_service_service() { async fn test_fn_service_service() {
let srv = fn_service(|()| ok::<_, ()>("srv")).clone(); let srv = fn_service(|()| ok::<_, ()>("srv")).clone();
@ -488,7 +488,7 @@ mod tests {
assert_eq!(res.unwrap(), "srv"); assert_eq!(res.unwrap(), "srv");
} }
#[ntex_rt::test] #[ntex::test]
async fn test_fn_service_with_config() { async fn test_fn_service_with_config() {
let new_srv = fn_factory_with_config(|cfg: usize| { let new_srv = fn_factory_with_config(|cfg: usize| {
ok::<_, ()>(fn_service(move |()| ok::<_, ()>(("srv", cfg)))) ok::<_, ()>(fn_service(move |()| ok::<_, ()>(("srv", cfg))))

View file

@ -92,7 +92,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn transform() { async fn transform() {
let srv = let srv =
fn_transform::<Srv, _, _, _, _, _>(|i: usize, srv: &_| srv.call(i + 1)) fn_transform::<Srv, _, _, _, _, _>(|i: usize, srv: &_| srv.call(i + 1))

View file

@ -232,7 +232,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn test_service() { async fn test_service() {
let srv = Srv.map(|_| "ok").clone(); let srv = Srv.map(|_| "ok").clone();
let res = srv.call(()).await; let res = srv.call(()).await;
@ -246,7 +246,7 @@ mod tests {
assert_eq!(res, Poll::Ready(())); assert_eq!(res, Poll::Ready(()));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_pipeline() { async fn test_pipeline() {
let srv = crate::pipeline(Srv).map(|_| "ok").clone(); let srv = crate::pipeline(Srv).map(|_| "ok").clone();
let res = srv.call(()).await; let res = srv.call(()).await;
@ -260,7 +260,7 @@ mod tests {
assert_eq!(res, Poll::Ready(())); assert_eq!(res, Poll::Ready(()));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_factory() { async fn test_factory() {
let new_srv = (|| ok::<_, ()>(Srv)).into_factory().map(|_| "ok").clone(); let new_srv = (|| ok::<_, ()>(Srv)).into_factory().map(|_| "ok").clone();
let srv = new_srv.new_service(&()).await.unwrap(); let srv = new_srv.new_service(&()).await.unwrap();
@ -269,7 +269,7 @@ mod tests {
assert_eq!(res.unwrap(), ("ok")); assert_eq!(res.unwrap(), ("ok"));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_pipeline_factory() { async fn test_pipeline_factory() {
let new_srv = crate::pipeline_factory((|| ok::<_, ()>(Srv)).into_factory()) let new_srv = crate::pipeline_factory((|| ok::<_, ()>(Srv)).into_factory())
.map(|_| "ok") .map(|_| "ok")

View file

@ -307,7 +307,7 @@ mod tests {
use super::*; use super::*;
use crate::{fn_factory_with_config, fn_service, ServiceFactory}; use crate::{fn_factory_with_config, fn_service, ServiceFactory};
#[ntex_rt::test] #[ntex::test]
async fn test_map_config() { async fn test_map_config() {
let item = Rc::new(Cell::new(1usize)); let item = Rc::new(Cell::new(1usize));
@ -321,7 +321,7 @@ mod tests {
assert_eq!(item.get(), 11); assert_eq!(item.get(), 11);
} }
#[ntex_rt::test] #[ntex::test]
async fn test_unit_config() { async fn test_unit_config() {
let _ = unit_config(fn_service(|item: usize| ok::<_, ()>(item))) let _ = unit_config(fn_service(|item: usize| ok::<_, ()>(item)))
.clone() .clone()
@ -329,7 +329,7 @@ mod tests {
.await; .await;
} }
#[ntex_rt::test] #[ntex::test]
async fn test_map_config_service() { async fn test_map_config_service() {
let item = Rc::new(Cell::new(10usize)); let item = Rc::new(Cell::new(10usize));
let item2 = item.clone(); let item2 = item.clone();

View file

@ -233,7 +233,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn test_poll_ready() { async fn test_poll_ready() {
let srv = Srv.map_err(|_| "error"); let srv = Srv.map_err(|_| "error");
let res = lazy(|cx| srv.poll_ready(cx)).await; let res = lazy(|cx| srv.poll_ready(cx)).await;
@ -243,7 +243,7 @@ mod tests {
assert_eq!(res, Poll::Ready(())); assert_eq!(res, Poll::Ready(()));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_service() { async fn test_service() {
let srv = Srv.map_err(|_| "error").clone(); let srv = Srv.map_err(|_| "error").clone();
let res = srv.call(()).await; let res = srv.call(()).await;
@ -251,7 +251,7 @@ mod tests {
assert_eq!(res.err().unwrap(), "error"); assert_eq!(res.err().unwrap(), "error");
} }
#[ntex_rt::test] #[ntex::test]
async fn test_pipeline() { async fn test_pipeline() {
let srv = crate::pipeline(Srv).map_err(|_| "error").clone(); let srv = crate::pipeline(Srv).map_err(|_| "error").clone();
let res = srv.call(()).await; let res = srv.call(()).await;
@ -259,7 +259,7 @@ mod tests {
assert_eq!(res.err().unwrap(), "error"); assert_eq!(res.err().unwrap(), "error");
} }
#[ntex_rt::test] #[ntex::test]
async fn test_factory() { async fn test_factory() {
let new_srv = (|| ok::<_, ()>(Srv)) let new_srv = (|| ok::<_, ()>(Srv))
.into_factory() .into_factory()
@ -271,7 +271,7 @@ mod tests {
assert_eq!(res.err().unwrap(), "error"); assert_eq!(res.err().unwrap(), "error");
} }
#[ntex_rt::test] #[ntex::test]
async fn test_pipeline_factory() { async fn test_pipeline_factory() {
let new_srv = crate::pipeline_factory((|| ok::<_, ()>(Srv)).into_factory()) let new_srv = crate::pipeline_factory((|| ok::<_, ()>(Srv)).into_factory())
.map_err(|_| "error") .map_err(|_| "error")

View file

@ -101,7 +101,7 @@ mod tests {
use crate::{fn_factory_with_config, fn_service, pipeline_factory, ServiceFactory}; use crate::{fn_factory_with_config, fn_service, pipeline_factory, ServiceFactory};
#[ntex_rt::test] #[ntex::test]
async fn map_init_err() { async fn map_init_err() {
let factory = pipeline_factory(fn_factory_with_config(|err: bool| async move { let factory = pipeline_factory(fn_factory_with_config(|err: bool| async move {
if err { if err {

View file

@ -310,7 +310,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn test_poll_ready() { async fn test_poll_ready() {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let srv = pipeline(Srv1(cnt.clone())).then(Srv2(cnt.clone())); let srv = pipeline(Srv1(cnt.clone())).then(Srv2(cnt.clone()));
@ -321,7 +321,7 @@ mod tests {
assert_eq!(res, Poll::Ready(())); assert_eq!(res, Poll::Ready(()));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_call() { async fn test_call() {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let srv = pipeline(Srv1(cnt.clone())).then(Srv2(cnt)).clone(); let srv = pipeline(Srv1(cnt.clone())).then(Srv2(cnt)).clone();
@ -335,7 +335,7 @@ mod tests {
assert_eq!(res.unwrap(), ("srv2", "err")); assert_eq!(res.unwrap(), ("srv2", "err"));
} }
#[ntex_rt::test] #[ntex::test]
async fn test_factory() { async fn test_factory() {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let cnt2 = cnt.clone(); let cnt2 = cnt.clone();

View file

@ -276,7 +276,7 @@ mod tests {
} }
} }
#[ntex_rt::test] #[ntex::test]
async fn transform() { async fn transform() {
let factory = apply( let factory = apply(
Rc::new(Tr.map_init_err(|_| ()).clone()), Rc::new(Tr.map_init_err(|_| ()).clone()),

View file

@ -40,7 +40,7 @@ ntex-codec = "0.4.0"
ntex-rt = "0.2.1" ntex-rt = "0.2.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.1" ntex-macros = "0.1.2"
base64 = "0.13" base64 = "0.13"
bitflags = "1.2.1" bitflags = "1.2.1"