Skip to content

Commit

Permalink
style: Update for new lints
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 1, 2024
1 parent 5dec389 commit 425f739
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
5 changes: 3 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn main() {
let out = path::PathBuf::from(env::var_os("OUT_DIR").expect("run within cargo"))
.join("current_target.txt");
let default_target = env::var("TARGET").expect("run as cargo build script");
let mut file = fs::File::create(out).unwrap();
file.write_all(default_target.as_bytes()).unwrap();
let mut file = fs::File::create(out).expect("can write to OUT_DIR");
file.write_all(default_target.as_bytes())
.expect("can write to OUT_DIR");
}
2 changes: 2 additions & 0 deletions examples/example_fixture.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::exit)]

use std::env;
use std::error::Error;
use std::io;
Expand Down
1 change: 1 addition & 0 deletions examples/failure.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::wildcard_imports)] // false positive
use assert_cmd::prelude::*;

use std::process::Command;
Expand Down
16 changes: 8 additions & 8 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ where
}

/// Keep `predicates` concrete Predicates out of our public API.
/// [predicates_core::Predicate] used by [`IntoCodePredicate`] for code.
/// [`predicates_core::Predicate`] used by [`IntoCodePredicate`] for code.
///
/// # Example
///
Expand Down Expand Up @@ -616,7 +616,7 @@ impl IntoCodePredicate<EqCodePredicate> for i32 {
}

/// Keep `predicates` concrete Predicates out of our public API.
/// [predicates_core::Predicate] used by [`IntoCodePredicate`] for iterables of codes.
/// [`predicates_core::Predicate`] used by [`IntoCodePredicate`] for iterables of codes.
///
/// # Example
///
Expand Down Expand Up @@ -741,7 +741,7 @@ where
}

/// Keep `predicates` concrete Predicates out of our public API.
/// [predicates_core::Predicate] used by [`IntoOutputPredicate`] for bytes.
/// [`predicates_core::Predicate`] used by [`IntoOutputPredicate`] for bytes.
///
/// # Example
///
Expand Down Expand Up @@ -781,7 +781,7 @@ impl predicates_core::Predicate<[u8]> for BytesContentOutputPredicate {
&self,
expected: bool,
variable: &[u8],
) -> Option<predicates_core::reflection::Case> {
) -> Option<predicates_core::reflection::Case<'_>> {
let actual = self.eval(variable);
if expected == actual {
Some(predicates_core::reflection::Case::new(Some(self), actual))
Expand Down Expand Up @@ -814,7 +814,7 @@ impl IntoOutputPredicate<BytesContentOutputPredicate> for &'static [u8] {
}

/// Keep `predicates` concrete Predicates out of our public API.
/// [predicates_core::Predicate] used by [`IntoOutputPredicate`] for [`str`].
/// [`predicates_core::Predicate`] used by [`IntoOutputPredicate`] for [`str`].
///
/// # Example
///
Expand Down Expand Up @@ -901,7 +901,7 @@ impl IntoOutputPredicate<StrContentOutputPredicate> for &'static str {
}

// Keep `predicates` concrete Predicates out of our public API.
/// [predicates_core::Predicate] used by [`IntoOutputPredicate`] for
/// [`predicates_core::Predicate`] used by [`IntoOutputPredicate`] for
/// [`Predicate<str>`][predicates_core::Predicate].
///
/// # Example
Expand Down Expand Up @@ -1123,7 +1123,7 @@ mod test {
fn convert_code<I, P>(pred: I) -> P
where
I: IntoCodePredicate<P>,
P: predicates_core::Predicate<i32>,
P: Predicate<i32>,
{
pred.into_code()
}
Expand Down Expand Up @@ -1157,7 +1157,7 @@ mod test {
fn convert_output<I, P>(pred: I) -> P
where
I: IntoOutputPredicate<P>,
P: predicates_core::Predicate<[u8]>,
P: Predicate<[u8]>,
{
pred.into_output()
}
Expand Down
2 changes: 2 additions & 0 deletions src/bin/bin_fixture.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::exit)]

use std::env;
use std::error::Error;
use std::io;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn target_dir() -> path::PathBuf {
}
path
})
.unwrap()
.expect("this should only be used where a `current_exe` can be set")
}

/// Look up the path to a cargo-built binary within an integration test.
Expand Down
15 changes: 9 additions & 6 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,8 @@ impl Command {
input: Option<Vec<u8>>,
timeout: Option<std::time::Duration>,
) -> io::Result<process::Output> {
let stdin = input.and_then(|i| {
child
.stdin
.take()
.map(|mut stdin| std::thread::spawn(move || stdin.write_all(&i)))
});
#![allow(unwrap_used)] // changes behavior in some tests

Check failure

Code scanning / clippy

lint name unwrap_used is deprecated and may not have an effect in the future. Error

lint name unwrap\_used is deprecated and may not have an effect in the future.

Check failure

Code scanning / clippy

lint name unwrap_used is deprecated and may not have an effect in the future. Error

lint name unwrap\_used is deprecated and may not have an effect in the future.

fn read<R>(mut input: R) -> std::thread::JoinHandle<io::Result<Vec<u8>>>
where
R: Read + Send + 'static,
Expand All @@ -459,6 +455,13 @@ impl Command {
input.read_to_end(&mut ret).map(|_| ret)
})
}

let stdin = input.and_then(|i| {
child
.stdin
.take()
.map(|mut stdin| std::thread::spawn(move || stdin.write_all(&i)))
});
let stdout = child.stdout.take().map(read);
let stderr = child.stderr.take().map(read);

Expand Down
3 changes: 2 additions & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,13 @@ fn format_bytes(data: &[u8], f: &mut impl fmt::Write) -> fmt::Result {
const LINES_MAX_START: usize = 20;
const LINES_MAX_END: usize = 40;
const LINES_MAX_PRINTED: usize = LINES_MAX_START + LINES_MAX_END;
assert!(LINES_MAX_PRINTED < LINES_MIN_OVERFLOW);

const BYTES_MIN_OVERFLOW: usize = 8192;
const BYTES_MAX_START: usize = 2048;
const BYTES_MAX_END: usize = 2048;
const BYTES_MAX_PRINTED: usize = BYTES_MAX_START + BYTES_MAX_END;

assert!(LINES_MAX_PRINTED < LINES_MIN_OVERFLOW);
assert!(BYTES_MAX_PRINTED < BYTES_MIN_OVERFLOW);

let lines_total = data.as_bstr().lines_with_terminator().count();
Expand Down

0 comments on commit 425f739

Please sign in to comment.