Add trybuild tests for route macro

This commit is contained in:
Matt Gathu 2020-09-13 18:20:23 +02:00
parent 7760f46a08
commit 5801cb945d
8 changed files with 98 additions and 0 deletions

View File

@ -4,4 +4,9 @@ fn compile_macros() {
t.pass("tests/trybuild/simple.rs");
t.compile_fail("tests/trybuild/simple-fail.rs");
t.pass("tests/trybuild/route-ok.rs");
t.compile_fail("tests/trybuild/route-missing-method-fail.rs");
t.compile_fail("tests/trybuild/route-duplicate-method-fail.rs");
t.compile_fail("tests/trybuild/route-unexpected-method-fail.rs");
}

View File

@ -0,0 +1,15 @@
use actix_web::*;
#[route("/", method="GET", method="GET")]
async fn index() -> impl Responder {
HttpResponse::Ok()
}
#[actix_web::main]
async fn main() {
let srv = test::start(|| App::new().service(index));
let request = srv.get("/");
let response = request.send().await.unwrap();
assert!(response.status().is_success());
}

View File

@ -0,0 +1,11 @@
error: HTTP Method defined more than once: `GET`
--> $DIR/route-duplicate-method-fail.rs:3:35
|
3 | #[route("/", method="GET", method="GET")]
| ^^^^^
error[E0425]: cannot find value `index` in this scope
--> $DIR/route-duplicate-method-fail.rs:10:49
|
10 | let srv = test::start(|| App::new().service(index));
| ^^^^^ not found in this scope

View File

@ -0,0 +1,15 @@
use actix_web::*;
#[route("/")]
async fn index() -> impl Responder {
HttpResponse::Ok()
}
#[actix_web::main]
async fn main() {
let srv = test::start(|| App::new().service(index));
let request = srv.get("/");
let response = request.send().await.unwrap();
assert!(response.status().is_success());
}

View File

@ -0,0 +1,11 @@
error: The #[route(..)] macro requires at least one `method` attribute
--> $DIR/route-missing-method-fail.rs:3:1
|
3 | #[route("/")]
| ^^^^^^^^^^^^^
error[E0425]: cannot find value `index` in this scope
--> $DIR/route-missing-method-fail.rs:10:49
|
10 | let srv = test::start(|| App::new().service(index));
| ^^^^^ not found in this scope

View File

@ -0,0 +1,15 @@
use actix_web::*;
#[route("/", method="GET", method="HEAD")]
async fn index() -> impl Responder {
HttpResponse::Ok()
}
#[actix_web::main]
async fn main() {
let srv = test::start(|| App::new().service(index));
let request = srv.get("/");
let response = request.send().await.unwrap();
assert!(response.status().is_success());
}

View File

@ -0,0 +1,15 @@
use actix_web::*;
#[route("/", method="UNEXPECTED")]
async fn index() -> impl Responder {
HttpResponse::Ok()
}
#[actix_web::main]
async fn main() {
let srv = test::start(|| App::new().service(index));
let request = srv.get("/");
let response = request.send().await.unwrap();
assert!(response.status().is_success());
}

View File

@ -0,0 +1,11 @@
error: Unexpected HTTP Method: `UNEXPECTED`
--> $DIR/route-unexpected-method-fail.rs:3:21
|
3 | #[route("/", method="UNEXPECTED")]
| ^^^^^^^^^^^^
error[E0425]: cannot find value `index` in this scope
--> $DIR/route-unexpected-method-fail.rs:10:49
|
10 | let srv = test::start(|| App::new().service(index));
| ^^^^^ not found in this scope