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 S4 rows with their Common Lisp values: a read of a cell that may be
6
//! unbound, a binder of an unbound special, the bound flag of a unit that
7
//! raises or traps, and a unit that does not compile.
8

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

            
12
use persist::{Row, assert_pinned, row};
13

            
14
const NEVER: &str = "(> (entity-count) 99)";
15
const ALWAYS: &str = "(> (entity-count) -1)";
16
const LOOP: &str = "(defun lp (n) (lp (+ n 1)))";
17

            
18
1
fn rows() -> Vec<Row> {
19
1
    let unset = format!("(defvar x) (when {NEVER} (setf x 1))");
20
1
    vec![
21
1
        row("U1", &[&format!("{unset} x"), "x"]),
22
1
        row(
23
1
            "U2",
24
1
            &[&format!(
25
1
                "{unset} (handler-case x (unbound-variable (e) 'u))"
26
1
            )],
27
1
        ),
28
1
        row(
29
1
            "U3",
30
1
            &[&format!("(defvar x) (when {ALWAYS} (setf x 1)) x"), "x"],
31
1
        ),
32
1
        row(
33
1
            "U4",
34
1
            &[
35
1
                &format!(
36
1
                    "(defvar lim) (handler-case (progn (when {ALWAYS} (error 'boom \"m\")) (defvar lim 10) 0) (t (e) 0)) (handler-case lim (unbound-variable (e) 'u))"
37
1
                ),
38
1
                "lim",
39
1
            ],
40
1
        ),
41
1
        row(
42
1
            "U5",
43
1
            &[&format!(
44
1
                "{unset} (handler-case (+ x 1) (unbound-variable (e) 'u))"
45
1
            )],
46
1
        ),
47
1
        row(
48
1
            "L1",
49
1
            &[
50
1
                "(defvar x) (defun get () x) (list (let ((x 3)) (get)) (handler-case (get) (unbound-variable (e) 'u)))",
51
1
                "x",
52
1
            ],
53
1
        ),
54
1
        row(
55
1
            "L2",
56
1
            &[
57
1
                "(defvar x) (defun g () x) (defun f (x) (g)) (list (f 3) (handler-case (g) (unbound-variable (e) 'u)))",
58
1
            ],
59
1
        ),
60
1
        row("L3", &["(defvar x) (let ((x 3)) (error 'boom \"m\"))", "x"]),
61
1
        row(
62
1
            "L4",
63
1
            &["(defvar x 1)", "(let ((x 3)) (error 'boom \"m\"))", "x"],
64
1
        ),
65
1
        row("R1", &["(defvar a) (setf a 5) (error 'boom \"m\")", "a"]),
66
1
        row(
67
1
            "R2",
68
1
            &[
69
1
                &format!("(defvar a) (when {ALWAYS} (error 'boom \"m\")) (setf a 5)"),
70
1
                "a",
71
1
            ],
72
1
        ),
73
1
        row(
74
1
            "R3",
75
1
            &[
76
1
                "(defun f () 1)",
77
1
                &format!("(when {ALWAYS} (error 'boom \"m\")) (defun f () 2) 0"),
78
1
                "(f)",
79
1
            ],
80
1
        ),
81
1
        row("T1", &[LOOP, "(defvar a) (setf a 5) (lp a)", "a"]),
82
1
        row(
83
1
            "T2",
84
1
            &[
85
1
                LOOP,
86
1
                &format!("(defvar a) (when {ALWAYS} (lp (entity-count))) (setf a 5)"),
87
1
                "a",
88
1
            ],
89
1
        ),
90
1
        row("E1", &["(defun f () 1)", "(defun f () 2) (car 5)", "(f)"]),
91
1
        row("E2", &["(defparameter *a* 2) (car 5)", "*a*"]),
92
1
        row(
93
1
            "E3",
94
1
            &[
95
1
                "(defparameter *a* 1)",
96
1
                "(defparameter *a* 2) (car 5)",
97
1
                "*a*",
98
1
            ],
99
1
        ),
100
1
        row(
101
1
            "E4",
102
1
            &[
103
1
                "(setf q 1)",
104
1
                "(setf q 2) (defmacro m () 1) (car 5)",
105
1
                "(list q (m))",
106
1
            ],
107
1
        ),
108
    ]
109
1
}
110

            
111
/// What each row prints; every row reads as Common Lisp does, or loudly.
112
const TODAY: &[(&str, &[&str])] = &[
113
    (
114
        "U1",
115
        &[
116
            "err: UNBOUND-VARIABLE: the variable X is unbound",
117
            "err: Compile error: symbol 'X' has no value",
118
        ],
119
    ),
120
    ("U2", &["u"]),
121
    ("U3", &["1", "1"]),
122
    (
123
        "U4",
124
        &["u", "err: Compile error: symbol 'LIM' has no value"],
125
    ),
126
    ("U5", &["u"]),
127
    (
128
        "L1",
129
        &["(3 u)", "err: Compile error: symbol 'X' has no value"],
130
    ),
131
    ("L2", &["(3 u)"]),
132
    (
133
        "L3",
134
        &[
135
            "err: BOOM: m",
136
            "err: Compile error: symbol 'X' has no value",
137
        ],
138
    ),
139
    ("L4", &["-", "err: BOOM: m", "1"]),
140
    ("R1", &["err: BOOM: m", "5"]),
141
    (
142
        "R2",
143
        &[
144
            "err: BOOM: m",
145
            "err: Compile error: symbol 'A' has no value",
146
        ],
147
    ),
148
    ("R3", &["f", "err: BOOM: m", "1"]),
149
    (
150
        "T1",
151
        &[
152
            "lp",
153
            "err: execution trapped: error while executing at ",
154
            "5",
155
        ],
156
    ),
157
    (
158
        "T2",
159
        &[
160
            "lp",
161
            "err: execution trapped: error while executing at ",
162
            "err: Compile error: symbol 'A' has no value",
163
        ],
164
    ),
165
    (
166
        "E1",
167
        &["f", "err: Compile error: CAR expects a list, got 5", "1"],
168
    ),
169
    (
170
        "E2",
171
        &[
172
            "err: Compile error: CAR expects a list, got 5",
173
            "err: Undefined symbol: *A*",
174
        ],
175
    ),
176
    (
177
        "E3",
178
        &["-", "err: Compile error: CAR expects a list, got 5", "1"],
179
    ),
180
    (
181
        "E4",
182
        &[
183
            "1",
184
            "err: Compile error: CAR expects a list, got 5",
185
            "err: Undefined symbol: M",
186
        ],
187
    ),
188
];
189

            
190
#[test]
191
1
fn every_row_reads_as_common_lisp() {
192
1
    assert_pinned(&rows(), TODAY);
193
1
}