@@ -37,14 +37,33 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
3737
3838 let mut functions = Vec :: new ( ) ;
3939 for & mut ( ref mut file, ref path) in & mut files {
40- for item in file. items . drain ( ..) {
41- if let syn:: Item :: Fn ( f) = item {
42- functions. push ( ( f, path) )
40+ for mut item in file. items . drain ( ..) {
41+ match item {
42+ syn:: Item :: Fn ( f) => functions. push ( ( f, path) ) ,
43+ syn:: Item :: Mod ( ref mut m) => {
44+ if let Some ( ref mut m) = m. content {
45+ for i in m. 1 . drain ( ..) {
46+ if let syn:: Item :: Fn ( f) = i {
47+ functions. push ( ( f, path) )
48+ }
49+ }
50+ }
51+ }
52+ _ => ( ) ,
4353 }
4454 }
4555 }
4656 assert ! ( !functions. is_empty( ) ) ;
4757
58+ let mut tests = std:: collections:: HashSet :: < String > :: new ( ) ;
59+ for f in & functions {
60+ let id = format ! ( "{}" , f. 0 . ident) ;
61+ if id. starts_with ( "test_" ) {
62+ tests. insert ( id) ;
63+ }
64+ }
65+ assert ! ( !tests. is_empty( ) ) ;
66+
4867 functions. retain ( |& ( ref f, _) | {
4968 if let syn:: Visibility :: Public ( _) = f. vis {
5069 if f. unsafety . is_some ( ) {
@@ -84,6 +103,16 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
84103 quote ! { None }
85104 } ;
86105 let required_const = find_required_const ( & f. attrs ) ;
106+
107+ // strip leading underscore from fn name when building a test
108+ // _mm_foo -> mm_foo such that the test name is test_mm_foo.
109+ let test_name_string = format ! ( "{}" , name) ;
110+ let mut test_name_id = test_name_string. as_str ( ) ;
111+ while test_name_id. starts_with ( '_' ) {
112+ test_name_id = & test_name_id[ 1 ..] ;
113+ }
114+ let has_test = tests. contains ( & format ! ( "test_{}" , test_name_id) ) ;
115+
87116 quote ! {
88117 Function {
89118 name: stringify!( #name) ,
@@ -93,6 +122,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
93122 instrs: & [ #( #instrs) , * ] ,
94123 file: stringify!( #path) ,
95124 required_const: & [ #( #required_const) , * ] ,
125+ has_test: #has_test,
96126 }
97127 }
98128 } )
0 commit comments