1
//! A macro body that discards a runtime sub-result (a DOLIST over a runtime
2
//! list here) is the structured expansion-time error, not a silent `nil`.
3

            
4
use rpc::{ScriptCtx, Session};
5
use uuid::Uuid;
6

            
7
#[tokio::test(flavor = "current_thread")]
8
1
async fn a_dolist_over_an_effectful_list_in_a_macro_body_is_refused() {
9
1
    let mut session = Session::new(ScriptCtx::new(Uuid::new_v4())).unwrap();
10
1
    let form = "(progn (defmacro m () (dolist (i (progn (print 0) (list 1))) (print i)) nil) (m))";
11
1
    let resp = session.handle_form(&format!("(:id 1 :form {form})")).await;
12
1
    assert!(
13
1
        resp.contains("a macro body cannot use a runtime value or effect at expansion time"),
14
1
        "got: {resp}"
15
1
    );
16
1
}
17

            
18
#[tokio::test(flavor = "current_thread")]
19
1
async fn a_do_body_burying_an_effect_in_a_let_init_is_refused() {
20
1
    let mut session = Session::new(ScriptCtx::new(Uuid::new_v4())).unwrap();
21
    let form =
22
1
        "(progn (defmacro m () (do ((i 0 (+ i 1))) ((= i 1)) (let ((x (print i))) nil)) nil) (m))";
23
1
    let resp = session.handle_form(&format!("(:id 1 :form {form})")).await;
24
1
    assert!(
25
1
        resp.contains("a macro body cannot use a runtime value or effect at expansion time"),
26
1
        "got: {resp}"
27
1
    );
28
1
}
29

            
30
#[tokio::test(flavor = "current_thread")]
31
1
async fn a_do_result_form_behind_return_from_is_not_an_expansion_effect() {
32
1
    let mut session = Session::new(ScriptCtx::new(Uuid::new_v4())).unwrap();
33
1
    let form = "(progn (defmacro m () (block b (do ((i 0 (+ i 1))) ((= i 1) (print 99)) (return-from b 7)))) (m))";
34
1
    let resp = session.handle_form(&format!("(:id 1 :form {form})")).await;
35
1
    assert!(!resp.contains(":error"), "got: {resp}");
36
1
    assert!(!resp.contains("99"), "the result form must not run: {resp}");
37
1
    assert!(resp.contains('7'), "got: {resp}");
38
1
}