From 4c5568ed70a54de94e4a41be8054d96fc053ff70 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 26 Apr 2020 20:11:16 +0100 Subject: [PATCH] add trybuild compile tests --- actix-macros/.gitignore | 1 + actix-macros/Cargo.toml | 6 ++++-- actix-macros/tests/trybuild.rs | 9 +++++++++ actix-macros/tests/trybuild/main-01-basic.rs | 4 ++++ actix-macros/tests/trybuild/main-02-only-async.rs | 4 ++++ .../tests/trybuild/main-02-only-async.stderr | 14 ++++++++++++++ actix-macros/tests/trybuild/test-01-basic.rs | 6 ++++++ actix-macros/tests/trybuild/test-02-keep-attrs.rs | 7 +++++++ string/src/lib.rs | 5 +++-- 9 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 actix-macros/.gitignore create mode 100644 actix-macros/tests/trybuild.rs create mode 100644 actix-macros/tests/trybuild/main-01-basic.rs create mode 100644 actix-macros/tests/trybuild/main-02-only-async.rs create mode 100644 actix-macros/tests/trybuild/main-02-only-async.stderr create mode 100644 actix-macros/tests/trybuild/test-01-basic.rs create mode 100644 actix-macros/tests/trybuild/test-02-keep-attrs.rs diff --git a/actix-macros/.gitignore b/actix-macros/.gitignore new file mode 100644 index 0000000000..b619655b32 --- /dev/null +++ b/actix-macros/.gitignore @@ -0,0 +1 @@ +/wip diff --git a/actix-macros/Cargo.toml b/actix-macros/Cargo.toml index eb72e52c43..16f3552755 100644 --- a/actix-macros/Cargo.toml +++ b/actix-macros/Cargo.toml @@ -8,7 +8,6 @@ documentation = "https://docs.rs/actix-macros/" categories = ["network-programming", "asynchronous"] license = "MIT/Apache-2.0" edition = "2018" -workspace = ".." [lib] proc-macro = true @@ -18,4 +17,7 @@ quote = "1.0.3" syn = { version = "^1", features = ["full"] } [dev-dependencies] -actix-rt = { version = "1.0.0" } +actix-rt = "1.0" + +futures = "0.3" +trybuild = "1" diff --git a/actix-macros/tests/trybuild.rs b/actix-macros/tests/trybuild.rs new file mode 100644 index 0000000000..d944e3a297 --- /dev/null +++ b/actix-macros/tests/trybuild.rs @@ -0,0 +1,9 @@ +#[test] +fn compile_macros() { + let t = trybuild::TestCases::new(); + t.pass("tests/trybuild/main-01-basic.rs"); + t.compile_fail("tests/trybuild/main-02-only-async.rs"); + + t.pass("tests/trybuild/test-01-basic.rs"); + t.pass("tests/trybuild/test-02-keep-attrs.rs"); +} diff --git a/actix-macros/tests/trybuild/main-01-basic.rs b/actix-macros/tests/trybuild/main-01-basic.rs new file mode 100644 index 0000000000..8bb86a8167 --- /dev/null +++ b/actix-macros/tests/trybuild/main-01-basic.rs @@ -0,0 +1,4 @@ +#[actix_rt::main] +async fn main() { + println!("Hello world"); +} diff --git a/actix-macros/tests/trybuild/main-02-only-async.rs b/actix-macros/tests/trybuild/main-02-only-async.rs new file mode 100644 index 0000000000..2c60c2597c --- /dev/null +++ b/actix-macros/tests/trybuild/main-02-only-async.rs @@ -0,0 +1,4 @@ +#[actix_rt::main] +fn main() { + futures::future::ready(()).await +} diff --git a/actix-macros/tests/trybuild/main-02-only-async.stderr b/actix-macros/tests/trybuild/main-02-only-async.stderr new file mode 100644 index 0000000000..6f71caef18 --- /dev/null +++ b/actix-macros/tests/trybuild/main-02-only-async.stderr @@ -0,0 +1,14 @@ +error: only async fn is supported + --> $DIR/main-02-only-async.rs:2:1 + | +2 | fn main() { + | ^^ + +error[E0601]: `main` function not found in crate `$CRATE` + --> $DIR/main-02-only-async.rs:1:1 + | +1 | / #[actix_rt::main] +2 | | fn main() { +3 | | futures::future::ready(()).await +4 | | } + | |_^ consider adding a `main` function to `$DIR/tests/trybuild/main-02-only-async.rs` diff --git a/actix-macros/tests/trybuild/test-01-basic.rs b/actix-macros/tests/trybuild/test-01-basic.rs new file mode 100644 index 0000000000..8339a96924 --- /dev/null +++ b/actix-macros/tests/trybuild/test-01-basic.rs @@ -0,0 +1,6 @@ +#[actix_rt::test] +async fn my_test() { + assert!(true); +} + +fn main() {} diff --git a/actix-macros/tests/trybuild/test-02-keep-attrs.rs b/actix-macros/tests/trybuild/test-02-keep-attrs.rs new file mode 100644 index 0000000000..22c98d550c --- /dev/null +++ b/actix-macros/tests/trybuild/test-02-keep-attrs.rs @@ -0,0 +1,7 @@ +#[actix_rt::test] +#[should_panic] +async fn my_test() { + todo!() +} + +fn main() {} diff --git a/string/src/lib.rs b/string/src/lib.rs index fbc1bf4cdf..7695c6fce4 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -1,10 +1,11 @@ -//! A utl-8 encoded read-only string with Bytes as a storage. +//! A UTF-8 encoded read-only string using Bytes as storage. + use std::convert::TryFrom; use std::{borrow, fmt, hash, ops, str}; use bytes::Bytes; -/// A utf-8 encoded string with [`Bytes`] as a storage. +/// A UTF-8 encoded string with [`Bytes`] as a storage. /// /// [`Bytes`]: https://docs.rs/bytes/0.5.3/bytes/struct.Bytes.html #[derive(Clone, Eq, Ord, PartialOrd, Default)]