1
//! Regression: a `catch-each` helper body must not inherit the enclosing
2
//! function's `unwind-protect` frames. The leak only shows here as the
3
//! `push_unwind_frame` precondition under `--cfg anodized_panic`; the codegen
4
//! test `unwind_protect_helper_scope` guards it in every build.
5

            
6
use rpc::{ScriptCtx, Session};
7
use uuid::Uuid;
8

            
9
1
async fn rpc_response(form: &str) -> String {
10
1
    let mut session = Session::new(ScriptCtx::new(Uuid::new_v4())).unwrap();
11
1
    session.handle_form(&format!("(:id 9 :form {form})")).await
12
1
}
13

            
14
1
fn extract_value(response: &str) -> &str {
15
1
    response
16
1
        .split_once(":value ")
17
1
        .map(|(_, rest)| rest.trim_end_matches(')').trim())
18
1
        .unwrap_or(response)
19
1
}
20

            
21
#[tokio::test(flavor = "current_thread")]
22
1
async fn outer_unwind_protect_does_not_disrupt_catch_each_helper_return_from() {
23
1
    let form = r#"(block a (block b (block c (block d
24
1
        (unwind-protect
25
1
          (fold (lambda (acc cell) (+ acc 1)) 0
26
1
            (catch-each (list 1 2) x (block q (unwind-protect (return-from q x) 0))))
27
1
          (+ 0 777777))))))"#;
28
1
    let resp = rpc_response(form).await;
29
1
    assert!(!resp.contains(":error"), "{resp}");
30
1
    assert_eq!(
31
1
        extract_value(&resp),
32
1
        "2",
33
1
        "both list items must complete the catch-each per-item helper: {resp}"
34
1
    );
35
1
}