@@ -86,7 +86,14 @@ pub struct MiniCore {
86
86
valid_flags : Vec < String > ,
87
87
}
88
88
89
- impl Fixture {
89
+ pub struct FixtureWithProjectMeta {
90
+ pub fixture : Vec < Fixture > ,
91
+ pub mini_core : Option < MiniCore > ,
92
+ pub proc_macro_names : Vec < String > ,
93
+ pub toolchain : Option < String > ,
94
+ }
95
+
96
+ impl FixtureWithProjectMeta {
90
97
/// Parses text which looks like this:
91
98
///
92
99
/// ```not_rust
@@ -96,37 +103,40 @@ impl Fixture {
96
103
/// //- other meta
97
104
/// ```
98
105
///
99
- /// Fixture can also start with a proc_macros and minicore declaration(in that order):
106
+ /// Fixture can also start with a proc_macros and minicore declaration (in that order):
100
107
///
101
108
/// ```
109
+ /// //- toolchain: nightly
102
110
/// //- proc_macros: identity
103
111
/// //- minicore: sized
104
112
/// ```
105
113
///
106
114
/// That will include predefined proc macros and a subset of `libcore` into the fixture, see
107
115
/// `minicore.rs` for what's available.
108
- pub fn parse ( ra_fixture : & str ) -> ( Option < MiniCore > , Vec < String > , Vec < Fixture > ) {
116
+ pub fn parse ( ra_fixture : & str ) -> Self {
109
117
let fixture = trim_indent ( ra_fixture) ;
110
118
let mut fixture = fixture. as_str ( ) ;
119
+ let mut toolchain = None ;
111
120
let mut mini_core = None ;
112
121
let mut res: Vec < Fixture > = Vec :: new ( ) ;
113
- let mut test_proc_macros = vec ! [ ] ;
114
-
115
- if fixture. starts_with ( "//- proc_macros:" ) {
116
- let first_line = fixture. split_inclusive ( '\n' ) . next ( ) . unwrap ( ) ;
117
- test_proc_macros = first_line
118
- . strip_prefix ( "//- proc_macros:" )
119
- . unwrap ( )
120
- . split ( ',' )
121
- . map ( |it| it. trim ( ) . to_string ( ) )
122
- . collect ( ) ;
123
- fixture = & fixture[ first_line. len ( ) ..] ;
122
+ let mut proc_macro_names = vec ! [ ] ;
123
+
124
+ if let Some ( meta) = fixture. strip_prefix ( "//- toolchain:" ) {
125
+ let ( meta, remain) = meta. split_once ( '\n' ) . unwrap ( ) ;
126
+ toolchain = Some ( meta. trim ( ) . to_string ( ) ) ;
127
+ fixture = remain;
124
128
}
125
129
126
- if fixture. starts_with ( "//- minicore:" ) {
127
- let first_line = fixture. split_inclusive ( '\n' ) . next ( ) . unwrap ( ) ;
128
- mini_core = Some ( MiniCore :: parse ( first_line) ) ;
129
- fixture = & fixture[ first_line. len ( ) ..] ;
130
+ if let Some ( meta) = fixture. strip_prefix ( "//- proc_macros:" ) {
131
+ let ( meta, remain) = meta. split_once ( '\n' ) . unwrap ( ) ;
132
+ proc_macro_names = meta. split ( ',' ) . map ( |it| it. trim ( ) . to_string ( ) ) . collect ( ) ;
133
+ fixture = remain;
134
+ }
135
+
136
+ if let Some ( meta) = fixture. strip_prefix ( "//- minicore:" ) {
137
+ let ( meta, remain) = meta. split_once ( '\n' ) . unwrap ( ) ;
138
+ mini_core = Some ( MiniCore :: parse ( meta) ) ;
139
+ fixture = remain;
130
140
}
131
141
132
142
let default = if fixture. contains ( "//-" ) { None } else { Some ( "//- /main.rs" ) } ;
@@ -142,7 +152,7 @@ impl Fixture {
142
152
}
143
153
144
154
if line. starts_with ( "//-" ) {
145
- let meta = Fixture :: parse_meta_line ( line) ;
155
+ let meta = Self :: parse_meta_line ( line) ;
146
156
res. push ( meta) ;
147
157
} else {
148
158
if line. starts_with ( "// " )
@@ -160,7 +170,7 @@ impl Fixture {
160
170
}
161
171
}
162
172
163
- ( mini_core, test_proc_macros , res )
173
+ Self { fixture : res , mini_core, proc_macro_names , toolchain }
164
174
}
165
175
166
176
//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
@@ -257,8 +267,7 @@ impl MiniCore {
257
267
fn parse ( line : & str ) -> MiniCore {
258
268
let mut res = MiniCore { activated_flags : Vec :: new ( ) , valid_flags : Vec :: new ( ) } ;
259
269
260
- let line = line. strip_prefix ( "//- minicore:" ) . unwrap ( ) . trim ( ) ;
261
- for entry in line. split ( ", " ) {
270
+ for entry in line. trim ( ) . split ( ", " ) {
262
271
if res. has_flag ( entry) {
263
272
panic ! ( "duplicate minicore flag: {entry:?}" ) ;
264
273
}
@@ -372,7 +381,7 @@ impl MiniCore {
372
381
#[ test]
373
382
#[ should_panic]
374
383
fn parse_fixture_checks_further_indented_metadata ( ) {
375
- Fixture :: parse (
384
+ FixtureWithProjectMeta :: parse (
376
385
r"
377
386
//- /lib.rs
378
387
mod bar;
@@ -386,15 +395,18 @@ fn parse_fixture_checks_further_indented_metadata() {
386
395
387
396
#[ test]
388
397
fn parse_fixture_gets_full_meta ( ) {
389
- let ( mini_core, proc_macros, parsed) = Fixture :: parse (
390
- r#"
398
+ let FixtureWithProjectMeta { fixture : parsed, mini_core, proc_macro_names, toolchain } =
399
+ FixtureWithProjectMeta :: parse (
400
+ r#"
401
+ //- toolchain: nightly
391
402
//- proc_macros: identity
392
403
//- minicore: coerce_unsized
393
404
//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b,atom env:OUTDIR=path/to,OTHER=foo
394
405
mod m;
395
406
"# ,
396
- ) ;
397
- assert_eq ! ( proc_macros, vec![ "identity" . to_string( ) ] ) ;
407
+ ) ;
408
+ assert_eq ! ( toolchain, Some ( "nightly" . to_string( ) ) ) ;
409
+ assert_eq ! ( proc_macro_names, vec![ "identity" . to_string( ) ] ) ;
398
410
assert_eq ! ( mini_core. unwrap( ) . activated_flags, vec![ "coerce_unsized" . to_string( ) ] ) ;
399
411
assert_eq ! ( 1 , parsed. len( ) ) ;
400
412
0 commit comments