Lines
100 %
Functions
Branches
// Skipped under Miri: these tests run the nms binary, which compiles and runs
// wasm via wasmtime, whose Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! PERSIST rows: a printed value nests as deep as a result does, and the
//! depth placeholder replaces the first level past `MAX_WIRE_LIST_DEPTH`.
#[path = "persist/stdout.rs"]
mod stdout;
use stdout::session;
const CAP: usize = 62;
/// The `(print 7 ...)` log line, which the REPL's own value echo cannot be
/// mistaken for.
fn logged_line(units: &[&str]) -> String {
let run = session(units);
assert!(!run.stderr.contains("panicked"), "{}", run.stderr);
run.stdout
.lines()
.find(|line| line.starts_with("> 7 "))
.unwrap_or_default()
.to_string()
}
fn depth_counts(line: &str, opener: &str) -> String {
format!(
"{}/{}",
line.matches(opener).count(),
line.matches("#<...>").count()
)
fn struct_chain(levels: usize) -> String {
let line = logged_line(&[
"(defstruct pt x)",
"(defvar *k* 0)",
"(defun chain (n) (if (= n 0) (make-pt :x 0) (make-pt :x (chain (- n 1)))))",
&format!("(defvar *q* (progn (setf *k* {}) (chain *k*)))", levels - 1),
"(print 7 *q*)",
]);
depth_counts(&line, "#S(PT")
fn list_nest(levels: usize) -> String {
let steps = vec!["1"; levels].join(" ");
let line = logged_line(&[&format!(
"(print 7 (let ((l nil)) (dolist (i '({steps})) (setf l (list l))) l))"
)]);
depth_counts(&line, "(")
#[test]
fn a_struct_chain_prints_every_level_to_the_cap() {
assert_eq!(struct_chain(CAP - 1), format!("{}/0", CAP - 1));
assert_eq!(struct_chain(CAP), format!("{CAP}/0"));
fn a_struct_chain_one_past_the_cap_ends_in_the_placeholder() {
assert_eq!(struct_chain(CAP + 1), format!("{CAP}/1"));
fn a_list_prints_every_level_to_the_cap() {
assert_eq!(list_nest(CAP - 1), format!("{}/0", CAP - 1));
assert_eq!(list_nest(CAP), format!("{CAP}/0"));
fn a_list_one_past_the_cap_ends_in_the_placeholder() {
assert_eq!(list_nest(CAP + 1), format!("{CAP}/1"));
fn a_cyclic_struct_prints_to_the_cap_then_the_placeholder() {
"(defstruct node next)",
"(defvar *n* (make-node))",
"(setf (node-next *n*) *n*)",
"(print 7 *n*)",
assert_eq!(depth_counts(&line, "#S(NODE"), format!("{CAP}/1"), "{line}");