[tests] Refine the test naming and error messages

- Make the naming of test cases less ambiguous, e.g., rename
  "missing_input_file" to "missing_input_arg" or "input_file_not_found"
- Unify the error messages on input/output options
This commit is contained in:
Ming-Hung Tsai
2021-06-23 17:42:41 +08:00
parent d00388f68a
commit 6660fde3c4
7 changed files with 49 additions and 28 deletions

View File

@@ -40,16 +40,16 @@ fn accepts_help() -> Result<()> {
}
#[test]
fn missing_metadata() -> Result<()> {
fn missing_input_arg() -> Result<()> {
let stderr = run_fail(cache_check!())?;
assert!(stderr.contains(msg::MISSING_INPUT_ARG));
Ok(())
}
#[test]
fn no_such_metadata() -> Result<()> {
fn input_file_not_found() -> Result<()> {
let stderr = run_fail(cache_check!("/arbitrary/filename"))?;
assert!(stderr.contains("No such file or directory"));
assert!(stderr.contains(msg::FILE_NOT_FOUND));
Ok(())
}

View File

@@ -20,7 +20,7 @@ use test_dir::TestDir;
#[cfg(not(feature = "rust_tests"))]
pub mod msg {
pub const FILE_NOT_FOUND: &str = "Couldn't stat file";
pub const FILE_NOT_FOUND: &str = "No such file or directory";
pub const MISSING_INPUT_ARG: &str = "No input file provided";
pub const MISSING_OUTPUT_ARG: &str = "No output file provided";
}

View File

@@ -48,13 +48,13 @@ fn dont_repair_xml() -> Result<()> {
}
#[test]
fn missing_input_file() -> Result<()> {
fn input_file_not_found() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let stderr = run_fail(thin_repair!("-i", "no-such-file", "-o", &md))?;
assert!(superblock_all_zeroes(&md)?);
// TODO: replace with msg::FILE_NOT_FOUND once the rust version is ready
assert!(stderr.contains("Couldn't stat file"));
assert!(stderr.contains("No such file or directory"));
Ok(())
}
@@ -69,7 +69,7 @@ fn garbage_input_file() -> Result<()> {
}
#[test]
fn missing_output_file() -> Result<()> {
fn missing_output_arg() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let stderr = run_fail(thin_repair!("-i", &md))?;

View File

@@ -40,7 +40,7 @@ fn accepts_help() -> Result<()> {
}
#[test]
fn no_input_file() -> Result<()> {
fn missing_input_arg() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let stderr = run_fail(thin_restore!("-o", &md))?;
@@ -49,7 +49,7 @@ fn no_input_file() -> Result<()> {
}
#[test]
fn missing_input_file() -> Result<()> {
fn input_file_not_found() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let stderr = run_fail(thin_restore!("-i", "no-such-file", "-o", &md))?;
@@ -69,7 +69,7 @@ fn garbage_input_file() -> Result<()> {
}
#[test]
fn no_output_file() -> Result<()> {
fn missing_output_arg() -> Result<()> {
let mut td = TestDir::new()?;
let xml = mk_valid_xml(&mut td)?;
let stderr = run_fail(thin_restore!("-i", &xml))?;