mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
xtask: don't depend on itertools
xtask should be fast to compiler, as it's a gateway to rust-analyzer
This commit is contained in:
parent
a669049ef3
commit
6048d29400
3 changed files with 22 additions and 19 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1771,7 +1771,6 @@ dependencies = [
|
||||||
name = "xtask"
|
name = "xtask"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -7,7 +7,6 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
walkdir = "2.1.3"
|
walkdir = "2.1.3"
|
||||||
itertools = "0.8.0"
|
|
||||||
pico-args = "0.3.0"
|
pico-args = "0.3.0"
|
||||||
quote = "1.0.2"
|
quote = "1.0.2"
|
||||||
proc-macro2 = "1.0.1"
|
proc-macro2 = "1.0.1"
|
||||||
|
|
|
@ -7,8 +7,6 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use itertools::Itertools;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
codegen::{self, update, Mode},
|
codegen::{self, update, Mode},
|
||||||
project_root, Result,
|
project_root, Result,
|
||||||
|
@ -61,38 +59,45 @@ struct Tests {
|
||||||
fn collect_tests(s: &str) -> Vec<(usize, Test)> {
|
fn collect_tests(s: &str) -> Vec<(usize, Test)> {
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
let prefix = "// ";
|
let prefix = "// ";
|
||||||
let comment_blocks = s
|
let lines = s.lines().map(str::trim_start).enumerate();
|
||||||
.lines()
|
|
||||||
.map(str::trim_start)
|
|
||||||
.enumerate()
|
|
||||||
.group_by(|(_idx, line)| line.starts_with(prefix));
|
|
||||||
|
|
||||||
'outer: for (is_comment, block) in comment_blocks.into_iter() {
|
let mut block = vec![];
|
||||||
if !is_comment {
|
for (line_idx, line) in lines {
|
||||||
continue;
|
let is_comment = line.starts_with(prefix);
|
||||||
|
if is_comment {
|
||||||
|
block.push((line_idx, &line[prefix.len()..]));
|
||||||
|
} else {
|
||||||
|
process_block(&mut res, &block);
|
||||||
|
block.clear();
|
||||||
}
|
}
|
||||||
let mut block = block.map(|(idx, line)| (idx, &line[prefix.len()..]));
|
}
|
||||||
|
process_block(&mut res, &block);
|
||||||
|
return res;
|
||||||
|
|
||||||
|
fn process_block(acc: &mut Vec<(usize, Test)>, block: &[(usize, &str)]) {
|
||||||
|
if block.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let mut ok = true;
|
let mut ok = true;
|
||||||
|
let mut block = block.iter();
|
||||||
let (start_line, name) = loop {
|
let (start_line, name) = loop {
|
||||||
match block.next() {
|
match block.next() {
|
||||||
Some((idx, line)) if line.starts_with("test ") => {
|
Some(&(idx, line)) if line.starts_with("test ") => {
|
||||||
break (idx, line["test ".len()..].to_string());
|
break (idx, line["test ".len()..].to_string());
|
||||||
}
|
}
|
||||||
Some((idx, line)) if line.starts_with("test_err ") => {
|
Some(&(idx, line)) if line.starts_with("test_err ") => {
|
||||||
ok = false;
|
ok = false;
|
||||||
break (idx, line["test_err ".len()..].to_string());
|
break (idx, line["test_err ".len()..].to_string());
|
||||||
}
|
}
|
||||||
Some(_) => (),
|
Some(_) => (),
|
||||||
None => continue 'outer,
|
None => return,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let text: String =
|
let text: String =
|
||||||
itertools::join(block.map(|(_, line)| line).chain(::std::iter::once("")), "\n");
|
block.map(|(_, line)| *line).chain(std::iter::once("")).collect::<Vec<_>>().join("\n");
|
||||||
assert!(!text.trim().is_empty() && text.ends_with('\n'));
|
assert!(!text.trim().is_empty() && text.ends_with('\n'));
|
||||||
res.push((start_line, Test { name, text, ok }))
|
acc.push((start_line, Test { name, text, ok }))
|
||||||
}
|
}
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tests_from_dir(dir: &Path) -> Result<Tests> {
|
fn tests_from_dir(dir: &Path) -> Result<Tests> {
|
||||||
|
|
Loading…
Reference in a new issue