From ce3aaf1888ed0b010841110fd5240189b57e4255 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Mon, 28 Jul 2025 15:51:55 +0100 Subject: [PATCH] Allow the corpus to point to a single file --- Cargo.toml | 2 +- crates/format/src/corpus.rs | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d077231..1c73bca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ authors = ["Parity Technologies "] license = "MIT/Apache-2.0" edition = "2024" repository = "https://github.com/paritytech/revive-differential-testing.git" -rust-version = "1.85.0" +rust-version = "1.88.0" [workspace.dependencies] revive-dt-common = { version = "0.1.0", path = "crates/common" } diff --git a/crates/format/src/corpus.rs b/crates/format/src/corpus.rs index 602a669..cdc28d7 100644 --- a/crates/format/src/corpus.rs +++ b/crates/format/src/corpus.rs @@ -28,13 +28,19 @@ impl Corpus { } } -/// Recursively walks `path` and parses any JSON or Solidity file into a test -/// definition [Metadata]. +/// If `path` is a file, try to parse it directly into a [MetadataFile]. +/// Else, recursively walk through the `path` directory and parse any +/// JSON or Solidity file into a test definition [MetadataFile]. /// /// Found tests are inserted into `tests`. -/// -/// `path` is expected to be a directory. pub fn collect_metadata(path: &Path, tests: &mut Vec) { + if path.is_file() + && let Some(metadata) = MetadataFile::try_from_file(&path) + { + tests.push(metadata); + return; + } + let dir_entry = match std::fs::read_dir(path) { Ok(dir_entry) => dir_entry, Err(error) => { @@ -53,15 +59,6 @@ pub fn collect_metadata(path: &Path, tests: &mut Vec) { }; let path = entry.path(); - if path.is_dir() { - collect_metadata(&path, tests); - continue; - } - - if path.is_file() { - if let Some(metadata) = MetadataFile::try_from_file(&path) { - tests.push(metadata) - } - } + collect_metadata(&path, tests); } }