Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/test-utils/src/fixture.rs')
| -rw-r--r-- | crates/test-utils/src/fixture.rs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/crates/test-utils/src/fixture.rs b/crates/test-utils/src/fixture.rs index 559894ee62..1f6262c897 100644 --- a/crates/test-utils/src/fixture.rs +++ b/crates/test-utils/src/fixture.rs @@ -96,9 +96,10 @@ pub struct Fixture { /// /// Syntax: `cfg:test,dbg=false,opt_level=2` pub cfgs: Vec<(String, Option<String>)>, - /// Specifies the edition of this crate. This must be used with `crate` meta. If - /// this is not specified, ([`base_db::input::Edition::CURRENT`]) will be used. - /// This must be used with `crate` meta. + /// Specifies the edition of this crate. This must be used with + /// `crate` meta. If this is not specified, + /// `base_db::input::Edition::CURRENT` will be used. This must be + /// used with `crate` meta. /// /// Syntax: `edition:2021` pub edition: Option<String>, @@ -106,8 +107,13 @@ pub struct Fixture { /// /// Syntax: `env:PATH=/bin,RUST_LOG=debug` pub env: FxHashMap<String, String>, - /// Introduces a new [source root](base_db::input::SourceRoot). This file **and - /// the following files** will belong the new source root. This must be used + /// Specifies extra crate-level attributes injected at the top of the crate root file. + /// This must be used with `crate` meta. + /// + /// Syntax: `crate-attr:no_std crate-attr:features(f16,f128) crate-attr:cfg(target_arch="x86")` + pub crate_attrs: Vec<String>, + /// Introduces a new source root. This file **and the following + /// files** will belong the new source root. This must be used /// with `crate` meta. /// /// Use this if you want to test something that uses `SourceRoot::is_library()` @@ -126,7 +132,7 @@ pub struct Fixture { /// This is implied if this file belongs to a library source root. /// /// Use this if you want to test something that checks if a crate is a workspace - /// member via [`CrateOrigin`](base_db::input::CrateOrigin). + /// member via `CrateOrigin`. /// /// Syntax: `library` pub library: bool, @@ -274,6 +280,7 @@ impl FixtureWithProjectMeta { let mut krate = None; let mut deps = Vec::new(); + let mut crate_attrs = Vec::new(); let mut extern_prelude = None; let mut edition = None; let mut cfgs = Vec::new(); @@ -291,6 +298,7 @@ impl FixtureWithProjectMeta { match key { "crate" => krate = Some(value.to_owned()), "deps" => deps = value.split(',').map(|it| it.to_owned()).collect(), + "crate-attr" => crate_attrs.push(value.to_owned()), "extern-prelude" => { if value.is_empty() { extern_prelude = Some(Vec::new()); @@ -333,6 +341,7 @@ impl FixtureWithProjectMeta { line, krate, deps, + crate_attrs, extern_prelude, cfgs, edition, @@ -547,7 +556,7 @@ fn parse_fixture_gets_full_meta() { //- toolchain: nightly //- proc_macros: identity //- minicore: coerce_unsized -//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b,atom env:OUTDIR=path/to,OTHER=foo +//- /lib.rs crate:foo deps:bar,baz crate-attr:no_std crate-attr:features(f16,f128) crate-attr:cfg(target_arch="x86") cfg:foo=a,bar=b,atom env:OUTDIR=path/to,OTHER=foo mod m; "#, ); @@ -560,6 +569,14 @@ mod m; assert_eq!("mod m;\n", meta.text); assert_eq!("foo", meta.krate.as_ref().unwrap()); + assert_eq!( + vec![ + "no_std".to_owned(), + "features(f16,f128)".to_owned(), + "cfg(target_arch=\"x86\")".to_owned() + ], + meta.crate_attrs + ); assert_eq!("/lib.rs", meta.path); assert_eq!(2, meta.env.len()); } |