Add trybuild tests for axum-debug (#501)

The things are also covered by the doc tests but this also gives us
assertions on the errors produced, which is the whole point of this
crate :)
This commit is contained in:
David Pedersen
2021-11-11 20:26:08 +00:00
committed by GitHub
parent 26faf0d7a6
commit c7b8813c47
18 changed files with 246 additions and 72 deletions
View File
@@ -0,0 +1,6 @@
use axum_debug::debug_handler;
#[debug_handler]
async fn handler(foo: bool) {}
fn main() {}
@@ -0,0 +1,11 @@
error[E0277]: the trait bound `bool: FromRequest` is not satisfied
--> tests/fail/argument_not_extractor.rs:4:23
|
4 | async fn handler(foo: bool) {}
| ^^^^ the trait `FromRequest` is not implemented for `bool`
|
note: required by a bound in `handler::{closure#0}::debug_handler`
--> tests/fail/argument_not_extractor.rs:4:23
|
4 | async fn handler(foo: bool) {}
| ^^^^ required by this bound in `handler::{closure#0}::debug_handler`
+6
View File
@@ -0,0 +1,6 @@
use axum_debug::debug_handler;
#[debug_handler]
struct A;
fn main() {}
@@ -0,0 +1,5 @@
error: expected `fn`
--> tests/fail/not_a_function.rs:4:1
|
4 | struct A;
| ^^^^^^
+6
View File
@@ -0,0 +1,6 @@
use axum_debug::debug_handler;
#[debug_handler]
fn handler() {}
fn main() {}
+5
View File
@@ -0,0 +1,5 @@
error: handlers must be async functions
--> tests/fail/not_async.rs:4:1
|
4 | fn handler() {}
| ^^
+9
View File
@@ -0,0 +1,9 @@
use axum_debug::debug_handler;
#[debug_handler]
async fn handler() {
let rc = std::rc::Rc::new(());
async {}.await;
}
fn main() {}
+21
View File
@@ -0,0 +1,21 @@
error: future cannot be sent between threads safely
--> tests/fail/not_send.rs:4:10
|
4 | async fn handler() {
| ^^^^^^^ future returned by `handler` is not `Send`
|
= help: within `impl Future`, the trait `Send` is not implemented for `Rc<()>`
note: future is not `Send` as this value is used across an await
--> tests/fail/not_send.rs:6:5
|
5 | let rc = std::rc::Rc::new(());
| -- has type `Rc<()>` which is not `Send`
6 | async {}.await;
| ^^^^^^^^^^^^^^ await occurs here, with `rc` maybe used later
7 | }
| - `rc` is later dropped here
note: required by a bound in `handler::{closure#0}::debug_handler`
--> tests/fail/not_send.rs:4:10
|
4 | async fn handler() {
| ^^^^^^^ required by this bound in `handler::{closure#0}::debug_handler`
+20
View File
@@ -0,0 +1,20 @@
use axum_debug::debug_handler;
use axum::{async_trait, extract::{FromRequest, RequestParts}};
struct A;
#[async_trait]
impl FromRequest for A {
type Rejection = ();
async fn from_request(_req: &mut RequestParts) -> Result<Self, Self::Rejection> {
unimplemented!()
}
}
impl A {
#[debug_handler]
async fn handler(self) {}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `#[debug_handler]` is not supported on methods
--> tests/fail/self_receiver.rs:17:22
|
17 | async fn handler(self) {}
| ^^^^
@@ -0,0 +1,24 @@
use axum_debug::debug_handler;
#[debug_handler]
async fn handler(
e1: String,
e2: String,
e3: String,
e4: String,
e5: String,
e6: String,
e7: String,
e8: String,
e9: String,
e10: String,
e11: String,
e12: String,
e13: String,
e14: String,
e15: String,
e16: String,
e17: String,
) {}
fn main() {}
@@ -0,0 +1,12 @@
error: too many extractors. 16 extractors are allowed
note: you can nest extractors like "a: (Extractor, Extractor), b: (Extractor, Extractor)"
--> tests/fail/too_many_extractors.rs:5:5
|
5 | / e1: String,
6 | | e2: String,
7 | | e3: String,
8 | | e4: String,
... |
20 | | e16: String,
21 | | e17: String,
| |________________^
@@ -0,0 +1,8 @@
use axum_debug::debug_handler;
#[debug_handler]
async fn handler() -> bool {
false
}
fn main() {}
@@ -0,0 +1,11 @@
error[E0277]: the trait bound `bool: IntoResponse` is not satisfied
--> tests/fail/wrong_return_type.rs:4:23
|
4 | async fn handler() -> bool {
| ^^^^ the trait `IntoResponse` is not implemented for `bool`
|
note: required by a bound in `handler::{closure#0}::debug_handler`
--> tests/fail/wrong_return_type.rs:4:23
|
4 | async fn handler() -> bool {
| ^^^^ required by this bound in `handler::{closure#0}::debug_handler`