in starlark/src/debug/evaluate.rs [116:172]
fn test_debug_evaluate() {
let mut a = assert::Assert::new();
a.globals_add(debugger);
let check = r#"
assert_eq(debug_evaluate("1+2"), 3)
x = 10
assert_eq(debug_evaluate("x"), 10)
assert_eq(debug_evaluate("x = 5"), None)
assert_eq(x, 5)
y = [20]
debug_evaluate("y.append(30)")
assert_eq(y, [20, 30])
"#;
// Check evaluation works at the root
a.pass(check);
// And inside functions
a.pass(&format!(
"def local():\n{}\nlocal()",
check.lines().map(|x| format!(" {}", x)).join("\n")
));
// Check we get the right stack frames
a.pass(
r#"
def foo(x, y, z):
return bar(y)
def bar(x):
return debug_evaluate("x")
assert_eq(foo(1, 2, 3), 2)
"#,
);
// Check we can access module-level and globals
a.pass(
r#"
x = 7
def bar(y):
return debug_evaluate("x + y")
assert_eq(bar(4), 4 + 7)
"#,
);
// Check module-level access works in imported modules
a.module(
"test",
r#"
x = 7
z = 2
def bar(y):
assert_eq(x, 7)
debug_evaluate("x = 20")
assert_eq(x, 7) # doesn't work for frozen variables
return debug_evaluate("x + y + z")
"#,
);
a.pass("load('test', 'bar'); assert_eq(bar(4), 4 + 7 + 2)");
}