diff --git a/tests/cache_check.rs b/tests/cache_check.rs index f89c182..6b6b668 100644 --- a/tests/cache_check.rs +++ b/tests/cache_check.rs @@ -29,8 +29,8 @@ impl<'a> Program<'a> for CacheCheck { "cache_check" } - fn path() -> &'a str { - CACHE_CHECK + fn path() -> &'a std::ffi::OsStr { + CACHE_CHECK.as_ref() } fn usage() -> &'a str { diff --git a/tests/cache_dump.rs b/tests/cache_dump.rs index a8f3754..365d69b 100644 --- a/tests/cache_dump.rs +++ b/tests/cache_dump.rs @@ -25,8 +25,8 @@ impl<'a> Program<'a> for CacheDump { "cache_dump" } - fn path() -> &'a str { - CACHE_DUMP + fn path() -> &'a std::ffi::OsStr { + CACHE_DUMP.as_ref() } fn usage() -> &'a str { diff --git a/tests/common/input_arg.rs b/tests/common/input_arg.rs index 4e096db..20feac4 100644 --- a/tests/common/input_arg.rs +++ b/tests/common/input_arg.rs @@ -53,7 +53,8 @@ pub fn test_missing_input_arg<'a, P>() -> Result<()> where P: InputProgram<'a>, { - let stderr = run_fail(P::path(), &[])?; + let args: [&str; 0] = []; + let stderr = run_fail(P::path(), &args)?; assert!(stderr.contains(P::missing_input_arg())); Ok(()) } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a4801aa..e9dffd8 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,9 +1,11 @@ #![allow(dead_code)] use anyhow::Result; +use std::ffi::{OsStr, OsString}; use std::fs::OpenOptions; use std::io::{Read, Write}; use std::path::PathBuf; + use thinp::file_utils; use thinp::io_engine::*; @@ -104,7 +106,7 @@ pub enum ArgType { pub trait Program<'a> { fn name() -> &'a str; - fn path() -> &'a str; + fn path() -> &'a OsStr; fn usage() -> &'a str; fn arg_type() -> ArgType; @@ -134,8 +136,15 @@ pub trait BinaryOutputProgram<'a>: OutputProgram<'a> {} //------------------------------------------ // Returns stdout. The command must return zero. -pub fn run_ok(program: &str, args: &[&str]) -> Result { - let command = duct::cmd(program, args).stdout_capture().stderr_capture(); +pub fn run_ok(program: S, args: I) -> Result +where + S: AsRef, + I: IntoIterator, + I::Item: Into, +{ + let command = duct::cmd(program.as_ref(), args) + .stdout_capture() + .stderr_capture(); let output = command.run()?; assert!(output.status.success()); let stdout = std::str::from_utf8(&output.stdout[..]) @@ -146,16 +155,30 @@ pub fn run_ok(program: &str, args: &[&str]) -> Result { } // Returns the entire output. The command must return zero. -pub fn run_ok_raw(program: &str, args: &[&str]) -> Result { - let command = duct::cmd(program, args).stdout_capture().stderr_capture(); +pub fn run_ok_raw(program: S, args: I) -> Result +where + S: AsRef, + I: IntoIterator, + I::Item: Into, +{ + let command = duct::cmd(program.as_ref(), args) + .stdout_capture() + .stderr_capture(); let output = command.run()?; assert!(output.status.success()); Ok(output) } // Returns stderr, a non zero status must be returned -pub fn run_fail(program: &str, args: &[&str]) -> Result { - let command = duct::cmd(program, args).stdout_capture().stderr_capture(); +pub fn run_fail(program: S, args: I) -> Result +where + S: AsRef, + I: IntoIterator, + I::Item: Into, +{ + let command = duct::cmd(program.as_ref(), args) + .stdout_capture() + .stderr_capture(); let output = command.unchecked().run()?; assert!(!output.status.success()); let stderr = std::str::from_utf8(&output.stderr[..]).unwrap().to_string(); @@ -163,8 +186,15 @@ pub fn run_fail(program: &str, args: &[&str]) -> Result { } // Returns the entire output, a non zero status must be returned -pub fn run_fail_raw(program: &str, args: &[&str]) -> Result { - let command = duct::cmd(program, args).stdout_capture().stderr_capture(); +pub fn run_fail_raw(program: S, args: I) -> Result +where + S: AsRef, + I: IntoIterator, + I::Item: Into, +{ + let command = duct::cmd(program.as_ref(), args) + .stdout_capture() + .stderr_capture(); let output = command.unchecked().run()?; assert!(!output.status.success()); Ok(output) diff --git a/tests/thin_check.rs b/tests/thin_check.rs index 577a34d..bfe1161 100644 --- a/tests/thin_check.rs +++ b/tests/thin_check.rs @@ -31,8 +31,8 @@ impl<'a> Program<'a> for ThinCheck { "thin_check" } - fn path() -> &'a str { - THIN_CHECK + fn path() -> &'a std::ffi::OsStr { + THIN_CHECK.as_ref() } fn usage() -> &'a str { diff --git a/tests/thin_delta.rs b/tests/thin_delta.rs index c9256a8..7455f10 100644 --- a/tests/thin_delta.rs +++ b/tests/thin_delta.rs @@ -26,8 +26,8 @@ impl<'a> Program<'a> for ThinDelta { "thin_delta" } - fn path() -> &'a str { - THIN_DELTA + fn path() -> &'a std::ffi::OsStr { + THIN_DELTA.as_ref() } fn usage() -> &'a str { diff --git a/tests/thin_dump.rs b/tests/thin_dump.rs index 6d6eb11..2f1fae6 100644 --- a/tests/thin_dump.rs +++ b/tests/thin_dump.rs @@ -32,8 +32,8 @@ impl<'a> Program<'a> for ThinDump { "thin_dump" } - fn path() -> &'a str { - THIN_DUMP + fn path() -> &'a std::ffi::OsStr { + THIN_DUMP.as_ref() } fn usage() -> &'a str { diff --git a/tests/thin_metadata_pack.rs b/tests/thin_metadata_pack.rs index 616bc83..bbcb8c0 100644 --- a/tests/thin_metadata_pack.rs +++ b/tests/thin_metadata_pack.rs @@ -36,8 +36,8 @@ impl<'a> Program<'a> for ThinMetadataPack { "thin_metadata_pack" } - fn path() -> &'a str { - THIN_METADATA_PACK + fn path() -> &'a std::ffi::OsStr { + THIN_METADATA_PACK.as_ref() } fn usage() -> &'a str { diff --git a/tests/thin_metadata_unpack.rs b/tests/thin_metadata_unpack.rs index 9a66d58..3702e73 100644 --- a/tests/thin_metadata_unpack.rs +++ b/tests/thin_metadata_unpack.rs @@ -36,8 +36,8 @@ impl<'a> Program<'a> for ThinMetadataUnpack { "thin_metadata_pack" } - fn path() -> &'a str { - THIN_METADATA_UNPACK + fn path() -> &'a std::ffi::OsStr { + THIN_METADATA_UNPACK.as_ref() } fn usage() -> &'a str { diff --git a/tests/thin_repair.rs b/tests/thin_repair.rs index aa2deba..e9b3b92 100644 --- a/tests/thin_repair.rs +++ b/tests/thin_repair.rs @@ -29,8 +29,8 @@ impl<'a> Program<'a> for ThinRepair { "thin_repair" } - fn path() -> &'a str { - THIN_REPAIR + fn path() -> &'a std::ffi::OsStr { + THIN_REPAIR.as_ref() } fn usage() -> &'a str { diff --git a/tests/thin_restore.rs b/tests/thin_restore.rs index 5208d71..7408be0 100644 --- a/tests/thin_restore.rs +++ b/tests/thin_restore.rs @@ -30,8 +30,8 @@ impl<'a> Program<'a> for ThinRestore { "thin_restore" } - fn path() -> &'a str { - THIN_RESTORE + fn path() -> &'a std::ffi::OsStr { + THIN_RESTORE.as_ref() } fn usage() -> &'a str { diff --git a/tests/thin_rmap.rs b/tests/thin_rmap.rs index 1acae99..bdee4cd 100644 --- a/tests/thin_rmap.rs +++ b/tests/thin_rmap.rs @@ -26,8 +26,8 @@ impl<'a> Program<'a> for ThinRmap { "thin_rmap" } - fn path() -> &'a str { - THIN_RMAP + fn path() -> &'a std::ffi::OsStr { + THIN_RMAP.as_ref() } fn usage() -> &'a str {