Skip to content

Commit 1b61178

Browse files
committed
refactor
1 parent e4f7995 commit 1b61178

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

gix-attributes/fuzz/fuzz_targets/fuzz_search.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use anyhow::Result;
44
use libfuzzer_sys::fuzz_target;
55

66
use std::hint::black_box;
7-
use std::path::Path;
87

98
use arbitrary::{Arbitrary, Unstructured};
109
use gix_attributes::{
@@ -17,44 +16,26 @@ fn arbitrary_case(u: &mut Unstructured) -> arbitrary::Result<Case> {
1716
Ok(*u.choose(&[Case::Sensitive, Case::Fold])?)
1817
}
1918

20-
fn arbitrary_relative_path<'a>(u: &mut Unstructured<'a>) -> arbitrary::Result<&'a str> {
21-
let mut path = <&str>::arbitrary(u)?;
22-
if path.starts_with("/") {
23-
path = path.trim_start_matches("/");
24-
}
25-
Ok(path)
26-
}
27-
2819
#[derive(Debug, Arbitrary)]
2920
struct Ctx<'a> {
3021
pattern: &'a str,
31-
#[arbitrary(with = arbitrary_relative_path)]
32-
path: &'a str,
33-
relative_containing_dir: Option<&'a str>,
3422
#[arbitrary(with = arbitrary_case)]
3523
case: Case,
3624
}
3725

38-
fn fuzz(ctx: Ctx) -> Result<()> {
39-
let Ctx {
40-
pattern,
41-
path,
42-
relative_containing_dir,
43-
case,
44-
} = ctx;
45-
26+
fn fuzz(Ctx { pattern, case }: Ctx) -> Result<()> {
4627
let mut search = Search::default();
4728
let mut collection = MetadataCollection::default();
4829
search.add_patterns_buffer(
49-
format!("{pattern} test").as_bytes(),
50-
relative_containing_dir.map_or_else(|| Path::new("<memory>").into(), |d| Path::new(d).join("filename")),
51-
relative_containing_dir.map(|_| Path::new("")),
30+
format!("{pattern} attr").as_bytes(),
31+
Default::default(),
32+
None,
5233
&mut collection,
5334
true,
5435
);
5536
let mut out = Outcome::default();
5637
out.initialize(&collection);
57-
_ = black_box(search.pattern_matching_relative_path(path.into(), case, None, &mut out));
38+
_ = black_box(search.pattern_matching_relative_path("relative/path".into(), case, None, &mut out));
5839
Ok(())
5940
}
6041

0 commit comments

Comments
 (0)