From 1a0df50954f49647e7917048438bd05aae462bc7 Mon Sep 17 00:00:00 2001 From: Matthias Zepper Date: Thu, 2 May 2024 22:03:42 +0200 Subject: [PATCH] Fixed the integration text that relies on an interactive prompt with the rexpect crate. --- .github/workflows/testing.yml | 7 ++-- Cargo.lock | 59 ++++++++++++++++++++++++++++- Cargo.toml | 1 + tests/integration_tests_external.rs | 27 ++++++++----- 4 files changed, 80 insertions(+), 14 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e96ef5e..62f2e23 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -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 @@ -121,7 +122,7 @@ jobs: - uses: actions/upload-artifact@v4 with: name: TarpaulinCodeCoverage.xml - path: cobertura.xmlgit st + path: cobertura.xml diff --git a/Cargo.lock b/Cargo.lock index d5d2f28..0d9af00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" @@ -307,6 +313,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "comma" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335" + [[package]] name = "console" version = "0.15.8" @@ -592,7 +604,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" dependencies = [ - "bitflags", + "bitflags 2.5.0", "ignore", "walkdir", ] @@ -810,6 +822,15 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -888,6 +909,20 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "nix" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "libc", + "memoffset", + "pin-utils", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -1003,6 +1038,12 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.30" @@ -1138,6 +1179,19 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "rexpect" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01ff60778f96fb5a48adbe421d21bf6578ed58c0872d712e7e08593c195adff8" +dependencies = [ + "comma", + "nix", + "regex", + "tempfile", + "thiserror", +] + [[package]] name = "rustc_version" version = "0.1.7" @@ -1153,7 +1207,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -1387,6 +1441,7 @@ dependencies = [ "owo-colors", "predicates", "regex", + "rexpect", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7ffda87..578272c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/tests/integration_tests_external.rs b/tests/integration_tests_external.rs index 4ee3345..ad36362 100644 --- a/tests/integration_tests_external.rs +++ b/tests/integration_tests_external.rs @@ -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; @@ -196,7 +199,7 @@ 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 @@ -204,6 +207,12 @@ fn external_fails_with_existing_output_file_and_no_force() { .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) @@ -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")