1
// Skipped under Miri: compiling a script builds wasm through wasmtime.
2
#![cfg(not(miri))]
3

            
4
//! SHOULD-APPLY is a separately compiled function: it reads no runtime
5
//! variable a function kept from a binder that ended.
6

            
7
const KEEP: &str = "(let ((r (+ 1 (entity-count)))) (defun cnt () r))";
8

            
9
3
fn compile_error(source: &str) -> String {
10
3
    rpc::compile_script(source)
11
3
        .expect_err("a kept runtime variable is not readable")
12
3
        .to_string()
13
3
}
14

            
15
#[test]
16
1
fn should_apply_does_not_read_the_runtime_variable_a_function_kept() {
17
1
    let locals = "(a (+ 7 (entity-count))) (b (+ 7 (entity-count))) (c (+ 7 (entity-count)))";
18
1
    for test in ["(= (cnt) 1)", "(= (cnt) 7)"] {
19
2
        let source = format!("{KEEP} (defun should-apply () (let ({locals}) {test}))");
20
2
        let err = compile_error(&source);
21
2
        assert!(err.contains("CNT: reads R, a runtime variable"), "{err}");
22
    }
23
1
}
24

            
25
#[test]
26
1
fn should_apply_without_locals_reads_none_either() {
27
1
    let err = compile_error(&format!("{KEEP} (defun should-apply () (= (cnt) 1))"));
28
1
    assert!(err.contains("CNT: reads R, a runtime variable"), "{err}");
29
1
}