Skip to content

Commit

Permalink
Merge pull request #222 from sylvestre/fix-release
Browse files Browse the repository at this point in the history
Various clippy fixes + precommit
  • Loading branch information
sylvestre authored Apr 2, 2023
2 parents 8f24097 + e4121cc commit 671916f
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 75 deletions.
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: local
hooks:
- id: rust-linting
name: Rust linting
description: Run cargo fmt on files included in the commit.
entry: cargo +nightly fmt --
pass_filenames: true
types: [file, rust]
language: system
- id: rust-clippy
name: Rust clippy
description: Run cargo clippy on files included in the commit.
entry: cargo +nightly clippy --workspace --all-targets --all-features --
pass_filenames: false
types: [file, rust]
language: system
2 changes: 1 addition & 1 deletion src/find/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

fn main() {
let args = std::env::args().collect::<Vec<String>>();
let strs: Vec<&str> = args.iter().map(|s| s.as_ref()).collect();
let strs: Vec<&str> = args.iter().map(std::convert::AsRef::as_ref).collect();
let deps = findutils::find::StandardDependencies::new();
std::process::exit(findutils::find::find_main(&strs, &deps));
}
12 changes: 6 additions & 6 deletions src/find/matchers/type_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod tests {
let dir = get_dir_entry_for("test_data", "simple");
let deps = FakeDependencies::new();

let matcher = TypeMatcher::new(&"f".to_string()).unwrap();
let matcher = TypeMatcher::new("f").unwrap();
assert!(!matcher.matches(&dir, &mut deps.new_matcher_io()));
assert!(matcher.matches(&file, &mut deps.new_matcher_io()));
}
Expand All @@ -98,7 +98,7 @@ mod tests {
let dir = get_dir_entry_for("test_data", "simple");
let deps = FakeDependencies::new();

let matcher = TypeMatcher::new(&"d".to_string()).unwrap();
let matcher = TypeMatcher::new("d").unwrap();
assert!(matcher.matches(&dir, &mut deps.new_matcher_io()));
assert!(!matcher.matches(&file, &mut deps.new_matcher_io()));
}
Expand All @@ -108,7 +108,7 @@ mod tests {
#[test]
fn link_type_matcher() {
#[cfg(unix)]
let _ = {
{
if let Err(e) = symlink("abbbc", "test_data/links/link-f") {
if e.kind() != ErrorKind::AlreadyExists {
panic!("Failed to create sym link: {:?}", e);
Expand Down Expand Up @@ -140,7 +140,7 @@ mod tests {
let dir = get_dir_entry_for("test_data", "links");
let deps = FakeDependencies::new();

let matcher = TypeMatcher::new(&"l".to_string()).unwrap();
let matcher = TypeMatcher::new("l").unwrap();
assert!(!matcher.matches(&dir, &mut deps.new_matcher_io()));
assert!(!matcher.matches(&file, &mut deps.new_matcher_io()));
assert!(matcher.matches(&link_f, &mut deps.new_matcher_io()));
Expand All @@ -155,15 +155,15 @@ mod tests {
let deps = FakeDependencies::new();

for typ in &["b", "c", "p", "s"] {
let matcher = TypeMatcher::new(&typ.to_string()).unwrap();
let matcher = TypeMatcher::new(typ.as_ref()).unwrap();
assert!(!matcher.matches(&dir, &mut deps.new_matcher_io()));
assert!(!matcher.matches(&file, &mut deps.new_matcher_io()));
}
}

#[test]
fn cant_create_with_invalid_pattern() {
let result = TypeMatcher::new(&"xxx".to_string());
let result = TypeMatcher::new("xxx");
assert!(result.is_err());
}
}
2 changes: 1 addition & 1 deletion src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ mod tests {
assert_eq!(rc, 0);
assert_eq!(
deps.get_output_as_string(),
(&new_dir).path().to_string_lossy().to_string() + "\n"
new_dir.path().to_string_lossy().to_string() + "\n"
);

// now do it the other way around, and nothing should be output
Expand Down
4 changes: 2 additions & 2 deletions src/testing/commandline/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn open_file(destination_dir: &str) -> File {
loop {
file_number += 1;
let mut file_path: PathBuf = PathBuf::from(destination_dir);
file_path.push(format!("{}.txt", file_number));
file_path.push(format!("{file_number}.txt"));
if let Ok(f) = OpenOptions::new()
.write(true)
.create_new(true)
Expand Down Expand Up @@ -68,7 +68,7 @@ fn write_content(mut f: impl Write, config: &Config, args: &[String]) {
// the destination_dir we want to write to. Don't write either of those
// as they'll be non-deterministic.
for arg in &args[2..] {
writeln!(f, "{}", arg).expect("failed to write to file");
writeln!(f, "{arg}").expect("failed to write to file");
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/xargs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
fn main() {
let args = std::env::args().collect::<Vec<String>>();
std::process::exit(findutils::xargs::xargs_main(
&args.iter().map(|s| s.as_ref()).collect::<Vec<&str>>(),
&args
.iter()
.map(std::convert::AsRef::as_ref)
.collect::<Vec<&str>>(),
))
}
4 changes: 2 additions & 2 deletions tests/common/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use walkdir::{DirEntry, WalkDir};
use findutils::find::matchers::MatcherIO;
use findutils::find::Dependencies;

/// A copy of find::tests::FakeDependencies.
/// A copy of `find::tests::FakeDependencies`.
/// TODO: find out how to share #[cfg(test)] functions/structs between unit
/// and integration tests.
pub struct FakeDependencies {
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn fix_up_slashes(path: &str) -> String {
path.to_string()
}

/// A copy of find::tests::FakeDependencies.
/// A copy of `find::tests::FakeDependencies`.
/// TODO: find out how to share #[cfg(test)] functions/structs between unit
/// and integration tests.
pub fn get_dir_entry_for(directory: &str, filename: &str) -> DirEntry {
Expand Down
8 changes: 5 additions & 3 deletions tests/exec_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

/// ! This file contains what would be normally be unit tests for find::matchers::exec.
/// ! This file contains what would be normally be unit tests for `find::matchers::exec`.
/// ! But as the tests require running an external executable, they need to be run
/// ! as integration tests so we can ensure that our testing-commandline binary
/// ! has been built.
Expand All @@ -17,8 +17,10 @@ use std::io::Read;
use tempfile::Builder;
use walkdir::WalkDir;

use common::test_helpers::*;
use findutils::find::matchers::exec::*;
use common::test_helpers::{
fix_up_slashes, get_dir_entry_for, path_to_testing_commandline, FakeDependencies,
};
use findutils::find::matchers::exec::SingleExecMatcher;
use findutils::find::matchers::Matcher;

mod common;
Expand Down
Loading

0 comments on commit 671916f

Please sign in to comment.