cfail tests for derive

This commit is contained in:
Steven Fackler
2019-10-10 15:21:45 -07:00
parent 218d889042
commit e69f1583c8
8 changed files with 101 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
use postgres_types::{FromSql, ToSql};
#[derive(ToSql)]
struct ToSqlUnit;
#[derive(FromSql)]
struct FromSqlUnit;
#[derive(ToSql)]
struct ToSqlTuple(i32, i32);
#[derive(FromSql)]
struct FromSqlTuple(i32, i32);
#[derive(ToSql)]
enum ToSqlEnum {
Foo(i32),
}
#[derive(FromSql)]
enum FromSqlEnum {
Foo(i32),
}
fn main() {}

View File

@@ -0,0 +1,35 @@
error: #[derive(ToSql)] may only be applied to structs, single field tuple structs, and enums
--> $DIR/invalid-types.rs:4:1
|
4 | struct ToSqlUnit;
| ^^^^^^^^^^^^^^^^^
error: #[derive(FromSql)] may only be applied to structs, single field tuple structs, and enums
--> $DIR/invalid-types.rs:7:1
|
7 | struct FromSqlUnit;
| ^^^^^^^^^^^^^^^^^^^
error: #[derive(ToSql)] may only be applied to structs, single field tuple structs, and enums
--> $DIR/invalid-types.rs:10:1
|
10 | struct ToSqlTuple(i32, i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: #[derive(FromSql)] may only be applied to structs, single field tuple structs, and enums
--> $DIR/invalid-types.rs:13:1
|
13 | struct FromSqlTuple(i32, i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: non-C-like enums are not supported
--> $DIR/invalid-types.rs:17:5
|
17 | Foo(i32),
| ^^^^^^^^
error: non-C-like enums are not supported
--> $DIR/invalid-types.rs:22:5
|
22 | Foo(i32),
| ^^^^^^^^

View File

@@ -0,0 +1,15 @@
use postgres_types::{FromSql, ToSql};
#[derive(FromSql)]
#[postgres(foo = "bar")]
struct Foo {
a: i32,
}
#[derive(ToSql)]
#[postgres(foo = "bar")]
struct Bar {
a: i32,
}
fn main() {}

View File

@@ -0,0 +1,11 @@
error: unknown override
--> $DIR/unknown-override.rs:4:12
|
4 | #[postgres(foo = "bar")]
| ^^^
error: unknown override
--> $DIR/unknown-override.rs:10:12
|
10 | #[postgres(foo = "bar")]
| ^^^

View File

@@ -25,3 +25,8 @@ where
assert_eq!(val, &result);
}
}
#[test]
fn compile_fail() {
trybuild::TestCases::new().compile_fail("src/compile-fail/*.rs");
}