mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 19:43:24 +00:00
macro DSL for cfg in tests
This commit is contained in:
parent
355419d404
commit
972079c0e3
@ -278,7 +278,10 @@ macro_rules! crate_graph {
|
||||
$crate_path:literal,
|
||||
$($edition:literal,)?
|
||||
[$($dep:literal),*]
|
||||
$(,$cfg:expr)?
|
||||
$(, cfg = {
|
||||
$($key:literal $(= $value:literal)?),*
|
||||
$(,)?
|
||||
})?
|
||||
),
|
||||
)*) => {{
|
||||
let mut res = $crate::mock::CrateGraphFixture::default();
|
||||
@ -286,7 +289,19 @@ macro_rules! crate_graph {
|
||||
#[allow(unused_mut, unused_assignments)]
|
||||
let mut edition = ra_db::Edition::Edition2018;
|
||||
$(edition = ra_db::Edition::from_string($edition);)?
|
||||
let cfg_options = { ::ra_cfg::CfgOptions::default() $(; $cfg)? };
|
||||
let cfg_options = {
|
||||
#[allow(unused_mut)]
|
||||
let mut cfg = ::ra_cfg::CfgOptions::default();
|
||||
$(
|
||||
$(
|
||||
if 0 == 0 $(+ { drop($value); 1})? {
|
||||
cfg.insert_atom($key.into());
|
||||
}
|
||||
$(cfg.insert_key_value($key.into(), $value.into());)?
|
||||
)*
|
||||
)?
|
||||
cfg
|
||||
};
|
||||
res.0.push((
|
||||
$crate_name.to_string(),
|
||||
($crate_path.to_string(), edition, cfg_options, vec![$($dep.to_string()),*])
|
||||
|
@ -7,7 +7,6 @@ mod mod_resolution;
|
||||
use std::sync::Arc;
|
||||
|
||||
use insta::assert_snapshot;
|
||||
use ra_cfg::CfgOptions;
|
||||
use ra_db::SourceDatabase;
|
||||
use test_utils::covers;
|
||||
|
||||
@ -561,13 +560,11 @@ fn cfg_test() {
|
||||
"#,
|
||||
crate_graph! {
|
||||
"main": ("/main.rs", ["std"]),
|
||||
"std": ("/lib.rs", [], {
|
||||
let mut opts = CfgOptions::default();
|
||||
opts.insert_atom("test".into());
|
||||
opts.insert_key_value("feature".into(), "foo".into());
|
||||
opts.insert_key_value("feature".into(), "bar".into());
|
||||
opts.insert_key_value("opt".into(), "42".into());
|
||||
opts
|
||||
"std": ("/lib.rs", [], cfg = {
|
||||
"test",
|
||||
"feature" = "foo",
|
||||
"feature" = "bar",
|
||||
"opt" = "42",
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
@ -3,7 +3,6 @@ use std::sync::Arc;
|
||||
|
||||
use insta::assert_snapshot;
|
||||
|
||||
use ra_cfg::CfgOptions;
|
||||
use ra_db::{salsa::Database, FilePosition, SourceDatabase};
|
||||
use ra_syntax::{
|
||||
algo,
|
||||
@ -62,11 +61,7 @@ impl S {
|
||||
"#,
|
||||
);
|
||||
db.set_crate_graph_from_fixture(crate_graph! {
|
||||
"main": ("/main.rs", ["foo"], {
|
||||
let mut opts = CfgOptions::default();
|
||||
opts.insert_atom("test".into());
|
||||
opts
|
||||
}),
|
||||
"main": ("/main.rs", ["foo"], cfg = { "test" }),
|
||||
"foo": ("/foo.rs", []),
|
||||
});
|
||||
assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos));
|
||||
|
Loading…
Reference in New Issue
Block a user