From f9d74fe3132b09cb8d3a81b49a571b3fa7e5409b Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 18 Aug 2022 21:36:00 +0800 Subject: [PATCH] Fix tests. --- src/packages/iter_basic.rs | 1 + tests/packages.rs | 33 +++++++++++++-------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index 688b2622..3ec29366 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -26,6 +26,7 @@ where x.checked_add(&y) } #[inline(always)] +#[allow(dead_code)] fn regular_add(x: T, y: T) -> Option where T: Debug + Copy + PartialOrd + std::ops::Add, diff --git a/tests/packages.rs b/tests/packages.rs index 06d64e52..49e9f27a 100644 --- a/tests/packages.rs +++ b/tests/packages.rs @@ -1,19 +1,20 @@ use rhai::packages::{Package, StandardPackage as SSS}; use rhai::{def_package, Engine, EvalAltResult, Module, Scope, INT}; -def_package! { - /// My custom package. - MyPackage(m) : SSS { - m.set_native_fn("hello", |x: INT| Ok(x + 1)); - m.set_native_fn("@", |x: INT, y: INT| Ok(x * x + y * y)); - } |> |engine| { - #[cfg(not(feature = "no_custom_syntax"))] - engine.register_custom_operator("@", 160).unwrap(); - } -} - +#[cfg(not(feature = "no_module"))] +#[cfg(not(feature = "no_custom_syntax"))] #[test] fn test_packages() -> Result<(), Box> { + def_package! { + /// My custom package. + MyPackage(m) : SSS { + m.set_native_fn("hello", |x: INT| Ok(x + 1)); + m.set_native_fn("@", |x: INT, y: INT| Ok(x * x + y * y)); + } |> |engine| { + engine.register_custom_operator("@", 160).unwrap(); + } + } + let pkg = MyPackage::new(); let make_call = |x: INT| -> Result> { @@ -32,19 +33,11 @@ fn test_packages() -> Result<(), Box> { // Evaluate script. - #[cfg(not(feature = "no_custom_syntax"))] - return engine.eval_with_scope::(&mut scope, "hello(x) @ foo::hello(x)"); - - #[cfg(feature = "no_custom_syntax")] - return engine.eval_with_scope::(&mut scope, "hello(x) + foo::hello(x)"); + engine.eval_with_scope::(&mut scope, "hello(x) @ foo::hello(x)") }; - #[cfg(not(feature = "no_custom_syntax"))] assert_eq!(make_call(42)?, 3698); - #[cfg(feature = "no_custom_syntax")] - assert_eq!(make_call(42)?, 86); - Ok(()) }