Convert several 'compilefail' tests to 'ui' tests.

This commit is contained in:
Sergio Benitez 2017-09-21 18:01:56 -07:00
parent 78cc1bda7e
commit 63169599a7
21 changed files with 479 additions and 132 deletions

View File

@ -164,22 +164,24 @@ pub fn param_to_ident(ecx: &ExtCtxt, s: Spanned<&str>) -> Option<Spanned<Ident>>
} }
fn parse_method(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned<Method> { fn parse_method(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned<Method> {
let valid_methods = "valid methods are: `GET`, `PUT`, `POST`, `DELETE`, `PATCH`";
let default_method = dummy_spanned(Method::Get);
if let Some(word) = meta_item.word() { if let Some(word) = meta_item.word() {
if let Ok(method) = Method::from_str(&word.name().as_str()) { if let Ok(method) = Method::from_str(&word.name().as_str()) {
if is_valid_method(method) { if is_valid_method(method) {
return span(method, word.span()); return span(method, word.span());
} }
} else {
let msg = format!("'{}' is not a valid HTTP method.", word.name());
ecx.span_err(word.span(), &msg);
}
} }
// Fallthrough. Return default method. let msg = format!("'{}' is not a valid method", word.name());
ecx.struct_span_err(meta_item.span, "expected a valid HTTP method") ecx.struct_span_err(word.span, &msg).help(valid_methods).emit();
.help("valid methods are: GET, PUT, POST, DELETE, PATCH") return default_method;
.emit(); }
// Fallthrough. Emit a generic error message and return default method.
let msg = "expected a valid HTTP method identifier";
ecx.struct_span_err(meta_item.span, msg).help(valid_methods).emit();
dummy_spanned(Method::Get) dummy_spanned(Method::Get)
} }

View File

@ -1,23 +1,6 @@
extern crate compiletest_rs as compiletest; mod compiletest;
use std::path::PathBuf;
use compiletest::common::Mode;
fn run_mode(mode: Mode) {
let mut config = compiletest::Config::default();
config.mode = mode;
config.src_base = PathBuf::from(format!("tests/{}", mode));
let flags = [
"-L crate=../target/debug/",
"-L dependency=../target/debug/deps/",
].join(" ");
config.target_rustcflags = Some(flags);
compiletest::run_tests(&config);
}
#[test] #[test]
fn compile_test() { fn compilefail() {
run_mode(Mode::CompileFail); compiletest::run(compiletest::Mode::CompileFail);
} }

View File

@ -1,12 +0,0 @@
#![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)]
extern crate rocket;
use rocket::Data;
#[get("/", data = "<something>")]
//~^ ERROR payload supporting methods
fn get(something: Data) -> &'static str { "hi" }
fn main() { }

View File

@ -1,13 +0,0 @@
#![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[route(FIX, "/hello")] //~ ERROR is not a valid HTTP method
//~^ ERROR valid HTTP method
fn get() -> &'static str { "hi" }
fn main() {
let _ = routes![get];
}

View File

@ -1,12 +0,0 @@
#![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[route(CONNECT, "/hello")] //~ ERROR valid HTTP method
fn get() -> &'static str { "hi" }
fn main() {
let _ = routes![get];
}

View File

@ -1,30 +0,0 @@
#![feature(plugin, decl_macro, custom_derive)]
#![plugin(rocket_codegen)]
#![allow(dead_code, unused_variables)]
extern crate rocket;
use std::fmt;
use rocket::http::Cookies;
#[post("/<id>")]
fn simple(id: i32) -> &'static str { "" }
#[post("/<id>")]
fn guard_1(cookies: Cookies, id: i32) -> &'static str { "" }
fn main() {
uri!(simple); //~ ERROR expects 1 parameter but 0 were supplied
uri!(simple: 1, 23); //~ ERROR expects 1 parameter but 2 were supplied
uri!(simple: "Hello", 23, ); //~ ERROR expects 1 parameter but 2 were supplied
uri!(guard_1: "hi", 100); //~ ERROR expects 1 parameter but 2 were supplied
uri!(simple: id = 100, name = "hi"); //~ ERROR invalid parameters
uri!(simple: id = 100, id = 100); //~ ERROR invalid parameters
uri!(simple: name = 100, id = 100); //~ ERROR invalid parameters
uri!(simple: id = 100, id = 100, ); //~ ERROR invalid parameters
uri!(simple: name = "hi"); //~ ERROR invalid parameters
uri!(guard_1: cookies = "hi", id = 100); //~ ERROR invalid parameters
uri!(guard_1: id = 100, cookies = "hi"); //~ ERROR invalid parameters
}

View File

@ -1,22 +0,0 @@
#![feature(plugin, decl_macro, custom_derive)]
#![plugin(rocket_codegen)]
#![allow(dead_code, unused_variables)]
extern crate rocket;
#[post("/<id>/<name>")]
fn simple(id: i32, name: String) -> &'static str { "" }
fn main() {
uri!(simple: id = 100, "Hello"); //~ ERROR cannot be mixed
uri!(simple: "Hello", id = 100); //~ ERROR cannot be mixed
uri!(simple,); //~ ERROR expected one of `::`, `:`, or `<eof>`
uri!(simple:); //~ ERROR expected argument list
uri!("/mount"); //~ ERROR expected `,`, found `<eof>`
uri!("/mount",); //~ ERROR expected identifier
uri!("mount", simple); //~ ERROR invalid mount point
uri!("/mount/<id>", simple); //~ ERROR invalid mount point
uri!(); //~ ERROR cannot be empty
uri!(simple: id = ); //~ ERROR expected argument list
//~^ ERROR expected expression
}

View File

@ -0,0 +1,20 @@
extern crate compiletest_rs;
use std::path::PathBuf;
pub use self::compiletest_rs::common::Mode;
pub use self::compiletest_rs::{Config, run_tests};
pub fn run(mode: Mode) {
let mut config = Config::default();
config.mode = mode;
config.src_base = PathBuf::from(format!("tests/{}", mode));
let flags = [
"-L crate=../target/debug/",
"-L dependency=../target/debug/deps/",
].join(" ");
config.target_rustcflags = Some(flags);
run_tests(&config);
}

6
codegen/tests/ui.rs Normal file
View File

@ -0,0 +1,6 @@
mod compiletest;
#[test]
fn ui() {
compiletest::run(compiletest::Mode::Ui);
}

View File

@ -0,0 +1,7 @@
#![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[get("/", data = "<something>")]
fn get(something: rocket::Data) -> &'static str { "hi" }

View File

@ -0,0 +1,10 @@
error: `data` route parameters can only be used with payload supporting methods
--> $DIR/data-without-post.rs:6:12
|
6 | #[get("/", data = "<something>")]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: 'GET' does not support payloads
error: aborting due to previous error

View File

@ -1,31 +1,29 @@
#![feature(plugin, decl_macro)] #![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)] #![plugin(rocket_codegen)]
#[get("/><")] //~ ERROR malformed #[get("/><")]
fn get() -> &'static str { "hi" } fn get() -> &'static str { "hi" }
#[get("/<id><")] //~ ERROR malformed #[get("/<id><")]
fn get1(id: usize) -> &'static str { "hi" } fn get1(id: usize) -> &'static str { "hi" }
#[get("/<<<<id><")] //~ ERROR malformed #[get("/<<<<id><")]
fn get2(id: usize) -> &'static str { "hi" } fn get2(id: usize) -> &'static str { "hi" }
#[get("/<!>")] //~ ERROR identifiers #[get("/<!>")]
fn get3() -> &'static str { "hi" } fn get3() -> &'static str { "hi" }
#[get("/<_>")] //~ ERROR named #[get("/<_>")]
fn get4() -> &'static str { "hi" } fn get4() -> &'static str { "hi" }
#[get("/<1>")] //~ ERROR identifiers #[get("/<1>")]
fn get5() -> &'static str { "hi" } fn get5() -> &'static str { "hi" }
#[get("/<>name><")] //~ ERROR malformed #[get("/<>name><")]
fn get6() -> &'static str { "hi" } fn get6() -> &'static str { "hi" }
#[get("/<name>:<id>")] //~ ERROR identifiers #[get("/<name>:<id>")]
fn get7() -> &'static str { "hi" } fn get7() -> &'static str { "hi" }
#[get("/<>")] //~ ERROR empty #[get("/<>")]
fn get8() -> &'static str { "hi" } fn get8() -> &'static str { "hi" }
fn main() { }

View File

@ -0,0 +1,72 @@
error: malformed parameter
--> $DIR/malformed-param-list.rs:4:9
|
4 | #[get("/><")]
| ^^
|
= help: parameters must be of the form '<param>'
error: malformed parameter
--> $DIR/malformed-param-list.rs:7:9
|
7 | #[get("/<id><")]
| ^^^^^
|
= help: parameters must be of the form '<param>'
error: malformed parameter
--> $DIR/malformed-param-list.rs:10:9
|
10 | #[get("/<<<<id><")]
| ^^^^^^^^
|
= help: parameters must be of the form '<param>'
error: parameter names must be valid identifiers
--> $DIR/malformed-param-list.rs:13:9
|
13 | #[get("/<!>")]
| ^^^
|
= note: "!" is not a valid identifier
error: parameters must be named
--> $DIR/malformed-param-list.rs:16:9
|
16 | #[get("/<_>")]
| ^^^
|
= help: use a name such as `_guard` or `_param`
error: parameter names must be valid identifiers
--> $DIR/malformed-param-list.rs:19:9
|
19 | #[get("/<1>")]
| ^^^
|
= note: "1" is not a valid identifier
error: malformed parameter
--> $DIR/malformed-param-list.rs:22:9
|
22 | #[get("/<>name><")]
| ^^^^^^^^
|
= help: parameters must be of the form '<param>'
error: parameter names must be valid identifiers
--> $DIR/malformed-param-list.rs:25:9
|
25 | #[get("/<name>:<id>")]
| ^^^^^^^^^^^
|
= note: "name>:<id" is not a valid identifier
error: parameters cannot be empty
--> $DIR/malformed-param-list.rs:28:9
|
28 | #[get("/<>")]
| ^^
error: aborting due to 9 previous errors

View File

@ -0,0 +1,19 @@
#![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[route(FIX, "/hello")]
fn get1() -> &'static str { "hi" }
#[route("hi", "/hello")]
fn get2() -> &'static str { "hi" }
#[route("GET", "/hello")]
fn get3() -> &'static str { "hi" }
#[route(120, "/hello")]
fn get4() -> &'static str { "hi" }
#[route(CONNECT, "/hello")]
fn get5() -> &'static str { "hi" }

View File

@ -0,0 +1,42 @@
error: 'FIX' is not a valid method
--> $DIR/route-bad-method.rs:6:9
|
6 | #[route(FIX, "/hello")]
| ^^^
|
= help: valid methods are: `GET`, `PUT`, `POST`, `DELETE`, `PATCH`
error: expected a valid HTTP method identifier
--> $DIR/route-bad-method.rs:9:9
|
9 | #[route("hi", "/hello")]
| ^^^^
|
= help: valid methods are: `GET`, `PUT`, `POST`, `DELETE`, `PATCH`
error: expected a valid HTTP method identifier
--> $DIR/route-bad-method.rs:12:9
|
12 | #[route("GET", "/hello")]
| ^^^^^
|
= help: valid methods are: `GET`, `PUT`, `POST`, `DELETE`, `PATCH`
error: expected a valid HTTP method identifier
--> $DIR/route-bad-method.rs:15:9
|
15 | #[route(120, "/hello")]
| ^^^
|
= help: valid methods are: `GET`, `PUT`, `POST`, `DELETE`, `PATCH`
error: 'CONNECT' is not a valid method
--> $DIR/route-bad-method.rs:18:9
|
18 | #[route(CONNECT, "/hello")]
| ^^^^^^^
|
= help: valid methods are: `GET`, `PUT`, `POST`, `DELETE`, `PATCH`
error: aborting due to 5 previous errors

View File

@ -25,11 +25,7 @@ fn not_uri_display_but_unused(id: i32, name: S) -> &'static str { "" }
fn main() { fn main() {
uri!(simple: id = "hi"); uri!(simple: id = "hi");
//~^ ERROR trait bound `i32: rocket::http::uri::FromUriParam<&str>` is not satisfied
uri!(simple: "hello"); uri!(simple: "hello");
//~^ ERROR trait bound `i32: rocket::http::uri::FromUriParam<&str>` is not satisfied
uri!(simple: id = 239239i64); uri!(simple: id = 239239i64);
//~^ ERROR trait bound `i32: rocket::http::uri::FromUriParam<i64>` is not satisfied
uri!(not_uri_display: 10, S); uri!(not_uri_display: 10, S);
//~^ ERROR trait bound `S: rocket::http::uri::FromUriParam<_>` is not satisfied
} }

View File

@ -0,0 +1,32 @@
error[E0277]: the trait bound `i32: rocket::http::uri::FromUriParam<&str>` is not satisfied
--> $DIR/typed-uri-bad-type.rs:27:23
|
27 | uri!(simple: id = "hi");
| ^^^^ the trait `rocket::http::uri::FromUriParam<&str>` is not implemented for `i32`
|
= note: required by `rocket::http::uri::FromUriParam::from_uri_param`
error[E0277]: the trait bound `i32: rocket::http::uri::FromUriParam<&str>` is not satisfied
--> $DIR/typed-uri-bad-type.rs:28:18
|
28 | uri!(simple: "hello");
| ^^^^^^^ the trait `rocket::http::uri::FromUriParam<&str>` is not implemented for `i32`
|
= note: required by `rocket::http::uri::FromUriParam::from_uri_param`
error[E0277]: the trait bound `i32: rocket::http::uri::FromUriParam<i64>` is not satisfied
--> $DIR/typed-uri-bad-type.rs:29:23
|
29 | uri!(simple: id = 239239i64);
| ^^^^^^^^^ the trait `rocket::http::uri::FromUriParam<i64>` is not implemented for `i32`
|
= note: required by `rocket::http::uri::FromUriParam::from_uri_param`
error[E0277]: the trait bound `S: rocket::http::uri::FromUriParam<_>` is not satisfied
--> $DIR/typed-uri-bad-type.rs:30:31
|
30 | uri!(not_uri_display: 10, S);
| ^ the trait `rocket::http::uri::FromUriParam<_>` is not implemented for `S`
error: aborting due to 4 previous errors

View File

@ -0,0 +1,30 @@
#![feature(plugin, decl_macro, custom_derive)]
#![plugin(rocket_codegen)]
#![allow(dead_code, unused_variables)]
extern crate rocket;
use std::fmt;
use rocket::http::Cookies;
#[post("/<id>")]
fn simple(id: i32) -> &'static str { "" }
#[post("/<id>")]
fn guard_1(cookies: Cookies, id: i32) -> &'static str { "" }
fn main() {
uri!(simple);
uri!(simple: 1, 23);
uri!(simple: "Hello", 23, );
uri!(guard_1: "hi", 100);
uri!(simple: id = 100, name = "hi");
uri!(simple: id = 100, id = 100);
uri!(simple: name = 100, id = 100);
uri!(simple: id = 100, id = 100, );
uri!(simple: name = "hi");
uri!(guard_1: cookies = "hi", id = 100);
uri!(guard_1: id = 100, cookies = "hi");
}

View File

@ -0,0 +1,126 @@
error: `simple` route uri expects 1 parameter but 0 were supplied
--> $DIR/typed-uris-bad-params.rs:18:10
|
18 | uri!(simple);
| ^^^^^^
|
= note: expected parameter: id: i32
error: `simple` route uri expects 1 parameter but 2 were supplied
--> $DIR/typed-uris-bad-params.rs:19:18
|
19 | uri!(simple: 1, 23);
| ^^^^^
|
= note: expected parameter: id: i32
error: `simple` route uri expects 1 parameter but 2 were supplied
--> $DIR/typed-uris-bad-params.rs:20:18
|
20 | uri!(simple: "Hello", 23, );
| ^^^^^^^^^^^^
|
= note: expected parameter: id: i32
error: `guard_1` route uri expects 1 parameter but 2 were supplied
--> $DIR/typed-uris-bad-params.rs:21:19
|
21 | uri!(guard_1: "hi", 100);
| ^^^^^^^^^
|
= note: expected parameter: id: i32
error: invalid parameters for `simple` route uri
--> $DIR/typed-uris-bad-params.rs:23:18
|
23 | uri!(simple: id = 100, name = "hi");
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: uri parameters are: id: i32
help: unknown parameter: `name`
--> $DIR/typed-uris-bad-params.rs:23:28
|
23 | uri!(simple: id = 100, name = "hi");
| ^^^^
error: invalid parameters for `simple` route uri
--> $DIR/typed-uris-bad-params.rs:24:18
|
24 | uri!(simple: id = 100, id = 100);
| ^^^^^^^^^^^^^^^^^^
|
= note: uri parameters are: id: i32
help: duplicate parameter: `id`
--> $DIR/typed-uris-bad-params.rs:24:28
|
24 | uri!(simple: id = 100, id = 100);
| ^^
error: invalid parameters for `simple` route uri
--> $DIR/typed-uris-bad-params.rs:25:18
|
25 | uri!(simple: name = 100, id = 100);
| ^^^^^^^^^^^^^^^^^^^^
|
= note: uri parameters are: id: i32
help: unknown parameter: `name`
--> $DIR/typed-uris-bad-params.rs:25:18
|
25 | uri!(simple: name = 100, id = 100);
| ^^^^
error: invalid parameters for `simple` route uri
--> $DIR/typed-uris-bad-params.rs:26:18
|
26 | uri!(simple: id = 100, id = 100, );
| ^^^^^^^^^^^^^^^^^^^
|
= note: uri parameters are: id: i32
help: duplicate parameter: `id`
--> $DIR/typed-uris-bad-params.rs:26:28
|
26 | uri!(simple: id = 100, id = 100, );
| ^^
error: invalid parameters for `simple` route uri
--> $DIR/typed-uris-bad-params.rs:27:18
|
27 | uri!(simple: name = "hi");
| ^^^^^^^^^^^
|
= note: uri parameters are: id: i32
help: unknown parameter: `name`
--> $DIR/typed-uris-bad-params.rs:27:18
|
27 | uri!(simple: name = "hi");
| ^^^^
= help: missing parameter: `id`
error: invalid parameters for `guard_1` route uri
--> $DIR/typed-uris-bad-params.rs:28:19
|
28 | uri!(guard_1: cookies = "hi", id = 100);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: uri parameters are: id: i32
help: unknown parameter: `cookies`
--> $DIR/typed-uris-bad-params.rs:28:19
|
28 | uri!(guard_1: cookies = "hi", id = 100);
| ^^^^^^^
error: invalid parameters for `guard_1` route uri
--> $DIR/typed-uris-bad-params.rs:29:19
|
29 | uri!(guard_1: id = 100, cookies = "hi");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: uri parameters are: id: i32
help: unknown parameter: `cookies`
--> $DIR/typed-uris-bad-params.rs:29:29
|
29 | uri!(guard_1: id = 100, cookies = "hi");
| ^^^^^^^
error: aborting due to 11 previous errors

View File

@ -0,0 +1,21 @@
#![feature(plugin, decl_macro, custom_derive)]
#![plugin(rocket_codegen)]
#![allow(dead_code, unused_variables)]
extern crate rocket;
#[post("/<id>/<name>")]
fn simple(id: i32, name: String) -> &'static str { "" }
fn main() {
uri!(simple: id = 100, "Hello");
uri!(simple: "Hello", id = 100);
uri!(simple,);
uri!(simple:);
uri!("/mount");
uri!("/mount",);
uri!("mount", simple);
uri!("/mount/<id>", simple);
uri!();
uri!(simple: id = );
}

View File

@ -0,0 +1,72 @@
error: named and unnamed parameters cannot be mixed
--> $DIR/typed-uris-invalid-syntax.rs:11:18
|
11 | uri!(simple: id = 100, "Hello");
| ^^^^^^^^^^^^^^^^^
error: named and unnamed parameters cannot be mixed
--> $DIR/typed-uris-invalid-syntax.rs:12:18
|
12 | uri!(simple: "Hello", id = 100);
| ^^^^^^^^^^^^^^^^^
error: expected one of `::`, `:`, or `<eof>`, found `,`
--> $DIR/typed-uris-invalid-syntax.rs:13:16
|
13 | uri!(simple,);
| ^ expected one of `::`, `:`, or `<eof>` here
error: expected argument list after `:`
--> $DIR/typed-uris-invalid-syntax.rs:14:16
|
14 | uri!(simple:);
| ^
error: expected `,`, found `<eof>`
--> $DIR/typed-uris-invalid-syntax.rs:15:10
|
15 | uri!("/mount");
| ^^^^^^^^
error: expected identifier, found `<eof>`
--> $DIR/typed-uris-invalid-syntax.rs:16:18
|
16 | uri!("/mount",);
| ^
error: invalid mount point
--> $DIR/typed-uris-invalid-syntax.rs:17:10
|
17 | uri!("mount", simple);
| ^^^^^^^
|
= help: mount points must be static, absolute URIs: `/example`
error: invalid mount point
--> $DIR/typed-uris-invalid-syntax.rs:18:10
|
18 | uri!("/mount/<id>", simple);
| ^^^^^^^^^^^^^
|
= help: mount points must be static, absolute URIs: `/example`
error: call to `uri!` cannot be empty
--> $DIR/typed-uris-invalid-syntax.rs:19:5
|
19 | uri!();
| ^^^^^^^
error: expected expression, found `<eof>`
--> $DIR/typed-uris-invalid-syntax.rs:20:21
|
20 | uri!(simple: id = );
| ^
error: expected argument list after `:`
--> $DIR/typed-uris-invalid-syntax.rs:20:21
|
20 | uri!(simple: id = );
| ^
error: aborting due to 11 previous errors