@@ -86,7 +86,14 @@ pub struct MiniCore {
8686 valid_flags : Vec < String > ,
8787}
8888
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 {
9097 /// Parses text which looks like this:
9198 ///
9299 /// ```not_rust
@@ -96,37 +103,40 @@ impl Fixture {
96103 /// //- other meta
97104 /// ```
98105 ///
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):
100107 ///
101108 /// ```
109+ /// //- toolchain: nightly
102110 /// //- proc_macros: identity
103111 /// //- minicore: sized
104112 /// ```
105113 ///
106114 /// That will include predefined proc macros and a subset of `libcore` into the fixture, see
107115 /// `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 {
109117 let fixture = trim_indent ( ra_fixture) ;
110118 let mut fixture = fixture. as_str ( ) ;
119+ let mut toolchain = None ;
111120 let mut mini_core = None ;
112121 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;
124128 }
125129
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;
130140 }
131141
132142 let default = if fixture. contains ( "//-" ) { None } else { Some ( "//- /main.rs" ) } ;
@@ -142,7 +152,7 @@ impl Fixture {
142152 }
143153
144154 if line. starts_with ( "//-" ) {
145- let meta = Fixture :: parse_meta_line ( line) ;
155+ let meta = Self :: parse_meta_line ( line) ;
146156 res. push ( meta) ;
147157 } else {
148158 if line. starts_with ( "// " )
@@ -160,7 +170,7 @@ impl Fixture {
160170 }
161171 }
162172
163- ( mini_core, test_proc_macros , res )
173+ Self { fixture : res , mini_core, proc_macro_names , toolchain }
164174 }
165175
166176 //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
@@ -257,8 +267,7 @@ impl MiniCore {
257267 fn parse ( line : & str ) -> MiniCore {
258268 let mut res = MiniCore { activated_flags : Vec :: new ( ) , valid_flags : Vec :: new ( ) } ;
259269
260- let line = line. strip_prefix ( "//- minicore:" ) . unwrap ( ) . trim ( ) ;
261- for entry in line. split ( ", " ) {
270+ for entry in line. trim ( ) . split ( ", " ) {
262271 if res. has_flag ( entry) {
263272 panic ! ( "duplicate minicore flag: {entry:?}" ) ;
264273 }
@@ -372,7 +381,7 @@ impl MiniCore {
372381#[ test]
373382#[ should_panic]
374383fn parse_fixture_checks_further_indented_metadata ( ) {
375- Fixture :: parse (
384+ FixtureWithProjectMeta :: parse (
376385 r"
377386 //- /lib.rs
378387 mod bar;
@@ -386,15 +395,18 @@ fn parse_fixture_checks_further_indented_metadata() {
386395
387396#[ test]
388397fn 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
391402//- proc_macros: identity
392403//- minicore: coerce_unsized
393404//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b,atom env:OUTDIR=path/to,OTHER=foo
394405mod m;
395406"# ,
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( ) ] ) ;
398410 assert_eq ! ( mini_core. unwrap( ) . activated_flags, vec![ "coerce_unsized" . to_string( ) ] ) ;
399411 assert_eq ! ( 1 , parsed. len( ) ) ;
400412
0 commit comments