Skip to content

Commit

Permalink
fix(test): don't compile Triton TUI integration tests
Browse files Browse the repository at this point in the history
Firstly, they are currently ignored anyway since they break
code-coverage tool `cargo tarpaulin`. Secondly, they fail to compile
on Windows.
  • Loading branch information
jan-ferdinand committed Jan 4, 2024
1 parent 42ff061 commit bf46f5a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 63 deletions.
6 changes: 5 additions & 1 deletion triton-tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand All @@ -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"
Expand Down
131 changes: 69 additions & 62 deletions triton-tui/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -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<u64>) -> 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<u64>,
) -> 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<u64>) -> 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<u64>) -> 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"))
}
}

0 comments on commit bf46f5a

Please sign in to comment.