Lines
93.75 %
Functions
60 %
Branches
100 %
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! A closure and a condition print in one opaque form each, whatever holds them.
use nms::interpreter::Interpreter;
use scripting::nomiscript::format_value;
fn printed(src: &str) -> String {
let mut interp = Interpreter::new(false).unwrap();
let value = interp
.eval(src)
.unwrap_or_else(|e| panic!("eval {src:?}: {e}"))
.into_iter()
.next_back()
.unwrap_or_else(|| panic!("eval {src:?} produced no value"));
format_value(&value)
}
#[test]
fn a_closure_prints_as_its_site() {
for (src, text) in [
("(lambda (x) x)", "#<closure:0>"),
("(list 1 (lambda (x) x))", "(1 #<closure:0>)"),
(
"(defstruct pt x) (let ((f (lambda () 1))) (make-pt :x f))",
"#S(PT :X #<closure:0>)",
),
] {
assert_eq!(printed(src), text, "{src}");
fn a_condition_prints_in_one_opaque_form() {
"(defstruct pt x) (defvar *p* (make-pt :x 1)) (handler-case (error 'boom \"m\" *p*) (boom (e) (list 1 e)))",
"(1 #<condition>)",
"(handler-case (error 'boom \"m\") (boom (e) e))",
"#<condition>",