revme/cmd/
statetest.rs

1pub mod merkle_trie;
2mod runner;
3pub mod utils;
4
5pub use runner::{TestError as Error, TestErrorKind};
6
7use crate::dir_utils::find_all_json_tests;
8use clap::Parser;
9use runner::{run, TestError};
10use std::path::PathBuf;
11
12/// `statetest` subcommand
13#[derive(Parser, Debug)]
14pub struct Cmd {
15    /// Path to folder or file containing the tests
16    ///
17    /// If multiple paths are specified they will be run in sequence.
18    ///
19    /// Folders will be searched recursively for files with the extension `.json`.
20    #[arg(required = true, num_args = 1..)]
21    paths: Vec<PathBuf>,
22    /// Run tests in a single thread
23    #[arg(short = 's', long)]
24    single_thread: bool,
25    /// Output results in JSON format
26    ///
27    /// It will stop second run of evm on failure.
28    #[arg(long)]
29    json: bool,
30    /// Output outcome in JSON format
31    ///
32    /// If `--json` is true, this is implied.
33    ///
34    /// It will stop second run of EVM on failure.
35    #[arg(short = 'o', long)]
36    json_outcome: bool,
37    /// Keep going after a test failure
38    #[arg(long, alias = "no-fail-fast")]
39    keep_going: bool,
40}
41
42impl Cmd {
43    /// Runs `statetest` command.
44    pub fn run(&self) -> Result<(), TestError> {
45        for path in &self.paths {
46            if !path.exists() {
47                return Err(TestError {
48                    name: "Path validation".to_string(),
49                    path: path.display().to_string(),
50                    kind: TestErrorKind::InvalidPath,
51                });
52            }
53
54            println!("\nRunning tests in {}...", path.display());
55            let test_files = find_all_json_tests(path);
56
57            if test_files.is_empty() {
58                return Err(TestError {
59                    name: "Path validation".to_string(),
60                    path: path.display().to_string(),
61                    kind: TestErrorKind::NoJsonFiles,
62                });
63            }
64
65            run(
66                test_files,
67                self.single_thread,
68                self.json,
69                self.json_outcome,
70                self.keep_going,
71            )?
72        }
73        Ok(())
74    }
75}