1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

add trybuild tests for OpenapiType and Resource derive macros

This commit is contained in:
Dominic 2020-05-09 15:29:29 +02:00
parent 9ed24c9bcb
commit 6680887b84
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
16 changed files with 149 additions and 3 deletions

View file

@ -0,0 +1,14 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
enum Food
{
Pasta,
Pizza { pineapple : bool },
Rice,
Other(String)
}
fn main()
{
}

View file

@ -0,0 +1,11 @@
error: #[derive(OpenapiType)] does not support enum variants with fields
--> $DIR/openapi_type_enum_with_fields.rs:7:2
|
7 | Pizza { pineapple : bool },
| ^^^^^
error: #[derive(OpenapiType)] does not support enum variants with fields
--> $DIR/openapi_type_enum_with_fields.rs:9:2
|
9 | Other(String)
| ^^^^^

View file

@ -0,0 +1,12 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo
{
#[openapi(nullable = "yes, please")]
bar : String
}
fn main()
{
}

View file

@ -0,0 +1,5 @@
error: Expected bool
--> $DIR/openapi_type_nullable_non_bool.rs:6:23
|
6 | #[openapi(nullable = "yes, please")]
| ^^^^^^^^^^^^^

View file

@ -0,0 +1,12 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo
{
#[openapi(rename = 42)]
bar : String
}
fn main()
{
}

View file

@ -0,0 +1,5 @@
error: Expected string literal
--> $DIR/openapi_type_rename_non_string.rs:6:21
|
6 | #[openapi(rename = 42)]
| ^^

View file

@ -0,0 +1,8 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo(String);
fn main()
{
}

View file

@ -0,0 +1,5 @@
error: #[derive(OpenapiType)] does not support unnamed fields
--> $DIR/openapi_type_tuple_struct.rs:4:11
|
4 | struct Foo(String);
| ^^^^^^^^

View file

@ -0,0 +1,12 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
union IntOrPointer
{
int: u64,
pointer: *mut String
}
fn main()
{
}

View file

@ -0,0 +1,5 @@
error: #[derive(OpenapiType)] only works for structs and enums
--> $DIR/openapi_type_union.rs:4:1
|
4 | union IntOrPointer
| ^^^^^

View file

@ -0,0 +1,12 @@
#[macro_use] extern crate gotham_restful;
#[derive(OpenapiType)]
struct Foo
{
#[openapi(like = "pizza")]
bar : String
}
fn main()
{
}

View file

@ -0,0 +1,5 @@
error: Unknown key
--> $DIR/openapi_type_unknown_key.rs:6:12
|
6 | #[openapi(like = "pizza")]
| ^^^^

View file

@ -0,0 +1,14 @@
#[macro_use] extern crate gotham_restful;
#[derive(Resource)]
#[resource(read_any)]
struct FooResource;
#[read_all(FooResource)]
fn read_all()
{
}
fn main()
{
}

View file

@ -0,0 +1,14 @@
error: Unknown method: `read_any'
--> $DIR/resource_unknown_method.rs:4:12
|
4 | #[resource(read_any)]
| ^^^^^^^^
error[E0277]: the trait bound `FooResource: gotham_restful::Resource` is not satisfied
--> $DIR/resource_unknown_method.rs:7:1
|
7 | #[read_all(FooResource)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `gotham_restful::Resource` is not implemented for `FooResource`
|
= help: see issue #48214
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)