1
+ #![ feature( rustc_private, proc_macro) ]
1
2
///! This implements the kvmargs macro to customize the execution of KVM based tests.
2
3
///!
3
4
///! One problem we have to solve here is that we need to store additional data
15
16
///! Obviously, this is a bit of a mess right now, my hope is that such things become
16
17
///! easier with better custom test harness support.
17
18
///!
18
- #![ feature( rustc_private, proc_macro) ]
19
-
20
19
extern crate proc_macro;
21
20
extern crate syn;
22
21
#[ macro_use]
@@ -44,7 +43,7 @@ fn generate_kvmtest_meta_data(test_ident: &syn::Ident) -> (syn::Ident, quote::To
44
43
extern crate test;
45
44
use self :: test:: KvmTestMetaData ;
46
45
#[ link_section = ".kvm" ]
47
- #[ used ]
46
+ #[ allow ( non_upper_case_globals ) ]
48
47
static #struct_ident: KvmTestMetaData = KvmTestMetaData { mbz: 0 , meta: "test" } ;
49
48
50
49
/// The generated impl
@@ -63,37 +62,38 @@ fn generate_kvmtest_meta_data(test_ident: &syn::Ident) -> (syn::Ident, quote::To
63
62
/// but I'm not sure how to do that in rust...
64
63
fn insert_meta_data_reference ( struct_ident : & syn:: Ident , test_block : & mut syn:: Block ) {
65
64
let stmt_string = format ! ( "assert!({}.mbz == 0);" , struct_ident) ;
66
-
67
65
let stmt = match syn:: parse:: stmt ( stmt_string. as_str ( ) ) {
68
66
IResult :: Done ( stmt_str, stmt) => stmt,
69
- IResult :: Error => panic ! ( "Unable to generate reference to meta data" ) ,
67
+ IResult :: Error => panic ! ( "Unable to generate reference to meta- data" ) ,
70
68
} ;
71
-
72
69
test_block. stmts . insert ( 0 , stmt) ;
73
70
}
74
71
75
72
76
73
#[ proc_macro_attribute]
77
74
pub fn kvmattrs ( args : TokenStream , input : TokenStream ) -> TokenStream {
78
- let args = args. to_string ( ) ;
75
+ let args_str = args. to_string ( ) ;
76
+ println ! ( "{}" , args) ;
79
77
let mut input = input. to_string ( ) ;
80
78
let mut ast = syn:: parse_item ( & input) . unwrap ( ) ;
81
79
let ident = ast. ident . clone ( ) ;
80
+
81
+ // Generate meta-data struct
82
82
let ( meta_data_ident, new_code) = generate_kvmtest_meta_data ( & ident) ;
83
83
84
- {
85
- match & mut ast. node {
86
- & mut syn:: ItemKind :: Fn ( _, _, _, _, _, ref mut block) => {
87
- let mod_test_code = insert_meta_data_reference ( & meta_data_ident, block) ;
88
- println ! ( "{:#?}" , block ) ;
89
- }
90
- _ => panic ! ( "Not a function!" ) ,
91
- } ;
92
- }
84
+ // Insert reference to meta-data in test
85
+ match & mut ast. node {
86
+ & mut syn:: ItemKind :: Fn ( _, _, _, _, _, ref mut block) => {
87
+ insert_meta_data_reference ( & meta_data_ident, block) ;
88
+ }
89
+ _ => panic ! ( "Not a function!" ) ,
90
+ } ;
91
+
92
+ // Merge everything together:
93
93
let mut token = quote:: Tokens :: new ( ) ;
94
94
ast. to_tokens ( & mut token) ;
95
95
token. append ( new_code) ;
96
96
97
- //input += new_code.to_string().as_str();
97
+ // Output this as replacement code for the test function
98
98
token. to_string ( ) . parse ( ) . unwrap ( )
99
99
}
0 commit comments