| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
use std::path::Path; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
fn replay(dir: &Path) -> usize { |
| 24 |
let Ok(entries) = std::fs::read_dir(dir) else { |
| 25 |
return 0; |
| 26 |
}; |
| 27 |
|
| 28 |
let mut count = 0; |
| 29 |
for entry in entries { |
| 30 |
let path = entry.expect("readable dir entry").path(); |
| 31 |
if !path.is_file() { |
| 32 |
continue; |
| 33 |
} |
| 34 |
|
| 35 |
if path.extension().is_some_and(|e| e == "md") { |
| 36 |
continue; |
| 37 |
} |
| 38 |
|
| 39 |
let bytes = std::fs::read(&path).expect("readable input"); |
| 40 |
|
| 41 |
let Ok(line) = std::str::from_utf8(&bytes) else { |
| 42 |
continue; |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
let outcome = std::panic::catch_unwind(|| git_command::oracle::check_line(line)); |
| 48 |
assert!( |
| 49 |
outcome.is_ok(), |
| 50 |
"oracle failed on {}: {line:?}", |
| 51 |
path.display() |
| 52 |
); |
| 53 |
count += 1; |
| 54 |
} |
| 55 |
count |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn every_seed_holds_the_oracle() { |
| 60 |
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("fuzz/seeds/command"); |
| 61 |
let n = replay(&dir); |
| 62 |
|
| 63 |
|
| 64 |
assert!( |
| 65 |
n >= 20, |
| 66 |
"expected the committed seed corpus, found {n} inputs" |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
#[test] |
| 71 |
fn every_regression_holds_the_oracle() { |
| 72 |
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("fuzz/regressions"); |
| 73 |
|
| 74 |
|
| 75 |
replay(&dir); |
| 76 |
} |
| 77 |
|