[tests] Change the path type to OsString for compatibility

This commit is contained in:
Ming-Hung Tsai 2021-07-20 15:07:12 +08:00
parent b92151d527
commit 66b49e6f3d
12 changed files with 61 additions and 30 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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(())
}

View File

@ -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<String> {
let command = duct::cmd(program, args).stdout_capture().stderr_capture();
pub fn run_ok<S, I>(program: S, args: I) -> Result<String>
where
S: AsRef<OsStr>,
I: IntoIterator,
I::Item: Into<OsString>,
{
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<String> {
}
// Returns the entire output. The command must return zero.
pub fn run_ok_raw(program: &str, args: &[&str]) -> Result<std::process::Output> {
let command = duct::cmd(program, args).stdout_capture().stderr_capture();
pub fn run_ok_raw<S, I>(program: S, args: I) -> Result<std::process::Output>
where
S: AsRef<OsStr>,
I: IntoIterator,
I::Item: Into<OsString>,
{
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<String> {
let command = duct::cmd(program, args).stdout_capture().stderr_capture();
pub fn run_fail<S, I>(program: S, args: I) -> Result<String>
where
S: AsRef<OsStr>,
I: IntoIterator,
I::Item: Into<OsString>,
{
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<String> {
}
// Returns the entire output, a non zero status must be returned
pub fn run_fail_raw(program: &str, args: &[&str]) -> Result<std::process::Output> {
let command = duct::cmd(program, args).stdout_capture().stderr_capture();
pub fn run_fail_raw<S, I>(program: S, args: I) -> Result<std::process::Output>
where
S: AsRef<OsStr>,
I: IntoIterator,
I::Item: Into<OsString>,
{
let command = duct::cmd(program.as_ref(), args)
.stdout_capture()
.stderr_capture();
let output = command.unchecked().run()?;
assert!(!output.status.success());
Ok(output)

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {