revme/cmd/
statetest.rs

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