2020-04-08 04:19:03 +02:00
|
|
|
#![cfg(not(feature = "no_function"))]
|
2020-04-07 17:13:47 +02:00
|
|
|
use rhai::{Engine, EvalAltResult};
|
|
|
|
|
|
|
|
#[test]
|
2020-04-21 17:25:12 +02:00
|
|
|
fn test_stack_overflow() -> Result<(), Box<EvalAltResult>> {
|
2020-04-07 17:13:47 +02:00
|
|
|
let engine = Engine::new();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
engine.eval::<i64>(
|
|
|
|
r"
|
|
|
|
fn foo(n) { if n == 0 { 0 } else { n + foo(n-1) } }
|
2020-04-17 13:00:52 +02:00
|
|
|
foo(25)
|
2020-04-07 17:13:47 +02:00
|
|
|
",
|
|
|
|
)?,
|
2020-04-17 13:00:52 +02:00
|
|
|
325
|
2020-04-07 17:13:47 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
match engine.eval::<()>(
|
|
|
|
r"
|
|
|
|
fn foo(n) { if n == 0 { 0 } else { n + foo(n-1) } }
|
|
|
|
foo(1000)
|
|
|
|
",
|
|
|
|
) {
|
|
|
|
Ok(_) => panic!("should be stack overflow"),
|
2020-04-21 17:25:12 +02:00
|
|
|
Err(err) => match *err {
|
2020-05-13 15:58:38 +02:00
|
|
|
EvalAltResult::ErrorInFunctionCall(name, _, _)
|
|
|
|
if name.starts_with("foo > foo > foo") => {}
|
2020-04-21 17:25:12 +02:00
|
|
|
_ => panic!("should be stack overflow"),
|
|
|
|
},
|
2020-04-07 17:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|