From 6053e48575cf3b421f3eb8a6af33c853a518d9c9 Mon Sep 17 00:00:00 2001 From: Ceri Storey Date: Sat, 27 Mar 2021 10:10:54 +0000 Subject: Replace a bunch of Err(…)? and format!("constant") calls. --- dhall/tests/spec.rs | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'dhall/tests') diff --git a/dhall/tests/spec.rs b/dhall/tests/spec.rs index a0fe583..b6eeac7 100644 --- a/dhall/tests/spec.rs +++ b/dhall/tests/spec.rs @@ -103,7 +103,9 @@ impl TestFile { TestFile::Source(_) => Parsed::parse_file(&self.path())?, TestFile::Binary(_) => Parsed::parse_binary_file(&self.path())?, TestFile::UI(_) => { - Err(TestError(format!("Can't parse a UI test file")))? + return Err( + TestError("Can't parse a UI test file".to_string()).into() + ) } }) } @@ -138,9 +140,12 @@ impl TestFile { let expr_data = binary::encode(&expr)?; file.write_all(&expr_data)?; } - TestFile::UI(_) => Err(TestError(format!( - "Can't write an expression to a UI file" - )))?, + TestFile::UI(_) => { + return Err(TestError( + "Can't write an expression to a UI file".to_string(), + ) + .into()) + } } Ok(()) } @@ -148,9 +153,12 @@ impl TestFile { fn write_ui(&self, x: impl Display) -> Result<()> { match self { TestFile::UI(_) => {} - _ => Err(TestError(format!( - "Can't write a ui string to a dhall file" - )))?, + _ => { + return Err(TestError( + "Can't write a ui string to a dhall file".to_string(), + ) + .into()) + } } let path = self.path(); create_dir_all(path.parent().unwrap())?; @@ -195,7 +203,11 @@ impl TestFile { pub fn compare_binary(&self, expr: Expr) -> Result<()> { match self { TestFile::Binary(_) => {} - _ => Err(TestError(format!("This is not a binary file")))?, + _ => { + return Err( + TestError("This is not a binary file".to_string()).into() + ) + } } if !self.path().is_file() { return self.write_expr(expr); @@ -593,17 +605,19 @@ fn run_test(test: &SpecTest) -> Result<()> { ParserFailure => { use std::io; let err = unwrap_err(expr.parse())?; - match err.downcast_ref::() { - Some(err) => match err.kind() { + if let Some(err) = err.downcast_ref::() { + match err.kind() { ErrorKind::Parse(_) => {} ErrorKind::IO(e) if e.kind() == io::ErrorKind::InvalidData => {} - e => Err(TestError(format!( - "Expected parse error, got: {:?}", - e - )))?, - }, - None => {} + e => { + return Err(TestError(format!( + "Expected parse error, got: {:?}", + e + )) + .into()) + } + } } expected.compare_ui(err)?; } -- cgit v1.2.3