Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions bins/revme/src/cmd/blockchaintest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod post_block;
pub mod pre_block;

use crate::dir_utils::find_all_json_tests;
use clap::Parser;

use revm::statetest_types::blockchain::{
Expand All @@ -26,7 +27,6 @@ use std::{
time::Instant,
};
use thiserror::Error;
use walkdir::{DirEntry, WalkDir};

/// Panics if the value cannot be serialized to JSON.
fn print_json<T: serde::Serialize>(value: &T) {
Expand Down Expand Up @@ -86,22 +86,6 @@ impl Cmd {
}
}

/// Find all JSON test files in the given path
/// If path is a file, returns it in a vector
/// If path is a directory, recursively finds all .json files
pub fn find_all_json_tests(path: &Path) -> Vec<PathBuf> {
if path.is_file() {
vec![path.to_path_buf()]
} else {
WalkDir::new(path)
.into_iter()
.filter_map(Result::ok)
.filter(|e| e.path().extension() == Some("json".as_ref()))
.map(DirEntry::into_path)
.collect()
}
}

/// Run all blockchain tests from the given files
fn run_tests(
test_files: Vec<PathBuf>,
Expand Down
3 changes: 2 additions & 1 deletion bins/revme/src/cmd/statetest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ pub mod utils;

pub use runner::{TestError as Error, TestErrorKind};

use crate::dir_utils::find_all_json_tests;
use clap::Parser;
use runner::{find_all_json_tests, run, TestError};
use runner::{run, TestError};
use std::path::PathBuf;

/// `statetest` subcommand
Expand Down
17 changes: 0 additions & 17 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::{
time::{Duration, Instant},
};
use thiserror::Error;
use walkdir::{DirEntry, WalkDir};

/// Error that occurs during test execution
#[derive(Debug, Error)]
Expand Down Expand Up @@ -66,22 +65,6 @@ pub enum TestErrorKind {
NoJsonFiles,
}

/// Find all JSON test files in the given path
/// If path is a file, returns it in a vector
/// If path is a directory, recursively finds all .json files
pub fn find_all_json_tests(path: &Path) -> Vec<PathBuf> {
if path.is_file() {
vec![path.to_path_buf()]
} else {
WalkDir::new(path)
.into_iter()
.filter_map(Result::ok)
.filter(|e| e.path().extension() == Some("json".as_ref()))
.map(DirEntry::into_path)
.collect()
}
}

/// Check if a test should be skipped based on its filename
/// Some tests are known to be problematic or take too long
fn skip_test(path: &Path) -> bool {
Expand Down
24 changes: 13 additions & 11 deletions bins/revme/src/dir_utils.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use std::path::{Path, PathBuf};
use walkdir::{DirEntry, WalkDir};

/// Find all JSON test files in the given path.
/// If path is a file, returns it in a vector.
/// If path is a directory, recursively finds all .json files.
pub fn find_all_json_tests(path: &Path) -> Vec<PathBuf> {
WalkDir::new(path)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| {
e.path()
.extension()
.map(|ext| ext == "json")
.unwrap_or(false)
})
.map(DirEntry::into_path)
.collect::<Vec<PathBuf>>()
if path.is_file() {
vec![path.to_path_buf()]
} else {
WalkDir::new(path)
.into_iter()
.filter_map(Result::ok)
.filter(|e| e.path().extension() == Some("json".as_ref()))
.map(DirEntry::into_path)
.collect()
}
}
Loading