diff --git a/CHANGES.md b/CHANGES.md index d49c9c053..58cd2401a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -59,6 +59,10 @@ - +- Remove `PartialEq` from `GdalError` + + - + - Prevent SIGGEGV when reading a string array on an MD Array that is not of type string. - diff --git a/src/errors.rs b/src/errors.rs index 95fec4631..abb84badd 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -5,8 +5,7 @@ use gdal_sys::{CPLErr, OGRErr, OGRFieldType, OGRwkbGeometryType}; pub type Result = std::result::Result; -#[allow(unknown_lints, clippy::derive_partial_eq_without_eq)] // only enforce `PartialEq` for `GdalError` -#[derive(Clone, PartialEq, Debug, Error)] +#[derive(Clone, Debug, Error)] pub enum GdalError { #[error("FfiNulError")] FfiNulError(#[from] std::ffi::NulError), diff --git a/src/raster/rasterize.rs b/src/raster/rasterize.rs index fed5b7836..baf3d2b8d 100644 --- a/src/raster/rasterize.rs +++ b/src/raster/rasterize.rs @@ -128,21 +128,21 @@ mod tests { fn test_rasterizeoptions_as_ptr() { let c_options = CslStringList::try_from(RasterizeOptions::default()).unwrap(); assert_eq!( - c_options.fetch_name_value("ALL_TOUCHED"), - Ok(Some("FALSE".to_string())) + c_options.fetch_name_value("ALL_TOUCHED").unwrap(), + Some("FALSE".to_string()) ); - assert_eq!(c_options.fetch_name_value("BURN_VALUE_FROM"), Ok(None)); + assert_eq!(c_options.fetch_name_value("BURN_VALUE_FROM").unwrap(), None); assert_eq!( - c_options.fetch_name_value("MERGE_ALG"), - Ok(Some("REPLACE".to_string())) + c_options.fetch_name_value("MERGE_ALG").unwrap(), + Some("REPLACE".to_string()) ); assert_eq!( - c_options.fetch_name_value("CHUNKYSIZE"), - Ok(Some("0".to_string())) + c_options.fetch_name_value("CHUNKYSIZE").unwrap(), + Some("0".to_string()) ); assert_eq!( - c_options.fetch_name_value("OPTIM"), - Ok(Some("AUTO".to_string())) + c_options.fetch_name_value("OPTIM").unwrap(), + Some("AUTO".to_string()) ); } } diff --git a/src/vector/vector_tests/mod.rs b/src/vector/vector_tests/mod.rs index c58eaca0f..6aa901871 100644 --- a/src/vector/vector_tests/mod.rs +++ b/src/vector/vector_tests/mod.rs @@ -322,14 +322,14 @@ mod tests { assert_eq!(feature.field_as_integer64_by_name("railway").unwrap(), None); assert_eq!(feature.field_as_double_by_name("railway").unwrap(), None); - // test error - assert_eq!( - feature.field_as_string_by_name("not_a_field"), - Err(GdalError::InvalidFieldName { - field_name: "not_a_field".to_owned(), + assert!(matches!( + feature.field_as_string_by_name("not_a_field").unwrap_err(), + GdalError::InvalidFieldName { + field_name, method_name: "OGR_F_GetFieldIndex", - }) - ); + } + if field_name == "not_a_field" + )); }); } @@ -371,13 +371,13 @@ mod tests { assert_eq!(feature.field_as_double(railway_field).unwrap(), None); // test error - assert_eq!( - feature.field_as_string(23), - Err(GdalError::InvalidFieldIndex { + assert!(matches!( + feature.field_as_string(23).unwrap_err(), + GdalError::InvalidFieldIndex { index: 23, method_name: "field_as_string", - }) - ); + } + )); }); } @@ -415,20 +415,22 @@ mod tests { assert_eq!(feature.field_as_datetime(railway_field).unwrap(), None); // test error - assert_eq!( - feature.field_as_datetime_by_name("not_a_field"), - Err(GdalError::InvalidFieldName { - field_name: "not_a_field".to_owned(), + assert!(matches!( + feature + .field_as_datetime_by_name("not_a_field") + .unwrap_err(), + GdalError::InvalidFieldName { + field_name, method_name: "OGR_F_GetFieldIndex", - }) - ); - assert_eq!( - feature.field_as_datetime(23), - Err(GdalError::InvalidFieldIndex { + } if field_name == "not_a_field" + )); + assert!(matches!( + feature.field_as_datetime(23).unwrap_err(), + GdalError::InvalidFieldIndex { index: 23, method_name: "field_as_datetime", - }) - ); + } + )); }); } @@ -849,13 +851,13 @@ mod tests { assert_eq!(layer.features().count(), 21); // force error - assert_eq!( - layer.set_attribute_filter("foo = bar"), - Err(GdalError::OgrError { + assert!(matches!( + layer.set_attribute_filter("foo = bar").unwrap_err(), + GdalError::OgrError { err: gdal_sys::OGRErr::OGRERR_CORRUPT_DATA, method_name: "OGR_L_SetAttributeFilter", - }) - ); + } + )); }); } diff --git a/src/vsi.rs b/src/vsi.rs index b31038dcf..4f1db5963 100644 --- a/src/vsi.rs +++ b/src/vsi.rs @@ -211,12 +211,13 @@ mod tests { assert_eq!(bytes, vec![1_u8, 2, 3, 4]); // mem file must not be there anymore - assert_eq!( - unlink_mem_file(file_name), - Err(GdalError::UnlinkMemFile { - file_name: file_name.to_string() - }) - ); + assert!(matches!( + unlink_mem_file(file_name).unwrap_err(), + GdalError::UnlinkMemFile { + file_name + } + if file_name == file_name + )); } #[test] @@ -246,13 +247,14 @@ mod tests { #[test] fn no_mem_file() { - assert_eq!( - get_vsi_mem_file_bytes_owned("foobar"), - Err(GdalError::NullPointer { + assert!(matches!( + get_vsi_mem_file_bytes_owned("foobar").unwrap_err(), + GdalError::NullPointer { method_name: "VSIGetMemFileBuffer", - msg: "".to_string(), - }) - ); + msg, + } + if msg.is_empty() + )); } #[test] @@ -286,20 +288,22 @@ mod tests { fn unable_to_create() { let file_name = ""; - assert_eq!( - create_mem_file(file_name, vec![1_u8, 2, 3, 4]), - Err(GdalError::NullPointer { + assert!(matches!( + create_mem_file(file_name, vec![1_u8, 2, 3, 4]).unwrap_err(), + GdalError::NullPointer { method_name: "VSIGetMemFileBuffer", - msg: "".to_string(), - }) - ); - - assert_eq!( - unlink_mem_file(file_name), - Err(GdalError::UnlinkMemFile { - file_name: "".to_string() - }) - ); + msg, + } + if msg.is_empty() + )); + + assert!(matches!( + unlink_mem_file(file_name).unwrap_err(), + GdalError::UnlinkMemFile { + file_name, + } + if file_name.is_empty() + )); } #[test]