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: a unit whose process never runs, or whose SHOULD-APPLY reads
6
//! a carried struct instance, leaves every carried instance as it was.
7

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

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

            
13
const PT: &str = "(defstruct pt x)";
14
const P: &str = "(defvar *p* (make-pt :x 1))";
15
const BUMP: &str = "(setf (pt-x *p*) 2)";
16

            
17
1
fn rows() -> Vec<Row> {
18
1
    vec![
19
1
        row(
20
1
            "A1",
21
1
            &[
22
1
                PT,
23
1
                P,
24
1
                BUMP,
25
1
                "(defun should-apply () 0) (+ 1 1)",
26
1
                "(pt-x *p*)",
27
1
            ],
28
1
        ),
29
1
        row(
30
1
            "A2",
31
1
            &[
32
1
                PT,
33
1
                P,
34
1
                BUMP,
35
1
                "(defun should-apply () (error 'boom \"x\")) (+ 1 1)",
36
1
                "(pt-x *p*)",
37
1
            ],
38
1
        ),
39
1
        row(
40
1
            "A3",
41
1
            &[
42
1
                PT,
43
1
                P,
44
1
                BUMP,
45
1
                "(defun should-apply () (if (= (pt-x *p*) 2) 1 0)) (setf (pt-x *p*) 3)",
46
1
                "(defun should-apply () 1)",
47
1
                "(pt-x *p*)",
48
1
            ],
49
1
        ),
50
1
        row(
51
1
            "A4",
52
1
            &[
53
1
                PT,
54
1
                P,
55
1
                "(defvar *l* (list *p* (make-pt :x 5)))",
56
1
                "(setf (pt-x (car (cdr *l*))) 6)",
57
1
                "(defun should-apply () 0) 1",
58
1
                "(list (pt-x *p*) (pt-x (car *l*)) (pt-x (car (cdr *l*))) (eq *p* (car *l*)))",
59
1
            ],
60
1
        ),
61
1
        row(
62
1
            "A5",
63
1
            &[
64
1
                "(defstruct node val next)",
65
1
                "(defvar *a* (make-node :val 1))",
66
1
                "(defvar *b* (make-node :val 2 :next *a*))",
67
1
                "(progn (setf (node-next *a*) *b*) 1)",
68
1
                "(defun should-apply () 0) 1",
69
1
                "(list (node-val (node-next (node-next *a*))) (eq *a* (node-next *b*)))",
70
1
            ],
71
1
        ),
72
1
        row(
73
1
            "A6",
74
1
            &[
75
1
                PT,
76
1
                P,
77
1
                "(defvar *f* (lambda () (pt-x *p*)))",
78
1
                "(setf (pt-x *p*) 7)",
79
1
                "(defun should-apply () 0) 1",
80
1
                "(funcall *f*)",
81
1
            ],
82
1
        ),
83
1
        row(
84
1
            "A7",
85
1
            &[
86
1
                PT,
87
1
                P,
88
1
                "(defun should-apply () (progn (setf (pt-x *p*) 8) 1)) 0",
89
1
                "(pt-x *p*)",
90
1
            ],
91
1
        ),
92
    ]
93
1
}
94

            
95
const REFUSED: &str = "err: should_apply returned 0, expected 1";
96

            
97
const CL: &[(&str, &[&str])] = &[
98
    ("A1", &["pt", "-", "2", REFUSED, "2"]),
99
    ("A2", &["pt", "-", "2", "err: BOOM: x", "2"]),
100
    ("A3", &["pt", "-", "2", "-", "-", "3"]),
101
    ("A4", &["pt", "-", "-", "6", REFUSED, "(1 1 6 t)"]),
102
    ("A5", &["node", "-", "-", "1", REFUSED, "(1 t)"]),
103
    ("A6", &["pt", "-", "-", "7", REFUSED, "7"]),
104
    ("A7", &["pt", "-", "-", "8"]),
105
];
106

            
107
#[test]
108
1
fn every_row_reads_as_common_lisp() {
109
1
    assert_pinned(&rows(), CL);
110
1
}