Skip to content

Commit

Permalink
Fixed the integration text that relies on an interactive prompt with …
Browse files Browse the repository at this point in the history
…the rexpect crate.
  • Loading branch information
MatthiasZepper committed May 6, 2024
1 parent 6e116e2 commit 1a0df50
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ jobs:

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: tarpaulin

- name: Install tarpaulin
run: cargo install cargo-tarpaulin

- name: Cache Rust toolchain
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2
Expand All @@ -121,7 +122,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: TarpaulinCodeCoverage.xml
path: cobertura.xmlgit st
path: cobertura.xml



59 changes: 57 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gzp = "0.11.3"
assert_cmd = "2.0.14"
assert_fs = "1.1.1"
predicates = "3.1.0"
rexpect = "0.5.0"

[workspace.metadata.marker.lints]
marker_lints = "0.5.0"
27 changes: 18 additions & 9 deletions tests/integration_tests_external.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use assert_cmd::Command;
use assert_fs::prelude::*;
use predicates::prelude::*;
use std::process::Command as StdCommand;

extern crate rexpect;

#[path = "auxiliary.rs"]
mod auxiliary;
Expand Down Expand Up @@ -196,14 +199,20 @@ fn external_fails_with_nonexisting_output_file() {

#[test]
fn external_fails_with_existing_output_file_and_no_force() {
let (mut cmd, temp_dir, test_files, _test_output) = auxiliary::setup_integration_test(false);
let (_cmd, temp_dir, test_files, _test_output) = auxiliary::setup_integration_test(false);

// create an existing output file
temp_dir
.child("read1_out.fq")
.write_str("GCCATTAGCTGTACCATACTCAGGCACACAAAAATACTGATA")
.unwrap();

// This test comprises an interactive prompt, which is not supported by assert_cmd.
// Therefore, we use rexpect to run the test in a session and must use
// a different Command type: std::process::Command instead of assert_cmd::Command.

let bin_path = assert_cmd::cargo::cargo_bin("umi-transfer");
let mut cmd = StdCommand::new(bin_path);
cmd.arg("external")
.arg("--in")
.arg(test_files.read1_gz)
Expand All @@ -214,15 +223,15 @@ fn external_fails_with_existing_output_file_and_no_force() {
.arg("--out")
.arg(test_files.new_output_read1_gz)
.arg("--out2")
.arg(test_files.new_output_read2_gz)
.write_stdin("yes\n".as_bytes());
.arg(test_files.new_output_read2_gz);

cmd.assert()
.failure()
.stderr(predicate::str::contains("Failed to include the UMIs"))
//.stderr(predicate::str::contains("Caused by:"))
//.stderr(predicate::str::contains("exists. Overwrite? (y/n)"))
.stderr(predicate::str::contains("not a terminal"));
// Evaluate that the prompt is shown, but do not overwrite the existing file.

let mut p = rexpect::session::spawn_command(cmd, Some(10000)).unwrap();
p.exp_string("read1_out.fq exists. Overwrite?").unwrap();
p.send_line("n").unwrap();
p.exp_string("read1_out.fq exists, but must not be overwritten.")
.unwrap();

temp_dir
.child("read2_out.fq")
Expand Down

0 comments on commit 1a0df50

Please sign in to comment.