Skip to content

Commit d9afbea

Browse files
chore: add check for path and existence existence
1 parent 76e1266 commit d9afbea

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

bins/revme/src/cmd/statetest.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod merkle_trie;
22
mod runner;
33
pub mod utils;
44

5-
pub use runner::TestError as Error;
5+
pub use runner::{TestError as Error, TestErrorKind};
66

77
use clap::Parser;
88
use runner::{find_all_json_tests, run, TestError};
@@ -42,8 +42,25 @@ impl Cmd {
4242
/// Runs `statetest` command.
4343
pub fn run(&self) -> Result<(), TestError> {
4444
for path in &self.paths {
45+
if !path.exists() {
46+
return Err(TestError {
47+
name: "Path validation".to_string(),
48+
path: path.display().to_string(),
49+
kind: TestErrorKind::InvalidPath,
50+
});
51+
}
52+
4553
println!("\nRunning tests in {}...", path.display());
4654
let test_files = find_all_json_tests(path);
55+
56+
if test_files.is_empty() {
57+
return Err(TestError {
58+
name: "Path validation".to_string(),
59+
path: path.display().to_string(),
60+
kind: TestErrorKind::NoJsonFiles,
61+
});
62+
}
63+
4764
run(
4865
test_files,
4966
self.single_thread,

bins/revme/src/cmd/statetest/runner.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ pub enum TestErrorKind {
6666
SerdeDeserialize(#[from] serde_json::Error),
6767
#[error("thread panicked")]
6868
Panic,
69+
#[error("path does not exist")]
70+
InvalidPath,
71+
#[error("no JSON test files found in path")]
72+
NoJsonFiles,
6973
}
7074

7175
pub fn find_all_json_tests(path: &Path) -> Vec<PathBuf> {

0 commit comments

Comments
 (0)