From 737cf2f67dcd5a51c3b194babcb5cc0050d047b3 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 31 Aug 2021 00:19:44 +0800 Subject: [PATCH] [tests] Refine trait names --- tests/cache_check.rs | 2 +- tests/common/input_arg.rs | 4 ++-- tests/common/output_option.rs | 6 +++--- tests/common/program.rs | 10 ++++++++-- tests/thin_check.rs | 2 +- tests/thin_metadata_pack.rs | 4 ---- tests/thin_metadata_unpack.rs | 4 ---- tests/thin_repair.rs | 10 ++++++---- tests/thin_restore.rs | 12 +++++++----- 9 files changed, 28 insertions(+), 26 deletions(-) diff --git a/tests/cache_check.rs b/tests/cache_check.rs index d729542..3aa724f 100644 --- a/tests/cache_check.rs +++ b/tests/cache_check.rs @@ -67,7 +67,7 @@ impl<'a> InputProgram<'a> for CacheCheck { } } -impl<'a> BinaryInputProgram<'_> for CacheCheck {} +impl<'a> MetadataReader<'a> for CacheCheck {} //------------------------------------------ diff --git a/tests/common/input_arg.rs b/tests/common/input_arg.rs index 3453f24..7ef7e69 100644 --- a/tests/common/input_arg.rs +++ b/tests/common/input_arg.rs @@ -182,7 +182,7 @@ macro_rules! test_unreadable_input_file { pub fn test_help_message_for_tiny_input_file<'a, P>() -> Result<()> where - P: BinaryInputProgram<'a>, + P: MetadataReader<'a>, { let mut td = TestDir::new()?; @@ -209,7 +209,7 @@ macro_rules! test_help_message_for_tiny_input_file { pub fn test_spot_xml_data<'a, P>() -> Result<()> where - P: BinaryInputProgram<'a>, + P: MetadataReader<'a>, { let mut td = TestDir::new()?; diff --git a/tests/common/output_option.rs b/tests/common/output_option.rs index e4e7695..57028f1 100644 --- a/tests/common/output_option.rs +++ b/tests/common/output_option.rs @@ -33,12 +33,12 @@ macro_rules! test_missing_output_option { pub fn test_output_file_not_found<'a, P>() -> Result<()> where - P: OutputProgram<'a>, + P: MetadataWriter<'a>, { let mut td = TestDir::new()?; let input = P::mk_valid_input(&mut td)?; let stderr = run_fail(P::path(), args!["-i", &input, "-o", "no-such-file"])?; - assert!(stderr.contains(

::file_not_found())); + assert!(stderr.contains(

::file_not_found())); Ok(()) } @@ -105,7 +105,7 @@ macro_rules! test_unwritable_output_file { // currently thin/cache_restore only pub fn test_tiny_output_file<'a, P>() -> Result<()> where - P: BinaryOutputProgram<'a>, + P: MetadataWriter<'a>, { let mut td = TestDir::new()?; let input = P::mk_valid_input(&mut td)?; diff --git a/tests/common/program.rs b/tests/common/program.rs index 51b63e9..0414b3d 100644 --- a/tests/common/program.rs +++ b/tests/common/program.rs @@ -30,14 +30,20 @@ pub trait InputProgram<'a>: Program<'a> { fn corrupted_input() -> &'a str; } -pub trait BinaryInputProgram<'a>: InputProgram<'a> {} +pub trait MetadataReader<'a>: InputProgram<'a> {} pub trait OutputProgram<'a>: InputProgram<'a> { // error messages fn missing_output_arg() -> &'a str; +} + +// programs that write existed files +pub trait MetadataWriter<'a>: OutputProgram<'a> { + // error messages fn file_not_found() -> &'a str; } -pub trait BinaryOutputProgram<'a>: OutputProgram<'a> {} +// programs that create output files (O_CREAT) +pub trait MetadataCreator<'a>: OutputProgram<'a> {} //------------------------------------------ diff --git a/tests/thin_check.rs b/tests/thin_check.rs index 1f1db46..608a5cb 100644 --- a/tests/thin_check.rs +++ b/tests/thin_check.rs @@ -70,7 +70,7 @@ impl<'a> InputProgram<'a> for ThinCheck { } } -impl<'a> BinaryInputProgram<'_> for ThinCheck {} +impl<'a> MetadataReader<'_> for ThinCheck {} //------------------------------------------ diff --git a/tests/thin_metadata_pack.rs b/tests/thin_metadata_pack.rs index dea1eff..b45c1bc 100644 --- a/tests/thin_metadata_pack.rs +++ b/tests/thin_metadata_pack.rs @@ -74,10 +74,6 @@ impl<'a> InputProgram<'a> for ThinMetadataPack { } impl<'a> OutputProgram<'a> for ThinMetadataPack { - fn file_not_found() -> &'a str { - rust_msg::FILE_NOT_FOUND - } - fn missing_output_arg() -> &'a str { rust_msg::MISSING_OUTPUT_ARG } diff --git a/tests/thin_metadata_unpack.rs b/tests/thin_metadata_unpack.rs index 1292965..fe77f22 100644 --- a/tests/thin_metadata_unpack.rs +++ b/tests/thin_metadata_unpack.rs @@ -76,10 +76,6 @@ impl<'a> InputProgram<'a> for ThinMetadataUnpack { } impl<'a> OutputProgram<'a> for ThinMetadataUnpack { - fn file_not_found() -> &'a str { - rust_msg::FILE_NOT_FOUND - } - fn missing_output_arg() -> &'a str { rust_msg::MISSING_OUTPUT_ARG } diff --git a/tests/thin_repair.rs b/tests/thin_repair.rs index 3a37846..eb3ac2d 100644 --- a/tests/thin_repair.rs +++ b/tests/thin_repair.rs @@ -69,15 +69,17 @@ impl<'a> InputProgram<'a> for ThinRepair { } impl<'a> OutputProgram<'a> for ThinRepair { - fn file_not_found() -> &'a str { - cpp_msg::FILE_NOT_FOUND - } - fn missing_output_arg() -> &'a str { cpp_msg::MISSING_OUTPUT_ARG } } +impl<'a> MetadataWriter<'a> for ThinRepair { + fn file_not_found() -> &'a str { + cpp_msg::FILE_NOT_FOUND + } +} + //----------------------------------------- test_accepts_help!(ThinRepair); diff --git a/tests/thin_restore.rs b/tests/thin_restore.rs index 65ef87a..b908566 100644 --- a/tests/thin_restore.rs +++ b/tests/thin_restore.rs @@ -70,16 +70,16 @@ impl<'a> InputProgram<'a> for ThinRestore { } impl<'a> OutputProgram<'a> for ThinRestore { - fn file_not_found() -> &'a str { - msg::FILE_NOT_FOUND - } - fn missing_output_arg() -> &'a str { msg::MISSING_OUTPUT_ARG } } -impl<'a> BinaryOutputProgram<'_> for ThinRestore {} +impl<'a> MetadataWriter<'a> for ThinRestore { + fn file_not_found() -> &'a str { + msg::FILE_NOT_FOUND + } +} //----------------------------------------- @@ -93,6 +93,8 @@ test_corrupted_input_data!(ThinRestore); test_missing_output_option!(ThinRestore); test_tiny_output_file!(ThinRestore); +test_unwritable_output_file!(ThinRestore); + //----------------------------------------- // TODO: share with cache_restore, era_restore