diff --git a/tests/arrays.rs b/tests/arrays.rs index 8820a54a..23d0f98f 100644 --- a/tests/arrays.rs +++ b/tests/arrays.rs @@ -210,34 +210,25 @@ fn test_array_index_types() -> Result<(), Box> { engine.compile("[1, 2, 3][0]['x']")?; assert!(matches!( - engine - .compile("[1, 2, 3]['x']") - .expect_err("should error") - .err_type(), + engine.compile("[1, 2, 3]['x']").unwrap_err().err_type(), ParseErrorType::MalformedIndexExpr(..) )); #[cfg(not(feature = "no_float"))] assert!(matches!( - engine - .compile("[1, 2, 3][123.456]") - .expect_err("should error") - .err_type(), + engine.compile("[1, 2, 3][123.456]").unwrap_err().err_type(), ParseErrorType::MalformedIndexExpr(..) )); assert!(matches!( - engine - .compile("[1, 2, 3][()]") - .expect_err("should error") - .err_type(), + engine.compile("[1, 2, 3][()]").unwrap_err().err_type(), ParseErrorType::MalformedIndexExpr(..) )); assert!(matches!( engine .compile(r#"[1, 2, 3]["hello"]"#) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedIndexExpr(..) )); @@ -245,7 +236,7 @@ fn test_array_index_types() -> Result<(), Box> { assert!(matches!( engine .compile("[1, 2, 3][true && false]") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedIndexExpr(..) )); diff --git a/tests/assignments.rs b/tests/assignments.rs index e2a90d4f..08846845 100644 --- a/tests/assignments.rs +++ b/tests/assignments.rs @@ -21,71 +21,44 @@ fn test_assignments_bad_lhs() -> Result<(), Box> { let engine = Engine::new(); assert_eq!( - *engine - .compile("(x+y) = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("(x+y) = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToInvalidLHS(String::new()) ); assert_eq!( - *engine - .compile("foo(x) = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("foo(x) = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToInvalidLHS(String::new()) ); assert_eq!( - *engine - .compile("true = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("true = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToConstant(String::new()) ); assert_eq!( - *engine - .compile("123 = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("123 = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToConstant(String::new()) ); #[cfg(not(feature = "no_object"))] { assert_eq!( - *engine - .compile("x.foo() = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("x.foo() = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToInvalidLHS(String::new()) ); assert_eq!( - *engine - .compile("x.foo().x.y = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("x.foo().x.y = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToInvalidLHS(String::new()) ); assert_eq!( - *engine - .compile("x.y.z.foo() = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("x.y.z.foo() = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToInvalidLHS(String::new()) ); #[cfg(not(feature = "no_index"))] assert_eq!( - *engine - .compile("x.foo()[0] = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("x.foo()[0] = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToInvalidLHS(String::new()) ); #[cfg(not(feature = "no_index"))] assert_eq!( - *engine - .compile("x[y].z.foo() = 42;") - .expect_err("should error") - .err_type(), + *engine.compile("x[y].z.foo() = 42;").unwrap_err().err_type(), ParseErrorType::AssignmentToInvalidLHS(String::new()) ); } diff --git a/tests/closures.rs b/tests/closures.rs index 0e934c30..a0511456 100644 --- a/tests/closures.rs +++ b/tests/closures.rs @@ -47,10 +47,7 @@ fn test_closures() -> Result<(), Box> { scope.push("x", 42 as INT); assert!(matches!( - engine - .compile_expression("|x| {}") - .expect_err("should error") - .err_type(), + engine.compile_expression("|x| {}").unwrap_err().err_type(), ParseErrorType::BadInput(..) )); @@ -292,7 +289,7 @@ fn test_closures_data_race() -> Result<(), Box> { a " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataRace(..) )); diff --git a/tests/constants.rs b/tests/constants.rs index bc49e8ee..943b518e 100644 --- a/tests/constants.rs +++ b/tests/constants.rs @@ -86,7 +86,7 @@ fn test_constant_mut() -> Result<(), Box> { MY_NUMBER.value = 42; " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorNonPureMethodCallOnConstant(..) )); @@ -119,7 +119,7 @@ fn test_constant_mut() -> Result<(), Box> { assert!(matches!( *engine .run_with_scope(&mut scope, "MY_NUMBER.value = 42;") - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorNonPureMethodCallOnConstant(..) )); diff --git a/tests/custom_syntax.rs b/tests/custom_syntax.rs index ec71e904..85072baf 100644 --- a/tests/custom_syntax.rs +++ b/tests/custom_syntax.rs @@ -13,11 +13,11 @@ fn test_custom_syntax() -> Result<(), Box> { // Disable 'while' and make sure it still works with custom syntax engine.disable_symbol("while"); assert!(matches!( - engine.compile("while false {}").expect_err("should error").err_type(), + engine.compile("while false {}").unwrap_err().err_type(), ParseErrorType::Reserved(err) if err == "while" )); assert!(matches!( - engine.compile("let while = 0").expect_err("should error").err_type(), + engine.compile("let while = 0").unwrap_err().err_type(), ParseErrorType::Reserved(err) if err == "while" )); @@ -127,7 +127,7 @@ fn test_custom_syntax() -> Result<(), Box> { assert!(matches!( *engine .run("let foo = (exec [x<<15] -> { x += 2 } while x < 42) * 10;") - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorRuntime(..) )); @@ -195,7 +195,7 @@ fn test_custom_syntax() -> Result<(), Box> { assert_eq!( *engine .register_custom_syntax(["!"], false, |_, _| Ok(Dynamic::UNIT)) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::BadInput(LexError::ImproperSymbol( "!".to_string(), @@ -364,10 +364,7 @@ fn test_custom_syntax_raw() -> Result<(), Box> { ); assert_eq!(engine.eval::("(hello kitty) + foo")?, 1041); assert_eq!( - *engine - .compile("hello hey") - .expect_err("should error") - .err_type(), + *engine.compile("hello hey").unwrap_err().err_type(), ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string(), String::new())) ); diff --git a/tests/data_size.rs b/tests/data_size.rs index 50f35f50..feb44199 100644 --- a/tests/data_size.rs +++ b/tests/data_size.rs @@ -15,7 +15,7 @@ fn test_max_string_size() -> Result<(), Box> { assert_eq!( *engine .compile(r#"let x = "hello, world!";"#) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::LiteralTooLarge("Length of string".to_string(), 10) ); @@ -23,7 +23,7 @@ fn test_max_string_size() -> Result<(), Box> { assert_eq!( *engine .compile(r#"let x = "朝に紅顔、暮に白骨";"#) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::LiteralTooLarge("Length of string".to_string(), 10) ); @@ -37,7 +37,7 @@ fn test_max_string_size() -> Result<(), Box> { x + y "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -51,7 +51,7 @@ fn test_max_string_size() -> Result<(), Box> { x "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -83,7 +83,7 @@ fn test_max_array_size() -> Result<(), Box> { assert_eq!( *engine .compile("let x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::LiteralTooLarge("Size of array literal".to_string(), 10) ); @@ -97,7 +97,7 @@ fn test_max_array_size() -> Result<(), Box> { x + y " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -130,7 +130,7 @@ fn test_max_array_size() -> Result<(), Box> { } " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -142,7 +142,7 @@ fn test_max_array_size() -> Result<(), Box> { loop { x[0] = x; } " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -168,7 +168,7 @@ fn test_max_array_size() -> Result<(), Box> { x " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -190,7 +190,7 @@ fn test_max_array_size() -> Result<(), Box> { [x, x, x, x] " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -203,7 +203,7 @@ fn test_max_array_size() -> Result<(), Box> { [x, x, x, x] " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -217,7 +217,7 @@ fn test_max_array_size() -> Result<(), Box> { [z, z, z] " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -265,7 +265,7 @@ fn test_max_map_size() -> Result<(), Box> { .compile( "let x = #{a:1,b:2,c:3,d:4,e:5,f:6,g:7,h:8,i:9,j:10,k:11,l:12,m:13,n:14,o:15};" ) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::LiteralTooLarge( "Number of properties in object map literal".to_string(), @@ -281,7 +281,7 @@ fn test_max_map_size() -> Result<(), Box> { loop { x.a = x; } " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -294,7 +294,7 @@ fn test_max_map_size() -> Result<(), Box> { x + y " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -306,7 +306,7 @@ fn test_max_map_size() -> Result<(), Box> { #{u:x, v:x, w:x, z:x} " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); @@ -319,7 +319,7 @@ fn test_max_map_size() -> Result<(), Box> { #{u:x, v:x, w:x, z:x} " ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorDataTooLarge(..) )); diff --git a/tests/eval.rs b/tests/eval.rs index a7b834f9..bd55e72f 100644 --- a/tests/eval.rs +++ b/tests/eval.rs @@ -169,7 +169,7 @@ fn test_eval_disabled() -> Result<(), Box> { assert!(matches!( engine .compile(r#"eval("40 + 2")"#) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::BadInput(LexError::ImproperSymbol(err, ..)) if err == "eval" )); diff --git a/tests/fn_ptr.rs b/tests/fn_ptr.rs index 1e2baa84..1d587e2b 100644 --- a/tests/fn_ptr.rs +++ b/tests/fn_ptr.rs @@ -72,7 +72,7 @@ fn test_fn_ptr() -> Result<(), Box> { x "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorInFunctionCall(fn_name, _, err, ..) if fn_name == "foo" && matches!(*err, EvalAltResult::ErrorUnboundThis(..)) )); diff --git a/tests/functions.rs b/tests/functions.rs index a079bbdd..ef873abd 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -93,7 +93,7 @@ fn test_functions_global_module() -> Result<(), Box> { const ANSWER = 42; foo() } - ").expect_err("should error"), + ").unwrap_err(), EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::ANSWER") )); @@ -112,7 +112,7 @@ fn test_functions_global_module() -> Result<(), Box> { const LOCAL_VALUE = 42; global::LOCAL_VALUE }); - ").expect_err("should error"), + ").unwrap_err(), EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::LOCAL_VALUE") )); diff --git a/tests/internal_fn.rs b/tests/internal_fn.rs index ddd8ff76..f440e479 100644 --- a/tests/internal_fn.rs +++ b/tests/internal_fn.rs @@ -109,7 +109,7 @@ fn test_internal_fn_overloading() -> Result<(), Box> { fn abc(x) { x - 42 } " ) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::FnDuplicatedDefinition("abc".to_string(), 1) ); @@ -125,7 +125,7 @@ fn test_internal_fn_params() -> Result<(), Box> { assert_eq!( *engine .compile("fn hello(x, x) { x }") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::FnDuplicatedParam("hello".to_string(), "x".to_string()) ); @@ -169,7 +169,7 @@ fn test_function_pointers() -> Result<(), Box> { #[cfg(not(feature = "no_object"))] assert!(matches!( - *engine.eval::(r#"let f = Fn("abc"); f.call(0)"#).expect_err("should error"), + *engine.eval::(r#"let f = Fn("abc"); f.call(0)"#).unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("abc (") )); @@ -247,7 +247,7 @@ fn test_internal_fn_bang() -> Result<(), Box> { y.foo!(); " ) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedCapture(..) )); diff --git a/tests/looping.rs b/tests/looping.rs index e011eb6b..191b7e85 100644 --- a/tests/looping.rs +++ b/tests/looping.rs @@ -27,10 +27,7 @@ fn test_loop() -> Result<(), Box> { ); assert_eq!( - *engine - .compile("let x = 0; break;") - .expect_err("should error") - .err_type(), + *engine.compile("let x = 0; break;").unwrap_err().err_type(), ParseErrorType::LoopBreak ); @@ -38,7 +35,7 @@ fn test_loop() -> Result<(), Box> { assert_eq!( *engine .compile("loop { let f = || { break; } }") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::LoopBreak ); @@ -46,7 +43,7 @@ fn test_loop() -> Result<(), Box> { assert_eq!( *engine .compile("let x = 0; if x > 0 { continue; }") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::LoopBreak ); diff --git a/tests/maps.rs b/tests/maps.rs index 2bfab623..d72b6356 100644 --- a/tests/maps.rs +++ b/tests/maps.rs @@ -52,7 +52,7 @@ b`: 1}; y["a\nb"] assert!(matches!( *engine .eval::("let y = #{`a${1}`: 1}; y.a1") - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorParsing(ParseErrorType::PropertyExpected, ..) )); @@ -116,7 +116,7 @@ fn test_map_prop() -> Result<(), Box> { engine.set_fail_on_invalid_map_property(true); assert!( - matches!(*engine.eval::<()>("let x = #{a: 42}; x.b").expect_err("should error"), + matches!(*engine.eval::<()>("let x = #{a: 42}; x.b").unwrap_err(), EvalAltResult::ErrorPropertyNotFound(prop, _) if prop == "b" ) ); @@ -134,7 +134,7 @@ fn test_map_index_types() -> Result<(), Box> { assert!(matches!( engine .compile("#{a:1, b:2, c:3}['x']") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedIndexExpr(..) )); @@ -142,7 +142,7 @@ fn test_map_index_types() -> Result<(), Box> { assert!(matches!( engine .compile("#{a:1, b:2, c:3}[1]") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedIndexExpr(..) )); @@ -151,7 +151,7 @@ fn test_map_index_types() -> Result<(), Box> { assert!(matches!( engine .compile("#{a:1, b:2, c:3}[123.456]") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedIndexExpr(..) )); @@ -159,7 +159,7 @@ fn test_map_index_types() -> Result<(), Box> { assert!(matches!( engine .compile("#{a:1, b:2, c:3}[()]") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedIndexExpr(..) )); @@ -167,7 +167,7 @@ fn test_map_index_types() -> Result<(), Box> { assert!(matches!( engine .compile("#{a:1, b:2, c:3}[true && false]") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::MalformedIndexExpr(..) )); @@ -272,38 +272,32 @@ fn test_map_json() -> Result<(), Box> { engine.parse_json(json, true)?; assert!(matches!( - *engine.parse_json("123", true).expect_err("should error"), + *engine.parse_json("123", true).unwrap_err(), EvalAltResult::ErrorMismatchOutputType(..) )); assert!(matches!( - *engine.parse_json("{a:42}", true).expect_err("should error"), + *engine.parse_json("{a:42}", true).unwrap_err(), EvalAltResult::ErrorParsing(..) )); assert!(matches!( - *engine - .parse_json("#{a:123}", true) - .expect_err("should error"), + *engine.parse_json("#{a:123}", true).unwrap_err(), EvalAltResult::ErrorParsing(..) )); assert!(matches!( - *engine.parse_json("{a:()}", true).expect_err("should error"), + *engine.parse_json("{a:()}", true).unwrap_err(), EvalAltResult::ErrorParsing(..) )); assert!(matches!( - *engine - .parse_json("#{a:123+456}", true) - .expect_err("should error"), + *engine.parse_json("#{a:123+456}", true).unwrap_err(), EvalAltResult::ErrorParsing(..) )); assert!(matches!( - *engine - .parse_json("{a:`hello${world}`}", true) - .expect_err("should error"), + *engine.parse_json("{a:`hello${world}`}", true).unwrap_err(), EvalAltResult::ErrorParsing(..) )); diff --git a/tests/method_call.rs b/tests/method_call.rs index 577447e7..75c19792 100644 --- a/tests/method_call.rs +++ b/tests/method_call.rs @@ -127,7 +127,7 @@ fn test_method_call_typed() -> Result<(), Box> { foo(1000); "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("foo") )); @@ -142,7 +142,7 @@ fn test_method_call_typed() -> Result<(), Box> { x.foo(1000); "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("foo") )); diff --git a/tests/mismatched_op.rs b/tests/mismatched_op.rs index 85d31857..dd094a45 100644 --- a/tests/mismatched_op.rs +++ b/tests/mismatched_op.rs @@ -36,21 +36,21 @@ fn test_mismatched_op_custom_type() -> Result<(), Box> { let x = new_ts(); let y = new_ts(); x == y - ").expect_err("should error"), + ").unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f == "== (TestStruct, TestStruct)")); assert!( - matches!(*engine.eval::("new_ts() == 42").expect_err("should error"), + matches!(*engine.eval::("new_ts() == 42").unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (TestStruct, ")) ); assert!(matches!( - *engine.eval::("60 + new_ts()").expect_err("should error"), + *engine.eval::("60 + new_ts()").unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f == format!("+ ({}, TestStruct)", std::any::type_name::()) )); assert!(matches!( - *engine.eval::("42").expect_err("should error"), + *engine.eval::("42").unwrap_err(), EvalAltResult::ErrorMismatchOutputType(need, actual, ..) if need == "TestStruct" && actual == std::any::type_name::() )); diff --git a/tests/modules.rs b/tests/modules.rs index 447917a3..f296d78b 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -227,7 +227,7 @@ fn test_module_resolver() -> Result<(), Box> { sum "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorTooManyModules(..) )); @@ -250,7 +250,7 @@ fn test_module_resolver() -> Result<(), Box> { sum "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorInFunctionCall(fn_name, ..) if fn_name == "foo" )); @@ -403,7 +403,7 @@ fn test_module_from_ast() -> Result<(), Box> { assert!(matches!( *engine .run(r#"import "testing" as ttt; ttt::hidden()"#) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorFunctionNotFound(fn_name, ..) if fn_name == "ttt::hidden ()" )); @@ -415,13 +415,13 @@ fn test_module_export() -> Result<(), Box> { let engine = Engine::new(); assert!(matches!( - engine.compile("let x = 10; { export x; }").expect_err("should error"), + engine.compile("let x = 10; { export x; }").unwrap_err(), ParseError(x, ..) if *x == ParseErrorType::WrongExport )); #[cfg(not(feature = "no_function"))] assert!(matches!( - engine.compile("fn abc(x) { export x; }").expect_err("should error"), + engine.compile("fn abc(x) { export x; }").unwrap_err(), ParseError(x, ..) if *x == ParseErrorType::WrongExport )); diff --git a/tests/operations.rs b/tests/operations.rs index c4eb37ab..b179e3e5 100644 --- a/tests/operations.rs +++ b/tests/operations.rs @@ -18,7 +18,7 @@ fn test_max_operations() -> Result<(), Box> { engine.run("let x = 0; while x < 20 { x += 1; }")?; assert!(matches!( - *engine.run("for x in 0..500 {}").expect_err("should error"), + *engine.run("for x in 0..500 {}").unwrap_err(), EvalAltResult::ErrorTooManyOperations(..) )); @@ -41,9 +41,7 @@ fn test_max_operations_literal() -> Result<(), Box> { #[cfg(not(feature = "no_index"))] assert!(matches!( - *engine - .run("[1, 2, 3, 4, 5, 6, 7, 8, 9]") - .expect_err("should error"), + *engine.run("[1, 2, 3, 4, 5, 6, 7, 8, 9]").unwrap_err(), EvalAltResult::ErrorTooManyOperations(..) )); @@ -54,7 +52,7 @@ fn test_max_operations_literal() -> Result<(), Box> { assert!(matches!( *engine .run("#{a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9}") - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorTooManyOperations(..) )); @@ -110,7 +108,7 @@ fn test_max_operations_functions() -> Result<(), Box> { } "#, ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorTooManyOperations(..) )); @@ -137,7 +135,7 @@ fn test_max_operations_eval() -> Result<(), Box> { eval(script); "# ) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(..)) )); @@ -162,7 +160,7 @@ fn test_max_operations_progress() -> Result<(), Box> { assert!(matches!( *engine .run("for x in 0..500 {}") - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorTerminated(x, ..) if x.as_int()? == 42 )); diff --git a/tests/ops.rs b/tests/ops.rs index ce6c5611..7c8e0077 100644 --- a/tests/ops.rs +++ b/tests/ops.rs @@ -26,17 +26,17 @@ fn test_ops_other_number_types() -> Result<(), Box> { scope.push("x", 42_u16); assert!(matches!( - *engine.eval_with_scope::(&mut scope, "x == 42").expect_err("should error"), + *engine.eval_with_scope::(&mut scope, "x == 42").unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (u16,") )); #[cfg(not(feature = "no_float"))] assert!(matches!( - *engine.eval_with_scope::(&mut scope, "x == 42.0").expect_err("should error"), + *engine.eval_with_scope::(&mut scope, "x == 42.0").unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (u16,") )); assert!( - matches!(*engine.eval_with_scope::(&mut scope, r#"x == "hello""#).expect_err("should error"), + matches!(*engine.eval_with_scope::(&mut scope, r#"x == "hello""#).unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (u16,") ) ); diff --git a/tests/plugins.rs b/tests/plugins.rs index ab752bc3..7b1214cb 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -118,7 +118,7 @@ fn test_plugins_package() -> Result<(), Box> { engine.run("const A = [1, 2, 3]; A.no_effect = 42;")?; assert!( - matches!(*engine.run("const A = [1, 2, 3]; A.test(42);").expect_err("should error"), + matches!(*engine.run("const A = [1, 2, 3]; A.test(42);").unwrap_err(), EvalAltResult::ErrorNonPureMethodCallOnConstant(x, ..) if x == "test") ) } diff --git a/tests/stack.rs b/tests/stack.rs index a63a5dbd..49e28224 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -28,7 +28,7 @@ fn test_stack_overflow_fn_calls() -> Result<(), Box> { ", max + 1 )) - .expect_err("should error"), + .unwrap_err(), EvalAltResult::ErrorStackOverflow(..) )); @@ -44,7 +44,7 @@ fn test_stack_overflow_parsing() -> Result<(), Box> { " let a = (1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+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(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+1)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) " - ).expect_err("should error").0, + ).unwrap_err().0, ParseErrorType::ExprTooDeep ); @@ -71,7 +71,7 @@ fn test_stack_overflow_parsing() -> Result<(), Box> { 1 + 2 " ) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::ExprTooDeep ); @@ -113,7 +113,7 @@ fn test_stack_overflow_parsing() -> Result<(), Box> { 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 " ) - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::ExprTooDeep ); diff --git a/tests/string.rs b/tests/string.rs index 37988600..6b150b96 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -116,7 +116,7 @@ fn test_string_mut() -> Result<(), Box> { assert_eq!(engine.eval::(r#"foo("hello")"#)?, 5); assert_eq!(engine.eval::(r#"bar("hello")"#)?, 5); assert!( - matches!(*engine.eval::(r#"baz("hello")"#).expect_err("should error"), + matches!(*engine.eval::(r#"baz("hello")"#).unwrap_err(), EvalAltResult::ErrorFunctionNotFound(f, ..) if f == "baz (&str | ImmutableString | String)" ) ); diff --git a/tests/switch.rs b/tests/switch.rs index f37dacc0..67569b5d 100644 --- a/tests/switch.rs +++ b/tests/switch.rs @@ -110,7 +110,7 @@ fn test_switch_errors() -> Result<(), Box> { assert!(matches!( engine .compile("switch x { _ => 123, 1 => 42 }") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::WrongSwitchDefaultCase )); @@ -174,7 +174,7 @@ fn test_switch_condition() -> Result<(), Box> { assert!(matches!( engine .compile("switch x { 1 => 123, _ if true => 42 }") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::WrongSwitchCaseCondition )); @@ -269,14 +269,14 @@ fn test_switch_ranges() -> Result<(), Box> { assert!(matches!( engine.compile( "switch x { 10..20 => (), 20..=42 => 'a', 25..45 => 'z', 42 => 'x', 30..100 => true }" - ).expect_err("should error").err_type(), + ).unwrap_err().err_type(), ParseErrorType::WrongSwitchIntegerCase )); #[cfg(not(feature = "no_float"))] assert!(matches!( engine.compile( "switch x { 10..20 => (), 20..=42 => 'a', 25..45 => 'z', 42.0 => 'x', 30..100 => true }" - ).expect_err("should error").err_type(), + ).unwrap_err().err_type(), ParseErrorType::WrongSwitchIntegerCase )); assert_eq!( diff --git a/tests/tokens.rs b/tests/tokens.rs index f6fac1aa..9a7b7d89 100644 --- a/tests/tokens.rs +++ b/tests/tokens.rs @@ -9,7 +9,7 @@ fn test_tokens_disabled() { assert!(matches!( engine .compile("let x = if true { 42 } else { 0 };") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::Reserved(err) if err == "if" )); @@ -19,13 +19,13 @@ fn test_tokens_disabled() { assert_eq!( *engine .compile("let x = 40 + 2; x += 1;") - .expect_err("should error") + .unwrap_err() .err_type(), ParseErrorType::UnknownOperator("+=".to_string()) ); assert!(matches!( - engine.compile("let x = += 0;").expect_err("should error").err_type(), + engine.compile("let x = += 0;").unwrap_err().err_type(), ParseErrorType::Reserved(err) if err == "+=" )); } diff --git a/tests/unit.rs b/tests/unit.rs index d2abd3c2..04c078bd 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -17,6 +17,6 @@ fn test_unit_eq() -> Result<(), Box> { #[test] fn test_unit_with_spaces() -> Result<(), Box> { let engine = Engine::new(); - let _ = engine.run("let x = ( ); x").expect_err("should error"); + let _ = engine.run("let x = ( ); x").unwrap_err(); Ok(()) } diff --git a/tests/var_scope.rs b/tests/var_scope.rs index 32db7db7..5a3120ba 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -209,7 +209,7 @@ fn test_var_resolver() -> Result<(), Box> { assert_eq!(engine.eval_with_scope::(&mut scope, "chameleon")?, 1); assert!( - matches!(*engine.eval_with_scope::(&mut scope, "DO_NOT_USE").expect_err("should error"), + matches!(*engine.eval_with_scope::(&mut scope, "DO_NOT_USE").unwrap_err(), EvalAltResult::ErrorVariableNotFound(n, ..) if n == "DO_NOT_USE") ); @@ -235,7 +235,7 @@ fn test_var_def_filter() -> Result<(), Box> { ); assert!(matches!( - engine.compile("let x = 42;").expect_err("should error").err_type(), + engine.compile("let x = 42;").unwrap_err().err_type(), ParseErrorType::ForbiddenVariable(s) if s == "x" )); assert!(matches!(