1
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
2
// Cranelift backend refuses to run under Miri.
3
#![cfg(not(miri))]
4

            
5
//! PERSIST rows with their Common Lisp values: `&body` is `&rest` in a macro
6
//! lambda list only, and any other `&` name in a lambda list is an error.
7

            
8
#[path = "persist/rows.rs"]
9
mod persist;
10

            
11
use persist::{Row, assert_pinned, assert_pinned_wide, row};
12

            
13
1
fn accepted() -> Vec<Row> {
14
1
    vec![
15
1
        row(
16
1
            "B1",
17
1
            &[
18
1
                "(defmacro my-progn (&body b) `(progn ,@b))",
19
1
                "(my-progn (print 1) 5)",
20
1
            ],
21
1
        ),
22
1
        row(
23
1
            "B2",
24
1
            &[
25
1
                "(defmacro wrap (&body body) `(list ,@body))",
26
1
                "(wrap 1 2 3)",
27
1
            ],
28
1
        ),
29
1
        row(
30
1
            "B3",
31
1
            &[
32
1
                "(defmacro req (a &body body) `(list ,a ,@body))",
33
1
                "(req 1 2 3)",
34
1
            ],
35
1
        ),
36
1
        row(
37
1
            "B4",
38
1
            &[
39
1
                "(defmacro destr ((a &body bs) c) `(list ,a ',bs ,c))",
40
1
                "(destr (1 2 3) 4)",
41
1
            ],
42
1
        ),
43
1
        row("B13", &["(defmacro mr (&rest b) `(list ,@b))", "(mr 1 2)"]),
44
1
        row(
45
1
            "B14",
46
1
            &[
47
1
                "(defun fk (a &optional (b 2) &key (c 3)) (list a b c))",
48
1
                "(fk 1)",
49
1
            ],
50
1
        ),
51
    ]
52
1
}
53

            
54
1
fn refused() -> Vec<Row> {
55
1
    vec![
56
1
        row("B5", &["(defun f5 (&body x) x)"]),
57
1
        row("B6", &["(funcall (lambda (&body x) x) 1 2)"]),
58
1
        row("B7", &["(defun f7 (&foo x) x)"]),
59
1
        row("B8", &["(defmacro m8 (&foo x) x)"]),
60
1
        row("B9", &["(defmacro m9 (&body a &rest b) a)"]),
61
1
        row("B10", &["(defmacro m10 (&rest a &body b) a)"]),
62
1
        row("B11", &["(defmacro m11 (a &body) a)"]),
63
1
        row("B12", &["(defun f12 (&environment e) e)"]),
64
1
        row("B15", &["(defun f15 (&rest r &optional x) (list r x))"]),
65
1
        row("B16", &["(defmacro m16 (&rest r &optional x) r)"]),
66
1
        row("B17", &["(defun f17 (a &rest r &optional) a)"]),
67
    ]
68
1
}
69

            
70
/// CL: B1 5 (prints 1), B2 and B3 (1 2 3), B4 (1 (2 3) 4), B13 (1 2), B14
71
/// (1 2 3). B1-B3 moved: &body is now &rest in a macro. B4 stays an error, a
72
/// macro lambda list has no destructuring.
73
const ACCEPTED: &[(&str, &[&str])] = &[
74
    ("B1", &["my-progn", "5"]),
75
    ("B2", &["wrap", "(1 2 3)"]),
76
    ("B3", &["req", "(1 2 3)"]),
77
    (
78
        "B4",
79
        &[
80
            "err: Compile error: DEFMACRO: required parameter ",
81
            "err: Undefined symbol: DESTR",
82
        ],
83
    ),
84
    ("B13", &["mr", "(1 2)"]),
85
    ("B14", &["fk", "(1 2 3)"]),
86
];
87

            
88
/// CL: B5, B6, B9-B11 and B15-B17 (SBCL: misplaced &OPTIONAL) are errors; B7, B8 and B12 are errors by the
89
/// owner's Q2 decision (SBCL only warns). B5-B8, B11 and B12 moved from
90
/// accepted; B9 and B10 now report the second rest parameter.
91
const REFUSED: &[(&str, &[&str])] = &[
92
    (
93
        "B5",
94
        &["err: Compile error: DEFUN: &body is allowed in a macro lambda list only"],
95
    ),
96
    (
97
        "B6",
98
        &["err: Compile error: LAMBDA: &body is allowed in a macro lambda list only"],
99
    ),
100
    (
101
        "B7",
102
        &["err: Compile error: DEFUN: unknown lambda list keyword &FOO"],
103
    ),
104
    (
105
        "B8",
106
        &["err: Compile error: DEFMACRO: unknown lambda list keyword &FOO"],
107
    ),
108
    (
109
        "B9",
110
        &["err: Compile error: DEFMACRO: multiple &rest parameters"],
111
    ),
112
    (
113
        "B10",
114
        &["err: Compile error: DEFMACRO: multiple &rest parameters"],
115
    ),
116
    (
117
        "B11",
118
        &["err: Compile error: DEFMACRO: &body needs a parameter"],
119
    ),
120
    (
121
        "B12",
122
        &["err: Compile error: DEFUN: unknown lambda list keyword &ENVIRONMENT"],
123
    ),
124
    (
125
        "B15",
126
        &["err: Compile error: DEFUN: &OPTIONAL after post-&rest"],
127
    ),
128
    (
129
        "B16",
130
        &["err: Compile error: DEFMACRO: &OPTIONAL after post-&rest"],
131
    ),
132
    (
133
        "B17",
134
        &["err: Compile error: DEFUN: &OPTIONAL after post-&rest"],
135
    ),
136
];
137

            
138
#[test]
139
1
fn accepted_rows_read_as_common_lisp() {
140
1
    assert_pinned(&accepted(), ACCEPTED);
141
1
}
142

            
143
#[test]
144
1
fn refused_rows_are_compile_errors() {
145
1
    assert_pinned_wide(&refused(), REFUSED, 70);
146
1
}