Skip to content

Commit

Permalink
add trybuild compile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Apr 24, 2020
1 parent 9addf1a commit 672316a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions actix-macros/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/wip
7 changes: 5 additions & 2 deletions actix-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,4 +17,8 @@ quote = "1.0.3"
syn = { version = "^1", features = ["full"] }

[dev-dependencies]
actix-rt = { version = "1.0.0" }
actix-rt = "1.0"

futures = "0.3"
compiletest_rs = "0.5"
trybuild = "1"
6 changes: 6 additions & 0 deletions actix-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {

result.into()
}

#[cfg(test)]
mod tests_trybuild;

#[cfg(test)]
mod tests_compiletest;
6 changes: 6 additions & 0 deletions actix-macros/src/tests_compiletest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[test]
fn main_macro() {
// let t = trybuild::TestCases::new();
// t.pass("tests/01-main.rs");
// // t.compile_fail("tests/03-expand-four-errors.rs");
}
9 changes: 9 additions & 0 deletions actix-macros/src/tests_trybuild.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[test]
fn main_macro() {
let t = trybuild::TestCases::new();
t.pass("test-compile/main-01-basic.rs");
t.compile_fail("test-compile/main-02-only-async.rs");

t.pass("test-compile/test-01-basic.rs");
t.pass("test-compile/test-02-keep-attrs.rs");
}
4 changes: 4 additions & 0 deletions actix-macros/test-compile/main-01-basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[actix_rt::main]
async fn main() {
println!("Hello world");
}
4 changes: 4 additions & 0 deletions actix-macros/test-compile/main-02-only-async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[actix_rt::main]
fn main() {
futures::future::ready(()).await
}
14 changes: 14 additions & 0 deletions actix-macros/test-compile/main-02-only-async.stderr
Original file line number Diff line number Diff line change
@@ -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/test-compile/main-02-only-async.rs`
6 changes: 6 additions & 0 deletions actix-macros/test-compile/test-01-basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[actix_rt::test]
async fn my_test() {
assert!(true);
}

fn main() {}
7 changes: 7 additions & 0 deletions actix-macros/test-compile/test-02-keep-attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[actix_rt::test]
#[should_panic]
async fn my_test() {
todo!()
}

fn main() {}

0 comments on commit 672316a

Please sign in to comment.