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