diff --git a/triton-tui/Cargo.toml b/triton-tui/Cargo.toml index e4c9d82cf..5324c93ef 100644 --- a/triton-tui/Cargo.toml +++ b/triton-tui/Cargo.toml @@ -29,6 +29,7 @@ lazy_static.workspace = true libc = "0.2" num-traits.workspace = true ratatui = { version = "0.25", features = ["serde", "macros"] } +rexpect = { version = "0.5", optional = true } serde.workspace = true serde_json = "1.0" signal-hook = "0.3" @@ -47,7 +48,6 @@ assert2.workspace = true pretty_assertions.workspace = true proptest.workspace = true proptest-arbitrary-interop.workspace = true -rexpect = "0.5" test-strategy.workspace = true [build-dependencies] @@ -56,6 +56,10 @@ clap_complete = "4.4" directories.workspace = true lazy_static.workspace = true +[features] +default = [] +integration-tests = ["rexpect"] + [[bin]] name = "triton-tui" path = "src/main.rs" diff --git a/triton-tui/tests/tests.rs b/triton-tui/tests/tests.rs index dfdb220e9..f9aa85fb6 100644 --- a/triton-tui/tests/tests.rs +++ b/triton-tui/tests/tests.rs @@ -1,75 +1,82 @@ -use std::path::PathBuf; +//! Integration tests for the triton-tui binary. Currently ignored for two reasons: +//! 1. They break code-coverage tool `cargo-tarpaulin`. +//! 2. The crate `rexpect` does not compile on Windows. -use assert2::let_assert; -use rexpect::error::Error; -use rexpect::session::PtySession; -use rexpect::spawn; +#[cfg(test)] +#[cfg(feature = "integration-tests")] +mod tests { + use std::path::PathBuf; -#[test] -#[ignore = "breaks code-coverage tool `cargo-tarpaulin`"] -fn setup_and_shutdown_triton_tui_with_trivial_program() { - let program = manifest_dir().join("tests/trivial_program.tasm"); - let timeout = Some(180_000); - let mut child = setup_and_start_triton_tui_with_program(program, timeout); - let_assert!(Ok(_) = child.send_line("q")); - let_assert!(Ok(_) = child.exp_eof()); -} + use assert2::let_assert; + use rexpect::error::Error; + use rexpect::session::PtySession; + use rexpect::spawn; -#[test] -#[ignore = "breaks code-coverage tool `cargo-tarpaulin`"] -fn setup_without_shutdown_of_triton_tui_with_trivial_program_leaves_tui_open() { - let program = manifest_dir().join("tests/trivial_program.tasm"); - let timeout = Some(10_000); - let mut child = setup_and_start_triton_tui_with_program(program, timeout); - let_assert!(Err(Error::Timeout { .. }) = child.exp_eof()); -} + #[test] + fn setup_and_shutdown_triton_tui_with_trivial_program() { + let program = manifest_dir().join("tests/trivial_program.tasm"); + let timeout = Some(180_000); + let mut child = setup_and_start_triton_tui_with_program(program, timeout); + let_assert!(Ok(_) = child.send_line("q")); + let_assert!(Ok(_) = child.exp_eof()); + } -#[test] -#[ignore = "breaks code-coverage tool `cargo-tarpaulin`"] -fn starting_triton_tui_on_program_with_infinite_loop_gives_control_back_to_user() { - let program = manifest_dir().join("tests/infinite_loop.tasm"); - let timeout = Some(180_000); - let mut child = setup_and_start_triton_tui_with_program(program, timeout); - let_assert!(Ok(_) = child.send_line("q")); - let_assert!(Ok(_) = child.exp_eof()); -} + #[test] + fn setup_without_shutdown_of_triton_tui_with_trivial_program_leaves_tui_open() { + let program = manifest_dir().join("tests/trivial_program.tasm"); + let timeout = Some(10_000); + let mut child = setup_and_start_triton_tui_with_program(program, timeout); + let_assert!(Err(Error::Timeout { .. }) = child.exp_eof()); + } -fn setup_and_start_triton_tui_with_program(program: PathBuf, timeout: Option) -> PtySession { - assert!(program.exists()); - let_assert!(Some(program) = program.to_str()); + #[test] + fn starting_triton_tui_on_program_with_infinite_loop_gives_control_back_to_user() { + let program = manifest_dir().join("tests/infinite_loop.tasm"); + let timeout = Some(180_000); + let mut child = setup_and_start_triton_tui_with_program(program, timeout); + let_assert!(Ok(_) = child.send_line("q")); + let_assert!(Ok(_) = child.exp_eof()); + } - let command = format!("cargo run --offline --bin triton-tui -- {program}"); - let_assert!(Ok(child) = spawn(&command, timeout)); - child -} + fn setup_and_start_triton_tui_with_program( + program: PathBuf, + timeout: Option, + ) -> PtySession { + assert!(program.exists()); + let_assert!(Some(program) = program.to_str()); -#[test] -#[ignore = "breaks code-coverage tool `cargo-tarpaulin`"] -fn setup_and_shutdown_triton_tui_with_example_initial_state() { - let timeout = Some(180_000); - let mut child = setup_and_start_triton_tui_with_example_initial_state(timeout); - let_assert!(Ok(_) = child.send_line("q")); - let_assert!(Ok(_) = child.exp_eof()); -} + let command = format!("cargo run --offline --bin triton-tui -- {program}"); + let_assert!(Ok(child) = spawn(&command, timeout)); + child + } + + #[test] + fn setup_and_shutdown_triton_tui_with_example_initial_state() { + let timeout = Some(180_000); + let mut child = setup_and_start_triton_tui_with_example_initial_state(timeout); + let_assert!(Ok(_) = child.send_line("q")); + let_assert!(Ok(_) = child.exp_eof()); + } -fn setup_and_start_triton_tui_with_example_initial_state(timeout: Option) -> PtySession { - let path_to_trivial_program = manifest_dir().join("examples/program.tasm"); - assert!(path_to_trivial_program.exists()); - let_assert!(Some(path_to_trivial_program) = path_to_trivial_program.to_str()); + fn setup_and_start_triton_tui_with_example_initial_state(timeout: Option) -> PtySession { + let path_to_trivial_program = manifest_dir().join("examples/program.tasm"); + assert!(path_to_trivial_program.exists()); + let_assert!(Some(path_to_trivial_program) = path_to_trivial_program.to_str()); - let path_to_initial_state = manifest_dir().join("examples/initial_state.json"); - assert!(path_to_initial_state.exists()); - let_assert!(Some(path_to_initial_state) = path_to_initial_state.to_str()); + let path_to_initial_state = manifest_dir().join("examples/initial_state.json"); + assert!(path_to_initial_state.exists()); + let_assert!(Some(path_to_initial_state) = path_to_initial_state.to_str()); - let command = format!( - "cargo run --offline --bin triton-tui -- \ + let command = format!( + "cargo run --offline --bin triton-tui -- \ {path_to_trivial_program} --initial_state {path_to_initial_state}" - ); - let_assert!(Ok(child) = spawn(&command, timeout)); - child -} + ); + let_assert!(Ok(child) = spawn(&command, timeout)); + child + } -/// The directory containing the Cargo.toml file. -fn manifest_dir() -> PathBuf { - PathBuf::from(env!("CARGO_MANIFEST_DIR")) + /// The directory containing the Cargo.toml file. + fn manifest_dir() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + } }