forked from actix/actix-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add trybuild tests to routing codegen (actix#1677)
- Loading branch information
Showing
8 changed files
with
110 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
# Helper and convenience macros for Actix-web. [](https://travis-ci.org/actix/actix-web) [](https://codecov.io/gh/actix/actix-web) [](https://crates.io/crates/actix-web-codegen) [](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
# actix-web-codegen | ||
|
||
> Helper and convenience macros for Actix Web | ||
[](https://crates.io/crates/actix-web-codegen) | ||
[](https://docs.rs/actix-web) | ||
[](https://blog.rust-lang.org/2020/03/12/Rust-1.42.html) | ||
[](https://travis-ci.org/actix/actix-web) | ||
[](https://codecov.io/gh/actix/actix-web) | ||
[](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
|
||
## Documentation & Resources | ||
|
||
* [API Documentation](https://docs.rs/actix-web-codegen/) | ||
* [Chat on gitter](https://gitter.im/actix/actix) | ||
* Cargo package: [actix-web-codegen](https://crates.io/crates/actix-web-codegen) | ||
* Minimum supported Rust version: 1.40 or later | ||
- [API Documentation](https://docs.rs/actix-web-codegen) | ||
- [Chat on Gitter](https://gitter.im/actix/actix-web) | ||
- Cargo package: [actix-web-codegen](https://crates.io/crates/actix-web-codegen) | ||
- Minimum supported Rust version: 1.42 or later. | ||
|
||
## Compile Testing | ||
Uses the [`trybuild`] crate. All compile fail tests should include a stderr file generated by `trybuild`. See the [workflow section](https://github.com/dtolnay/trybuild#workflow) of the trybuild docs for info on how to do this. | ||
|
||
[`trybuild`]: https://github.com/dtolnay/trybuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#[test] | ||
fn compile_macros() { | ||
let t = trybuild::TestCases::new(); | ||
|
||
t.pass("tests/trybuild/simple.rs"); | ||
t.compile_fail("tests/trybuild/simple-fail.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use actix_web::*; | ||
|
||
#[get("/one", other)] | ||
async fn one() -> impl Responder { | ||
HttpResponse::Ok() | ||
} | ||
|
||
#[post(/two)] | ||
async fn two() -> impl Responder { | ||
HttpResponse::Ok() | ||
} | ||
|
||
static PATCH_PATH: &str = "/three"; | ||
|
||
#[patch(PATCH_PATH)] | ||
async fn three() -> impl Responder { | ||
HttpResponse::Ok() | ||
} | ||
|
||
#[delete("/four", "/five")] | ||
async fn four() -> impl Responder { | ||
HttpResponse::Ok() | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: Unknown attribute. | ||
--> $DIR/simple-fail.rs:3:15 | ||
| | ||
3 | #[get("/one", other)] | ||
| ^^^^^ | ||
|
||
error: expected identifier or literal | ||
--> $DIR/simple-fail.rs:8:8 | ||
| | ||
8 | #[post(/two)] | ||
| ^ | ||
|
||
error: Unknown attribute. | ||
--> $DIR/simple-fail.rs:15:9 | ||
| | ||
15 | #[patch(PATCH_PATH)] | ||
| ^^^^^^^^^^ | ||
|
||
error: Multiple paths specified! Should be only one! | ||
--> $DIR/simple-fail.rs:20:19 | ||
| | ||
20 | #[delete("/four", "/five")] | ||
| ^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use actix_web::*; | ||
|
||
#[get("/config")] | ||
async fn config() -> impl Responder { | ||
HttpResponse::Ok() | ||
} | ||
|
||
#[actix_web::main] | ||
async fn main() { | ||
let srv = test::start(|| App::new().service(config)); | ||
|
||
let request = srv.get("/config"); | ||
let response = request.send().await.unwrap(); | ||
assert!(response.status().is_success()); | ||
} |