Skip to content

Commit

Permalink
fmt; move compile fail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Sep 28, 2024
1 parent d37b93e commit f7a5c0a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 2 deletions.
5 changes: 4 additions & 1 deletion sea-query-attr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sea-query-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
8 changes: 8 additions & 0 deletions sea-query-derive/tests/compile-fail/enum_def/enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use sea_query_derive::enum_def;

#[enum_def]
enum Hello {
Name,
}

fn main() {}
5 changes: 5 additions & 0 deletions sea-query-derive/tests/compile-fail/enum_def/enum.stderr
Original file line number Diff line number Diff line change
@@ -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 {
| ^^^^
6 changes: 6 additions & 0 deletions sea-query-derive/tests/compile-fail/enum_def/tuple_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use sea_query_derive::enum_def;

#[enum_def]
struct Hello(String);

fn main() {}
Original file line number Diff line number Diff line change
@@ -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);
| ^^^^^^
8 changes: 8 additions & 0 deletions sea-query-derive/tests/compile-fail/enum_def/unknown_field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use sea_query_derive::enum_def;

#[enum_def(unknown_field)]
pub struct Hello {
pub name: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Unknown field: `unknown_field`
--> tests/compile-fail/enum_def/unknown_field.rs:3:12
|
3 | #[enum_def(unknown_field)]
| ^^^^^^^^^^^^^
1 change: 1 addition & 0 deletions sea-query-derive/tests/test_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit f7a5c0a

Please sign in to comment.