From f7a5c0a8ed327fe368541f18ebf282f7ccdd72e1 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 28 Sep 2024 10:12:04 +0100 Subject: [PATCH] fmt; move compile fail tests --- sea-query-attr/src/lib.rs | 5 ++++- sea-query-derive/src/lib.rs | 2 +- sea-query-derive/tests/compile-fail/enum_def/enum.rs | 8 ++++++++ sea-query-derive/tests/compile-fail/enum_def/enum.stderr | 5 +++++ .../tests/compile-fail/enum_def/tuple_struct.rs | 6 ++++++ .../tests/compile-fail/enum_def/tuple_struct.stderr | 5 +++++ .../tests/compile-fail/enum_def/unknown_field.rs | 8 ++++++++ .../tests/compile-fail/enum_def/unknown_field.stderr | 5 +++++ sea-query-derive/tests/test_build.rs | 1 + 9 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 sea-query-derive/tests/compile-fail/enum_def/enum.rs create mode 100644 sea-query-derive/tests/compile-fail/enum_def/enum.stderr create mode 100644 sea-query-derive/tests/compile-fail/enum_def/tuple_struct.rs create mode 100644 sea-query-derive/tests/compile-fail/enum_def/tuple_struct.stderr create mode 100644 sea-query-derive/tests/compile-fail/enum_def/unknown_field.rs create mode 100644 sea-query-derive/tests/compile-fail/enum_def/unknown_field.stderr diff --git a/sea-query-attr/src/lib.rs b/sea-query-attr/src/lib.rs index ef6aa1382..159d62222 100644 --- a/sea-query-attr/src/lib.rs +++ b/sea-query-attr/src/lib.rs @@ -40,7 +40,10 @@ impl Default for GenEnumArgs { } } -#[deprecated(since = "0.1.2", note = "use #[enum_def] attr defined in `sea-query-derive` crate")] +#[deprecated( + since = "0.1.2", + note = "use #[enum_def] attr defined in `sea-query-derive` crate" +)] #[proc_macro_attribute] pub fn enum_def(args: TokenStream, input: TokenStream) -> TokenStream { let args = parse_macro_input!(args with AttributeArgs::parse_terminated); diff --git a/sea-query-derive/src/lib.rs b/sea-query-derive/src/lib.rs index 2f524c7ad..6de24ea8a 100644 --- a/sea-query-derive/src/lib.rs +++ b/sea-query-derive/src/lib.rs @@ -300,7 +300,7 @@ pub fn enum_def(args: TokenStream, input: TokenStream) -> TokenStream { .. }) => &fields.named, _ => return quote_spanned! { - input.span() => compile_error!("you can only derive Iden on enums or unit structs"); + input.span() => compile_error!("#[enum_def] can only be used on non-tuple structs"); } .into(), }; diff --git a/sea-query-derive/tests/compile-fail/enum_def/enum.rs b/sea-query-derive/tests/compile-fail/enum_def/enum.rs new file mode 100644 index 000000000..a693c00af --- /dev/null +++ b/sea-query-derive/tests/compile-fail/enum_def/enum.rs @@ -0,0 +1,8 @@ +use sea_query_derive::enum_def; + +#[enum_def] +enum Hello { + Name, +} + +fn main() {} diff --git a/sea-query-derive/tests/compile-fail/enum_def/enum.stderr b/sea-query-derive/tests/compile-fail/enum_def/enum.stderr new file mode 100644 index 000000000..2905884d2 --- /dev/null +++ b/sea-query-derive/tests/compile-fail/enum_def/enum.stderr @@ -0,0 +1,5 @@ +error: #[enum_def] can only be used on non-tuple structs + --> tests/compile-fail/enum_def/enum.rs:4:1 + | +4 | enum Hello { + | ^^^^ diff --git a/sea-query-derive/tests/compile-fail/enum_def/tuple_struct.rs b/sea-query-derive/tests/compile-fail/enum_def/tuple_struct.rs new file mode 100644 index 000000000..04b8f1957 --- /dev/null +++ b/sea-query-derive/tests/compile-fail/enum_def/tuple_struct.rs @@ -0,0 +1,6 @@ +use sea_query_derive::enum_def; + +#[enum_def] +struct Hello(String); + +fn main() {} diff --git a/sea-query-derive/tests/compile-fail/enum_def/tuple_struct.stderr b/sea-query-derive/tests/compile-fail/enum_def/tuple_struct.stderr new file mode 100644 index 000000000..b64dc25ab --- /dev/null +++ b/sea-query-derive/tests/compile-fail/enum_def/tuple_struct.stderr @@ -0,0 +1,5 @@ +error: #[enum_def] can only be used on non-tuple structs + --> tests/compile-fail/enum_def/tuple_struct.rs:4:1 + | +4 | struct Hello(String); + | ^^^^^^ diff --git a/sea-query-derive/tests/compile-fail/enum_def/unknown_field.rs b/sea-query-derive/tests/compile-fail/enum_def/unknown_field.rs new file mode 100644 index 000000000..abb503953 --- /dev/null +++ b/sea-query-derive/tests/compile-fail/enum_def/unknown_field.rs @@ -0,0 +1,8 @@ +use sea_query_derive::enum_def; + +#[enum_def(unknown_field)] +pub struct Hello { + pub name: String, +} + +fn main() {} diff --git a/sea-query-derive/tests/compile-fail/enum_def/unknown_field.stderr b/sea-query-derive/tests/compile-fail/enum_def/unknown_field.stderr new file mode 100644 index 000000000..18a94181e --- /dev/null +++ b/sea-query-derive/tests/compile-fail/enum_def/unknown_field.stderr @@ -0,0 +1,5 @@ +error: Unknown field: `unknown_field` + --> tests/compile-fail/enum_def/unknown_field.rs:3:12 + | +3 | #[enum_def(unknown_field)] + | ^^^^^^^^^^^^^ diff --git a/sea-query-derive/tests/test_build.rs b/sea-query-derive/tests/test_build.rs index f166a98d4..cc1bfed9e 100644 --- a/sea-query-derive/tests/test_build.rs +++ b/sea-query-derive/tests/test_build.rs @@ -2,6 +2,7 @@ fn build_tests() { let t = trybuild::TestCases::new(); t.compile_fail("./tests/compile-fail/*.rs"); + t.compile_fail("./tests/compile-fail/enum_def/*.rs"); // all of these are exactly the same as the examples in `examples/derive.rs` t.pass("./tests/pass/*.rs");