mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-09 19:11:03 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cb8b4a100d |
+1
-1
@@ -8,7 +8,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2024"
|
||||
repository = "https://github.com/paritytech/revive-differential-testing.git"
|
||||
rust-version = "1.88.0"
|
||||
rust-version = "1.85.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
revive-dt-common = { version = "0.1.0", path = "crates/common" }
|
||||
|
||||
+33
-12
@@ -17,7 +17,25 @@ impl Corpus {
|
||||
/// Try to read and parse the corpus definition file at given `path`.
|
||||
pub fn try_from_path(path: &Path) -> anyhow::Result<Self> {
|
||||
let file = File::open(path)?;
|
||||
Ok(serde_json::from_reader(file)?)
|
||||
let mut corpus: Corpus = serde_json::from_reader(file)?;
|
||||
|
||||
// Ensure that the path mentioned in the corpus is relative to the corpus file.
|
||||
// Canonicalizing also helps make the path in any errors unambiguous.
|
||||
corpus.path = path
|
||||
.parent()
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("Corpus path '{}' does not point to a file", path.display())
|
||||
})?
|
||||
.canonicalize()
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
"Failed to canonicalize path to corpus '{}': {error}",
|
||||
path.display()
|
||||
)
|
||||
})?
|
||||
.join(corpus.path);
|
||||
|
||||
Ok(corpus)
|
||||
}
|
||||
|
||||
/// Scan the corpus base directory and return all tests found.
|
||||
@@ -28,19 +46,13 @@ impl Corpus {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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].
|
||||
/// Recursively walks `path` and parses any JSON or Solidity file into a test
|
||||
/// definition [Metadata].
|
||||
///
|
||||
/// Found tests are inserted into `tests`.
|
||||
///
|
||||
/// `path` is expected to be a directory.
|
||||
pub fn collect_metadata(path: &Path, tests: &mut Vec<MetadataFile>) {
|
||||
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) => {
|
||||
@@ -59,6 +71,15 @@ pub fn collect_metadata(path: &Path, tests: &mut Vec<MetadataFile>) {
|
||||
};
|
||||
|
||||
let path = entry.path();
|
||||
collect_metadata(&path, tests);
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user