mirror of https://github.com/fafhrd91/actix-web
test: Add trybuild tests for codegen visibility
This commit is contained in:
parent
1613f830e6
commit
b2cc95292d
|
@ -6,6 +6,9 @@ fn compile_macros() {
|
||||||
t.pass("tests/trybuild/simple.rs");
|
t.pass("tests/trybuild/simple.rs");
|
||||||
t.compile_fail("tests/trybuild/simple-fail.rs");
|
t.compile_fail("tests/trybuild/simple-fail.rs");
|
||||||
|
|
||||||
|
t.pass("tests/trybuild/visibility-ok.rs");
|
||||||
|
t.compile_fail("tests/trybuild/visibility-fail.rs");
|
||||||
|
|
||||||
t.pass("tests/trybuild/route-ok.rs");
|
t.pass("tests/trybuild/route-ok.rs");
|
||||||
t.compile_fail("tests/trybuild/route-missing-method-fail.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-duplicate-method-fail.rs");
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
use actix_web::App;
|
||||||
|
|
||||||
|
mod config {
|
||||||
|
use actix_web_codegen::*;
|
||||||
|
use actix_web::{Responder, HttpResponse};
|
||||||
|
|
||||||
|
#[get("/config")]
|
||||||
|
async fn config() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = actix_test::start(|| App::new().service(config::config));
|
||||||
|
|
||||||
|
let request = srv.get("/config");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0603]: unit struct `config` is private
|
||||||
|
--> tests/trybuild/visibility-fail.rs:15:63
|
||||||
|
|
|
||||||
|
15 | let srv = actix_test::start(|| App::new().service(config::config));
|
||||||
|
| ^^^^^^ private unit struct
|
||||||
|
|
|
||||||
|
note: the unit struct `config` is defined here
|
||||||
|
--> tests/trybuild/visibility-fail.rs:7:5
|
||||||
|
|
|
||||||
|
7 | #[get("/config")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
= note: this error originates in the attribute macro `get` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -0,0 +1,20 @@
|
||||||
|
use actix_web::App;
|
||||||
|
|
||||||
|
mod config {
|
||||||
|
use actix_web_codegen::*;
|
||||||
|
use actix_web::{Responder, HttpResponse};
|
||||||
|
|
||||||
|
#[get("/config")]
|
||||||
|
pub async fn config() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = actix_test::start(|| App::new().service(config::config));
|
||||||
|
|
||||||
|
let request = srv.get("/config");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
Loading…
Reference in New Issue