@@ -21,7 +21,7 @@ use std::convert::TryFrom;
2121use spdx:: { Expression , ParseMode } ;
2222use thiserror:: Error ;
2323
24- use crate :: validation:: { FailureReason , Validate , ValidationResult } ;
24+ use crate :: validation:: { Validate , ValidationResult } ;
2525
2626/// An identifier for a single, specific license
2727///
@@ -84,15 +84,10 @@ impl Validate for SpdxIdentifier {
8484 fn validate_with_context (
8585 & self ,
8686 context : crate :: validation:: ValidationContext ,
87- ) -> Result < ValidationResult , crate :: validation :: ValidationError > {
87+ ) -> ValidationResult {
8888 match Self :: try_from ( self . 0 . clone ( ) ) {
89- Ok ( _) => Ok ( ValidationResult :: Passed ) ,
90- Err ( _) => Ok ( ValidationResult :: Failed {
91- reasons : vec ! [ FailureReason {
92- message: "SPDX identifier is not valid" . to_string( ) ,
93- context,
94- } ] ,
95- } ) ,
89+ Ok ( _) => ValidationResult :: Passed ,
90+ Err ( _) => ValidationResult :: failure ( "SPDX identifier is not valid" , context) ,
9691 }
9792 }
9893}
@@ -184,15 +179,10 @@ impl Validate for SpdxExpression {
184179 fn validate_with_context (
185180 & self ,
186181 context : crate :: validation:: ValidationContext ,
187- ) -> Result < crate :: validation :: ValidationResult , crate :: validation :: ValidationError > {
182+ ) -> ValidationResult {
188183 match SpdxExpression :: try_from ( self . 0 . clone ( ) ) {
189- Ok ( _) => Ok ( ValidationResult :: Passed ) ,
190- Err ( _) => Ok ( ValidationResult :: Failed {
191- reasons : vec ! [ FailureReason {
192- message: "SPDX expression is not valid" . to_string( ) ,
193- context,
194- } ] ,
195- } ) ,
184+ Ok ( _) => ValidationResult :: Passed ,
185+ Err ( _) => ValidationResult :: failure ( "SPDX expression is not valid" , context) ,
196186 }
197187 }
198188}
@@ -208,7 +198,7 @@ pub enum SpdxExpressionError {
208198
209199#[ cfg( test) ]
210200mod test {
211- use crate :: validation:: { FailureReason , ValidationContext , ValidationResult } ;
201+ use crate :: validation:: { ValidationContext , ValidationResult } ;
212202
213203 use super :: * ;
214204 use pretty_assertions:: assert_eq;
@@ -257,27 +247,18 @@ mod test {
257247
258248 #[ test]
259249 fn valid_spdx_identifiers_should_pass_validation ( ) {
260- let validation_result = SpdxIdentifier ( "MIT" . to_string ( ) )
261- . validate_with_context ( ValidationContext :: default ( ) )
262- . expect ( "Error while validating" ) ;
250+ let validation_result = SpdxIdentifier ( "MIT" . to_string ( ) ) . validate ( ) ;
263251
264252 assert_eq ! ( validation_result, ValidationResult :: Passed ) ;
265253 }
266254
267255 #[ test]
268256 fn invalid_spdx_identifiers_should_fail_validation ( ) {
269- let validation_result = SpdxIdentifier ( "MIT OR Apache-2.0" . to_string ( ) )
270- . validate_with_context ( ValidationContext :: default ( ) )
271- . expect ( "Error while validating" ) ;
257+ let validation_result = SpdxIdentifier ( "MIT OR Apache-2.0" . to_string ( ) ) . validate ( ) ;
272258
273259 assert_eq ! (
274260 validation_result,
275- ValidationResult :: Failed {
276- reasons: vec![ FailureReason {
277- message: "SPDX identifier is not valid" . to_string( ) ,
278- context: ValidationContext :: default ( )
279- } ]
280- }
261+ ValidationResult :: failure( "SPDX identifier is not valid" , ValidationContext :: default ( ) ) ,
281262 ) ;
282263 }
283264
@@ -307,27 +288,18 @@ mod test {
307288
308289 #[ test]
309290 fn valid_spdx_expressions_should_pass_validation ( ) {
310- let validation_result = SpdxExpression ( "MIT OR Apache-2.0" . to_string ( ) )
311- . validate_with_context ( ValidationContext :: default ( ) )
312- . expect ( "Error while validating" ) ;
291+ let validation_result = SpdxExpression ( "MIT OR Apache-2.0" . to_string ( ) ) . validate ( ) ;
313292
314293 assert_eq ! ( validation_result, ValidationResult :: Passed ) ;
315294 }
316295
317296 #[ test]
318297 fn invalid_spdx_expressions_should_fail_validation ( ) {
319- let validation_result = SpdxExpression ( "not a real license" . to_string ( ) )
320- . validate_with_context ( ValidationContext :: default ( ) )
321- . expect ( "Error while validating" ) ;
298+ let validation_result = SpdxExpression ( "not a real license" . to_string ( ) ) . validate ( ) ;
322299
323300 assert_eq ! (
324301 validation_result,
325- ValidationResult :: Failed {
326- reasons: vec![ FailureReason {
327- message: "SPDX expression is not valid" . to_string( ) ,
328- context: ValidationContext :: default ( )
329- } ]
330- }
302+ ValidationResult :: failure( "SPDX expression is not valid" , ValidationContext :: default ( ) )
331303 ) ;
332304 }
333305}
0 commit comments