Limit modules loading.
This commit is contained in:
@@ -72,13 +72,60 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r#"
|
||||
import "hello" as h;
|
||||
h::answer
|
||||
import "hello" as h1;
|
||||
import "hello" as h2;
|
||||
h2::answer
|
||||
"#
|
||||
)?,
|
||||
42
|
||||
);
|
||||
|
||||
engine.set_max_modules(5);
|
||||
|
||||
assert!(matches!(
|
||||
*engine
|
||||
.eval::<()>(
|
||||
r#"
|
||||
for x in range(0, 10) {
|
||||
import "hello" as h;
|
||||
}
|
||||
"#
|
||||
)
|
||||
.expect_err("should error"),
|
||||
EvalAltResult::ErrorTooManyModules(_)
|
||||
));
|
||||
|
||||
assert!(matches!(
|
||||
*engine
|
||||
.eval::<()>(
|
||||
r#"
|
||||
fn foo() {
|
||||
import "hello" as h;
|
||||
}
|
||||
|
||||
for x in range(0, 10) {
|
||||
foo();
|
||||
}
|
||||
"#
|
||||
)
|
||||
.expect_err("should error"),
|
||||
EvalAltResult::ErrorInFunctionCall(fn_name, _, _) if fn_name == "foo"
|
||||
));
|
||||
|
||||
engine.set_max_modules(0);
|
||||
|
||||
engine.eval::<()>(
|
||||
r#"
|
||||
fn foo() {
|
||||
import "hello" as h;
|
||||
}
|
||||
|
||||
for x in range(0, 10) {
|
||||
foo();
|
||||
}
|
||||
"#,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user