From 355419d4044704d13a902641d86ad5501af8714d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Oct 2019 14:22:49 +0300 Subject: use slightly more idiomatic api for cfg --- crates/ra_hir/src/nameres/tests.rs | 14 ++++++++------ crates/ra_hir/src/ty/tests.rs | 6 +++++- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 34dd79574..208c2f16f 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -561,12 +561,14 @@ fn cfg_test() { "#, crate_graph! { "main": ("/main.rs", ["std"]), - "std": ("/lib.rs", [], CfgOptions::default() - .atom("test".into()) - .key_value("feature".into(), "foo".into()) - .key_value("feature".into(), "bar".into()) - .key_value("opt".into(), "42".into()) - ), + "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 + }), }, ); diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 25dad81eb..b16b48258 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -62,7 +62,11 @@ impl S { "#, ); db.set_crate_graph_from_fixture(crate_graph! { - "main": ("/main.rs", ["foo"], CfgOptions::default().atom("test".into())), + "main": ("/main.rs", ["foo"], { + let mut opts = CfgOptions::default(); + opts.insert_atom("test".into()); + opts + }), "foo": ("/foo.rs", []), }); assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos)); -- cgit v1.2.3 From 972079c0e32ba6085eb5ba02a137a6df86b79b5a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Oct 2019 14:39:44 +0300 Subject: macro DSL for cfg in tests --- crates/ra_hir/src/mock.rs | 19 +++++++++++++++++-- crates/ra_hir/src/nameres/tests.rs | 13 +++++-------- crates/ra_hir/src/ty/tests.rs | 7 +------ 3 files changed, 23 insertions(+), 16 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index f750986b8..827424983 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -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()),*]) diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 208c2f16f..8c6b40aaf 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -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", }), }, ); diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index b16b48258..263b61a59 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -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)); -- cgit v1.2.3