mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-10 17:07:36 +00:00
Add toolchain
meta for tests
This commit is contained in:
parent
5d41affc77
commit
584d2697cc
@ -4,7 +4,8 @@ use std::{mem, str::FromStr, sync::Arc};
|
|||||||
use cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use test_utils::{
|
use test_utils::{
|
||||||
extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER, ESCAPED_CURSOR_MARKER,
|
extract_range_or_offset, Fixture, FixtureWithProjectMeta, RangeOrOffset, CURSOR_MARKER,
|
||||||
|
ESCAPED_CURSOR_MARKER,
|
||||||
};
|
};
|
||||||
use tt::token_id::{Leaf, Subtree, TokenTree};
|
use tt::token_id::{Leaf, Subtree, TokenTree};
|
||||||
use vfs::{file_set::FileSet, VfsPath};
|
use vfs::{file_set::FileSet, VfsPath};
|
||||||
@ -12,7 +13,7 @@ use vfs::{file_set::FileSet, VfsPath};
|
|||||||
use crate::{
|
use crate::{
|
||||||
input::{CrateName, CrateOrigin, LangCrateOrigin},
|
input::{CrateName, CrateOrigin, LangCrateOrigin},
|
||||||
Change, CrateDisplayName, CrateGraph, CrateId, Dependency, Edition, Env, FileId, FilePosition,
|
Change, CrateDisplayName, CrateGraph, CrateId, Dependency, Edition, Env, FileId, FilePosition,
|
||||||
FileRange, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacros,
|
FileRange, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacros, ReleaseChannel,
|
||||||
SourceDatabaseExt, SourceRoot, SourceRootId,
|
SourceDatabaseExt, SourceRoot, SourceRootId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,7 +103,14 @@ impl ChangeFixture {
|
|||||||
ra_fixture: &str,
|
ra_fixture: &str,
|
||||||
mut proc_macro_defs: Vec<(String, ProcMacro)>,
|
mut proc_macro_defs: Vec<(String, ProcMacro)>,
|
||||||
) -> ChangeFixture {
|
) -> ChangeFixture {
|
||||||
let (mini_core, proc_macro_names, fixture) = Fixture::parse(ra_fixture);
|
let FixtureWithProjectMeta { fixture, mini_core, proc_macro_names, toolchain } =
|
||||||
|
FixtureWithProjectMeta::parse(ra_fixture);
|
||||||
|
let toolchain = toolchain
|
||||||
|
.map(|it| {
|
||||||
|
ReleaseChannel::from_str(&it)
|
||||||
|
.unwrap_or_else(|| panic!("unknown release channel found: {it}"))
|
||||||
|
})
|
||||||
|
.unwrap_or(ReleaseChannel::Stable);
|
||||||
let mut change = Change::new();
|
let mut change = Change::new();
|
||||||
|
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
@ -166,7 +174,7 @@ impl ChangeFixture {
|
|||||||
.as_deref()
|
.as_deref()
|
||||||
.map(Arc::from)
|
.map(Arc::from)
|
||||||
.ok_or_else(|| "target_data_layout unset".into()),
|
.ok_or_else(|| "target_data_layout unset".into()),
|
||||||
None,
|
Some(toolchain),
|
||||||
);
|
);
|
||||||
let prev = crates.insert(crate_name.clone(), crate_id);
|
let prev = crates.insert(crate_name.clone(), crate_id);
|
||||||
assert!(prev.is_none());
|
assert!(prev.is_none());
|
||||||
@ -205,7 +213,7 @@ impl ChangeFixture {
|
|||||||
default_target_data_layout
|
default_target_data_layout
|
||||||
.map(|x| x.into())
|
.map(|x| x.into())
|
||||||
.ok_or_else(|| "target_data_layout unset".into()),
|
.ok_or_else(|| "target_data_layout unset".into()),
|
||||||
None,
|
Some(toolchain),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (from, to, prelude) in crate_deps {
|
for (from, to, prelude) in crate_deps {
|
||||||
@ -247,7 +255,7 @@ impl ChangeFixture {
|
|||||||
false,
|
false,
|
||||||
CrateOrigin::Lang(LangCrateOrigin::Core),
|
CrateOrigin::Lang(LangCrateOrigin::Core),
|
||||||
target_layout.clone(),
|
target_layout.clone(),
|
||||||
None,
|
Some(toolchain),
|
||||||
);
|
);
|
||||||
|
|
||||||
for krate in all_crates {
|
for krate in all_crates {
|
||||||
@ -286,7 +294,7 @@ impl ChangeFixture {
|
|||||||
true,
|
true,
|
||||||
CrateOrigin::Local { repo: None, name: None },
|
CrateOrigin::Local { repo: None, name: None },
|
||||||
target_layout,
|
target_layout,
|
||||||
None,
|
Some(toolchain),
|
||||||
);
|
);
|
||||||
proc_macros.insert(proc_macros_crate, Ok(proc_macro));
|
proc_macros.insert(proc_macros_crate, Ok(proc_macro));
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ fn external_docs_doc_url_std_crate() {
|
|||||||
//- /main.rs crate:std
|
//- /main.rs crate:std
|
||||||
use self$0;
|
use self$0;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"https://doc.rust-lang.org/nightly/std/index.html"#]],
|
expect!["https://doc.rust-lang.org/stable/std/index.html"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4242,7 +4242,7 @@ fn foo() {
|
|||||||
/// [threads]: ../book/ch16-01-threads.html#using-move-closures-with-threads
|
/// [threads]: ../book/ch16-01-threads.html#using-move-closures-with-threads
|
||||||
mod move_keyword {}
|
mod move_keyword {}
|
||||||
"#,
|
"#,
|
||||||
expect
|
[closure](https://doc.rust-lang.org/stable/book/ch13-01-closures.html)
|
||||||
[closures](https://doc.rust-lang.org/nightly/book/ch13-01-closures.html)
|
[closures](https://doc.rust-lang.org/stable/book/ch13-01-closures.html)
|
||||||
[threads](https://doc.rust-lang.org/nightly/book/ch16-01-threads.html#using-move-closures-with-threads)
|
[threads](https://doc.rust-lang.org/stable/book/ch16-01-threads.html#using-move-closures-with-threads)
|
||||||
<https://doc.rust-lang.org/nightly/book/ch13-01-closures.html>
|
<https://doc.rust-lang.org/nightly/book/ch13-01-closures.html>
|
||||||
"##]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use project_model::ProjectManifest;
|
|||||||
use rust_analyzer::{config::Config, lsp_ext, main_loop};
|
use rust_analyzer::{config::Config, lsp_ext, main_loop};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{json, to_string_pretty, Value};
|
use serde_json::{json, to_string_pretty, Value};
|
||||||
use test_utils::Fixture;
|
use test_utils::FixtureWithProjectMeta;
|
||||||
use vfs::AbsPathBuf;
|
use vfs::AbsPathBuf;
|
||||||
|
|
||||||
use crate::testdir::TestDir;
|
use crate::testdir::TestDir;
|
||||||
@ -84,10 +84,12 @@ impl<'a> Project<'a> {
|
|||||||
profile::init_from(crate::PROFILE);
|
profile::init_from(crate::PROFILE);
|
||||||
});
|
});
|
||||||
|
|
||||||
let (mini_core, proc_macros, fixtures) = Fixture::parse(self.fixture);
|
let FixtureWithProjectMeta { fixture, mini_core, proc_macro_names, toolchain } =
|
||||||
assert!(proc_macros.is_empty());
|
FixtureWithProjectMeta::parse(self.fixture);
|
||||||
|
assert!(proc_macro_names.is_empty());
|
||||||
assert!(mini_core.is_none());
|
assert!(mini_core.is_none());
|
||||||
for entry in fixtures {
|
assert!(toolchain.is_none());
|
||||||
|
for entry in fixture {
|
||||||
let path = tmp_dir.path().join(&entry.path['/'.len_utf8()..]);
|
let path = tmp_dir.path().join(&entry.path['/'.len_utf8()..]);
|
||||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||||
fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
|
fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
|
||||||
|
@ -86,7 +86,14 @@ pub struct MiniCore {
|
|||||||
valid_flags: Vec<String>,
|
valid_flags: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fixture {
|
pub struct FixtureWithProjectMeta {
|
||||||
|
pub fixture: Vec<Fixture>,
|
||||||
|
pub mini_core: Option<MiniCore>,
|
||||||
|
pub proc_macro_names: Vec<String>,
|
||||||
|
pub toolchain: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FixtureWithProjectMeta {
|
||||||
/// Parses text which looks like this:
|
/// Parses text which looks like this:
|
||||||
///
|
///
|
||||||
/// ```not_rust
|
/// ```not_rust
|
||||||
@ -96,37 +103,40 @@ impl Fixture {
|
|||||||
/// //- other meta
|
/// //- other meta
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Fixture can also start with a proc_macros and minicore declaration(in that order):
|
/// Fixture can also start with a proc_macros and minicore declaration (in that order):
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
/// //- toolchain: nightly
|
||||||
/// //- proc_macros: identity
|
/// //- proc_macros: identity
|
||||||
/// //- minicore: sized
|
/// //- minicore: sized
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// That will include predefined proc macros and a subset of `libcore` into the fixture, see
|
/// That will include predefined proc macros and a subset of `libcore` into the fixture, see
|
||||||
/// `minicore.rs` for what's available.
|
/// `minicore.rs` for what's available.
|
||||||
pub fn parse(ra_fixture: &str) -> (Option<MiniCore>, Vec<String>, Vec<Fixture>) {
|
pub fn parse(ra_fixture: &str) -> Self {
|
||||||
let fixture = trim_indent(ra_fixture);
|
let fixture = trim_indent(ra_fixture);
|
||||||
let mut fixture = fixture.as_str();
|
let mut fixture = fixture.as_str();
|
||||||
|
let mut toolchain = None;
|
||||||
let mut mini_core = None;
|
let mut mini_core = None;
|
||||||
let mut res: Vec<Fixture> = Vec::new();
|
let mut res: Vec<Fixture> = Vec::new();
|
||||||
let mut test_proc_macros = vec![];
|
let mut proc_macro_names = vec![];
|
||||||
|
|
||||||
if fixture.starts_with("//- proc_macros:") {
|
if let Some(meta) = fixture.strip_prefix("//- toolchain:") {
|
||||||
let first_line = fixture.split_inclusive('\n').next().unwrap();
|
let (meta, remain) = meta.split_once('\n').unwrap();
|
||||||
test_proc_macros = first_line
|
toolchain = Some(meta.trim().to_string());
|
||||||
.strip_prefix("//- proc_macros:")
|
fixture = remain;
|
||||||
.unwrap()
|
|
||||||
.split(',')
|
|
||||||
.map(|it| it.trim().to_string())
|
|
||||||
.collect();
|
|
||||||
fixture = &fixture[first_line.len()..];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if fixture.starts_with("//- minicore:") {
|
if let Some(meta) = fixture.strip_prefix("//- proc_macros:") {
|
||||||
let first_line = fixture.split_inclusive('\n').next().unwrap();
|
let (meta, remain) = meta.split_once('\n').unwrap();
|
||||||
mini_core = Some(MiniCore::parse(first_line));
|
proc_macro_names = meta.split(',').map(|it| it.trim().to_string()).collect();
|
||||||
fixture = &fixture[first_line.len()..];
|
fixture = remain;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(meta) = fixture.strip_prefix("//- minicore:") {
|
||||||
|
let (meta, remain) = meta.split_once('\n').unwrap();
|
||||||
|
mini_core = Some(MiniCore::parse(meta));
|
||||||
|
fixture = remain;
|
||||||
}
|
}
|
||||||
|
|
||||||
let default = if fixture.contains("//-") { None } else { Some("//- /main.rs") };
|
let default = if fixture.contains("//-") { None } else { Some("//- /main.rs") };
|
||||||
@ -142,7 +152,7 @@ impl Fixture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if line.starts_with("//-") {
|
if line.starts_with("//-") {
|
||||||
let meta = Fixture::parse_meta_line(line);
|
let meta = Self::parse_meta_line(line);
|
||||||
res.push(meta);
|
res.push(meta);
|
||||||
} else {
|
} else {
|
||||||
if line.starts_with("// ")
|
if line.starts_with("// ")
|
||||||
@ -160,7 +170,7 @@ impl Fixture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(mini_core, test_proc_macros, res)
|
Self { fixture: res, mini_core, proc_macro_names, toolchain }
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
|
//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
|
||||||
@ -257,8 +267,7 @@ impl MiniCore {
|
|||||||
fn parse(line: &str) -> MiniCore {
|
fn parse(line: &str) -> MiniCore {
|
||||||
let mut res = MiniCore { activated_flags: Vec::new(), valid_flags: Vec::new() };
|
let mut res = MiniCore { activated_flags: Vec::new(), valid_flags: Vec::new() };
|
||||||
|
|
||||||
let line = line.strip_prefix("//- minicore:").unwrap().trim();
|
for entry in line.trim().split(", ") {
|
||||||
for entry in line.split(", ") {
|
|
||||||
if res.has_flag(entry) {
|
if res.has_flag(entry) {
|
||||||
panic!("duplicate minicore flag: {entry:?}");
|
panic!("duplicate minicore flag: {entry:?}");
|
||||||
}
|
}
|
||||||
@ -372,7 +381,7 @@ impl MiniCore {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn parse_fixture_checks_further_indented_metadata() {
|
fn parse_fixture_checks_further_indented_metadata() {
|
||||||
Fixture::parse(
|
FixtureWithProjectMeta::parse(
|
||||||
r"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod bar;
|
mod bar;
|
||||||
@ -386,15 +395,18 @@ fn parse_fixture_checks_further_indented_metadata() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_fixture_gets_full_meta() {
|
fn parse_fixture_gets_full_meta() {
|
||||||
let (mini_core, proc_macros, parsed) = Fixture::parse(
|
let FixtureWithProjectMeta { fixture: parsed, mini_core, proc_macro_names, toolchain } =
|
||||||
r#"
|
FixtureWithProjectMeta::parse(
|
||||||
|
r#"
|
||||||
|
//- toolchain: nightly
|
||||||
//- proc_macros: identity
|
//- proc_macros: identity
|
||||||
//- minicore: coerce_unsized
|
//- 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 cfg:foo=a,bar=b,atom env:OUTDIR=path/to,OTHER=foo
|
||||||
mod m;
|
mod m;
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
assert_eq!(proc_macros, vec!["identity".to_string()]);
|
assert_eq!(toolchain, Some("nightly".to_string()));
|
||||||
|
assert_eq!(proc_macro_names, vec!["identity".to_string()]);
|
||||||
assert_eq!(mini_core.unwrap().activated_flags, vec!["coerce_unsized".to_string()]);
|
assert_eq!(mini_core.unwrap().activated_flags, vec!["coerce_unsized".to_string()]);
|
||||||
assert_eq!(1, parsed.len());
|
assert_eq!(1, parsed.len());
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ pub use rustc_hash::FxHashMap;
|
|||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
assert_linear::AssertLinear,
|
assert_linear::AssertLinear,
|
||||||
fixture::{Fixture, MiniCore},
|
fixture::{Fixture, FixtureWithProjectMeta, MiniCore},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const CURSOR_MARKER: &str = "$0";
|
pub const CURSOR_MARKER: &str = "$0";
|
||||||
|
Loading…
Reference in New Issue
Block a user