Skip to content

Commit

Permalink
style: apply clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Dec 21, 2023
1 parent f74a0fe commit 47c9477
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
built::write_built_file().expect("failed to acquire build-time information")
built::write_built_file().expect("failed to acquire build-time information");
}
30 changes: 17 additions & 13 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "test")]
#![allow(clippy::missing_panics_doc)]

use itertools::{chain, Itertools};
pub use pacaptr_macros::test_dsl;
Expand Down Expand Up @@ -26,19 +27,22 @@ const fn cmd_prefix() -> (&'static str, &'static [&'static str]) {
}
}

#[derive(Debug)]
pub struct Test<'t> {
sequence: Vec<(Input<'t>, Vec<&'t str>)>,
pending_input: Option<Input<'t>>,
}

impl<'t> Test<'t> {
pub fn new() -> Self {
#[must_use]
pub const fn new() -> Self {
Test {
sequence: Vec::new(),
pending_input: None,
}
}

#[must_use]
pub fn pacaptr(mut self, args: &'t [&str], flags: &'t [&str]) -> Self {
// Guard against consecutive inputs without calling `self.output()`.
if self.pending_input.is_some() {
Expand All @@ -49,6 +53,7 @@ impl<'t> Test<'t> {
}

#[allow(dead_code)]
#[must_use]
pub fn exec(mut self, cmd: &'t [&str], kws: &'t [&str]) -> Self {
// Guard against consecutive inputs without calling `self.output()`.
if self.pending_input.is_some() {
Expand All @@ -58,9 +63,10 @@ impl<'t> Test<'t> {
self
}

#[must_use]
pub fn output(mut self, out: &'t [&str]) -> Self {
if let Some(cmd) = self.pending_input.take() {
self.sequence.push((cmd, out.into()))
self.sequence.push((cmd, out.into()));
} else if let Some((_cmd, outs)) = self.sequence.last_mut() {
outs.extend(out);
} else {
Expand All @@ -71,23 +77,21 @@ impl<'t> Test<'t> {

pub fn run(&self) {
let try_match = |out: &str, patterns: &[&str]| {
patterns.iter().for_each(|p| {
for &p in patterns {
let re = RegexBuilder::new(p).multi_line(true).build().unwrap();
let is_match = re.is_match(out);
assert!(is_match, "Failed with pattern `{p}`, got `{out}`")
})
assert!(is_match, "Failed with pattern `{p}`, got `{out}`");
}
};

// Prevent running the test before `self.sequence` is configured.
if self.sequence.is_empty() {
panic!("Test sequence not yet configured")
}
assert!(
!self.sequence.is_empty(),
"Test sequence not yet configured"
);

let s = Shell::new().unwrap();
self.sequence.iter().for_each(|(input, patterns)| {
// got = cmd.run()
// if not matches_all(got, patterns):
// raise MatchError(some_msg)
for (input, patterns) in &self.sequence {
let (sh, sh_args) = cmd_prefix();
let cmd = match *input {
Input::Exec { cmd, kws } => chain!(cmd, kws).join(" "),
Expand All @@ -102,7 +106,7 @@ impl<'t> Test<'t> {
.unwrap();
println!("{got}");
try_match(&got, patterns);
})
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/port.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A big part of these tests are copied from https://guide.macports.org/#using.port.installed.
//! A big part of these tests are copied from <https://guide.macports.org/#using.port.installed>.

#![cfg(all(target_os = "macos", feature = "test"))]

Expand Down

0 comments on commit 47c9477

Please sign in to comment.