Skip to content

Commit c8e7324

Browse files
committed
Add test-suite for failure modes
Also, discover that apparently `momo` isn't effective where it should be *or* the implementation is more complex.
1 parent c4ed7c1 commit c8e7324

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

Cargo.lock

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-macros/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ proc_macro = true
2020
syn = { version = "2.0", features = ["full", "fold"] }
2121
quote = "1.0"
2222
proc-macro2 = "1.0"
23+
24+
[dev-dependencies]
25+
trybuild = "1.0"

gix-macros/src/momo.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ pub(crate) fn inner(code: proc_macro2::TokenStream) -> proc_macro2::TokenStream
1111

1212
if let Item::Fn(item_fn) = fn_item {
1313
let ty_conversions = parse_generics(&item_fn.sig);
14+
// TODO: uncomment and see it fail in places where it should actually succeed.
15+
// if ty_conversions.is_empty() {
16+
// return Error::new(
17+
// item_fn.span(),
18+
// "Couldn't apply a single conversion - momo is ineffective here",
19+
// )
20+
// .to_compile_error();
21+
// }
1422
let (argtypes, argexprs, has_self) = convert(&item_fn.sig.inputs, &ty_conversions);
1523

1624
let uses_self = has_self

gix-macros/tests/momo/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,16 @@ fn struct_fn() {
302302
)
303303
.unwrap_err();
304304
}
305+
306+
#[test]
307+
fn ux() {
308+
let t = trybuild::TestCases::new();
309+
t.compile_fail("tests/momo/ux/error_on_struct.rs");
310+
}
311+
312+
#[test]
313+
#[ignore = "needs work"]
314+
fn ux_todo() {
315+
let t = trybuild::TestCases::new();
316+
t.compile_fail("tests/momo/ux/error_if_ineffective.rs");
317+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// If nothing is done, momo should fail.
2+
#[gix_macros::momo]
3+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {}
2+
3+
/// Only functions work with momo
4+
#[gix_macros::momo]
5+
struct S;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: expect a function
2+
--> tests/momo/ux/error_on_struct.rs:3:1
3+
|
4+
3 | /// Only functions work with momo
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)