Skip to content

replace walkdir with ripgreps ignore crate #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ inputs:
runs:
using: composite
steps:
# Work around for sporadic issues with rustup self-update on windows
- run: rustup set auto-self-update disable
if: contains(runner.os, 'windows')
shell: bash
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
Expand Down
66 changes: 66 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ lto = true
[dev-dependencies]
regex = "1"
once_cell = "1"
walkdir = "2"
ignore = "0.4"

[package.metadata.release]
dev-version = false
Expand Down
6 changes: 4 additions & 2 deletions ci/test-bisect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ main() {
# shellcheck disable=SC2016
echo '#!/usr/bin/env bash
export CROSS_CUSTOM_TOOLCHAIN=1
exec "${CROSS}" run --target '"${TARGET}" > bisect.sh
"${CROSS}" run --target '"${TARGET}"'
cargo -V | grep 2022-06
' > bisect.sh
chmod +x bisect.sh

if ! err=$(cargo bisect-rustc --script=./bisect.sh --target "${TARGET}" 2>&1 >/dev/null); then
if ! err=$(cargo bisect-rustc --start 2022-07-01 --end 2022-07-03 --script=./bisect.sh --target "${TARGET}" 2>&1); then
if [[ "${err}" != *"does not reproduce the regression"* ]]; then
echo "${err}"
exit 1
Expand Down
15 changes: 8 additions & 7 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ pub fn get_cargo_workspace() -> &'static Path {

pub fn walk_dir<'a>(
root: &'_ Path,
skip: &'a [impl AsRef<OsStr>],
ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + 'static,
) -> impl Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>> + 'a {
walkdir::WalkDir::new(root)
.into_iter()
skip: &'static [impl AsRef<OsStr> + Send + Sync + 'a],
ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + Sync + Send + 'static,
) -> impl Iterator<Item = Result<ignore::DirEntry, ignore::Error>> {
ignore::WalkBuilder::new(root)
.filter_entry(move |e| {
if skip
.iter()
.map(|s| -> &std::ffi::OsStr { s.as_ref() })
.any(|dir| e.file_name() == dir)
{
return false;
} else if e.file_type().is_dir() {
} else if e.file_type().map_or(false, |f| f.is_dir()) {
return true;
}
ext(e.path().extension())
})
.build()
}

#[test]
Expand Down Expand Up @@ -134,9 +134,10 @@ release: {version}
fn check_newlines() -> crate::Result<()> {
for file in walk_dir(get_cargo_workspace(), &[".git", "target"], |_| true) {
let file = file?;
if !file.file_type().is_file() {
if !file.file_type().map_or(true, |f| f.is_file()) {
continue;
}
eprintln!("File: {:?}", file.path());
assert!(
crate::file::read(file.path())
.unwrap_or_else(|_| String::from("\n"))
Expand Down
2 changes: 1 addition & 1 deletion src/tests/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {

for dir_entry in walk {
let dir_entry = dir_entry?;
if dir_entry.file_type().is_dir() {
if dir_entry.file_type().map_or(true, |f| f.is_dir()) {
continue;
}
eprintln!("File: {:?}", dir_entry.path());
Expand Down