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:
Aleksey Kladov 2019-10-23 18:24:40 +03:00
parent a669049ef3
commit 6048d29400
3 changed files with 22 additions and 19 deletions

1
Cargo.lock generated
View file

@ -1771,7 +1771,6 @@ dependencies = [
name = "xtask"
version = "0.1.0"
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)",
"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)",

View file

@ -7,7 +7,6 @@ publish = false
[dependencies]
walkdir = "2.1.3"
itertools = "0.8.0"
pico-args = "0.3.0"
quote = "1.0.2"
proc-macro2 = "1.0.1"

View file

@ -7,8 +7,6 @@ use std::{
path::{Path, PathBuf},
};
use itertools::Itertools;
use crate::{
codegen::{self, update, Mode},
project_root, Result,
@ -61,38 +59,45 @@ struct Tests {
fn collect_tests(s: &str) -> Vec<(usize, Test)> {
let mut res = vec![];
let prefix = "// ";
let comment_blocks = s
.lines()
.map(str::trim_start)
.enumerate()
.group_by(|(_idx, line)| line.starts_with(prefix));
let lines = s.lines().map(str::trim_start).enumerate();
'outer: for (is_comment, block) in comment_blocks.into_iter() {
if !is_comment {
continue;
let mut block = vec![];
for (line_idx, line) in lines {
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 block = block.iter();
let (start_line, name) = loop {
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());
}
Some((idx, line)) if line.starts_with("test_err ") => {
Some(&(idx, line)) if line.starts_with("test_err ") => {
ok = false;
break (idx, line["test_err ".len()..].to_string());
}
Some(_) => (),
None => continue 'outer,
None => return,
}
};
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'));
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> {