@@ -46,9 +46,9 @@ pub fn xtest(attrs: TokenStream, item: TokenStream) -> TokenStream {
46
46
let expanded = match input {
47
47
Item :: Mod ( item_mod) => {
48
48
let cfg = if attrs. is_empty ( ) {
49
- quote ! { #[ cfg ( test) ] }
49
+ quote ! { #[ cfg_attr ( test , test) ] }
50
50
} else {
51
- quote ! { #[ cfg( any( test, #attrs) ) ] }
51
+ quote ! { #[ cfg_attr ( test , test ) ] # [ cfg( any( test, #attrs) ) ] }
52
52
} ;
53
53
quote ! {
54
54
#cfg
@@ -57,10 +57,23 @@ pub fn xtest(attrs: TokenStream, item: TokenStream) -> TokenStream {
57
57
} ,
58
58
Item :: Fn ( item_fn) => {
59
59
let cfg_attr = if attrs. is_empty ( ) {
60
- quote ! { #[ cfg( test) ] }
60
+ // export the test if not actually testing
61
+ quote ! { #[ cfg_attr( test, test) ] }
61
62
} else {
62
- quote ! { #[ cfg( any( test, #attrs) ) ] }
63
+ // export the test if the feature is enabled
64
+ quote ! { #[ cfg_attr( test, test) ] #[ cfg( any( test, #attrs) ) ] }
63
65
} ;
66
+
67
+ // Check that the function doesn't take args and returns nothing
68
+ if !item_fn. sig . inputs . is_empty ( ) || !matches ! ( item_fn. sig. output, syn:: ReturnType :: Default ) {
69
+ return syn:: Error :: new_spanned (
70
+ item_fn. sig ,
71
+ "xtest functions must not take arguments and must return nothing" ,
72
+ )
73
+ . to_compile_error ( )
74
+ . into ( ) ;
75
+ }
76
+
64
77
quote ! {
65
78
#cfg_attr
66
79
#item_fn
0 commit comments