Skip to main content

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    /// Omit progress output
38    #[arg(long)]
39    omit_progress: bool,
40    /// Keep going after a test failure
41    #[arg(long, alias = "no-fail-fast")]
42    keep_going: bool,
43}
44
45impl Cmd {
46    /// Runs `statetest` command.
47    pub fn run(&self) -> Result<(), TestError> {
48        for path in &self.paths {
49            if !path.exists() {
50                return Err(TestError {
51                    name: "Path validation".to_string(),
52                    path: path.display().to_string(),
53                    kind: TestErrorKind::InvalidPath,
54                });
55            }
56
57            println!("\nRunning tests in {}...", path.display());
58            let test_files = find_all_json_tests(path);
59
60            if test_files.is_empty() {
61                return Err(TestError {
62                    name: "Path validation".to_string(),
63                    path: path.display().to_string(),
64                    kind: TestErrorKind::NoJsonFiles,
65                });
66            }
67
68            run(
69                test_files,
70                self.single_thread,
71                self.json,
72                self.json_outcome,
73                self.keep_going,
74                self.omit_progress,
75            )?
76        }
77        Ok(())
78    }
79}