From d9afbea97d2a4ab0692ad170f7f98145add2de0c Mon Sep 17 00:00:00 2001 From: startup-dreamer Date: Thu, 27 Mar 2025 05:23:25 +0530 Subject: [PATCH] chore: add check for path and existence existence --- bins/revme/src/cmd/statetest.rs | 19 ++++++++++++++++++- bins/revme/src/cmd/statetest/runner.rs | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bins/revme/src/cmd/statetest.rs b/bins/revme/src/cmd/statetest.rs index bac92b6fbe..3094316d53 100644 --- a/bins/revme/src/cmd/statetest.rs +++ b/bins/revme/src/cmd/statetest.rs @@ -2,7 +2,7 @@ pub mod merkle_trie; mod runner; pub mod utils; -pub use runner::TestError as Error; +pub use runner::{TestError as Error, TestErrorKind}; use clap::Parser; use runner::{find_all_json_tests, run, TestError}; @@ -42,8 +42,25 @@ impl Cmd { /// Runs `statetest` command. pub fn run(&self) -> Result<(), TestError> { for path in &self.paths { + if !path.exists() { + return Err(TestError { + name: "Path validation".to_string(), + path: path.display().to_string(), + kind: TestErrorKind::InvalidPath, + }); + } + println!("\nRunning tests in {}...", path.display()); let test_files = find_all_json_tests(path); + + if test_files.is_empty() { + return Err(TestError { + name: "Path validation".to_string(), + path: path.display().to_string(), + kind: TestErrorKind::NoJsonFiles, + }); + } + run( test_files, self.single_thread, diff --git a/bins/revme/src/cmd/statetest/runner.rs b/bins/revme/src/cmd/statetest/runner.rs index 544b8dc3ac..5ec5186dc3 100644 --- a/bins/revme/src/cmd/statetest/runner.rs +++ b/bins/revme/src/cmd/statetest/runner.rs @@ -66,6 +66,10 @@ pub enum TestErrorKind { SerdeDeserialize(#[from] serde_json::Error), #[error("thread panicked")] Panic, + #[error("path does not exist")] + InvalidPath, + #[error("no JSON test files found in path")] + NoJsonFiles, } pub fn find_all_json_tests(path: &Path) -> Vec {