Lines
100 %
Functions
Branches
//! Plan 0014 PERSIST S4 over the session: a cell that may be unbound is read
//! at run time, a binder restores its boundness, and a unit that does not
//! compile leaves every name as it was. The values are Common Lisp's.
use super::*;
async fn units(sources: &[&str]) -> Vec<String> {
let mut session = Session::new(ScriptCtx::new(uuid::Uuid::nil())).expect("Session::new");
let mut outcomes = Vec::new();
for source in sources {
let outcome = session.handle_request(source).await;
outcomes.push(match outcome.payload {
ResponsePayload::Error { message, .. } => message,
ResponsePayload::Value(value) => format!("{value:?}"),
});
}
outcomes
fn value(text: &str) -> String {
format!("{:?}", parse_to_value(text).expect("parses"))
#[tokio::test]
async fn a_read_of_an_unbound_cell_signals_unbound_variable() {
let outcomes = units(&[
"(progn (defvar x) (when (> (rpc-protocol-version) 99) (setf x 1)) (handler-case x (unbound-variable (e) 'u)))",
"(progn (defvar y) (when (> (rpc-protocol-version) 99) (setf y 1)) y)",
])
.await;
assert_eq!(outcomes[0], value("u"));
assert!(outcomes[1].contains("UNBOUND-VARIABLE"), "{}", outcomes[1]);
async fn a_binder_of_an_unbound_special_leaves_it_unbound() {
"(defvar x)",
"(defun g () x)",
"(list (let ((x 3)) (g)) (handler-case (g) (unbound-variable (e) 'u)))",
assert_eq!(outcomes[2], value("(3 u)"));
async fn a_unit_that_does_not_compile_redefines_nothing() {
"(defun f () 1)",
"(defparameter *a* 1)",
"(progn (defun f () 2) (defparameter *a* 2) (car 5))",
"(list (f) *a*)",
assert!(
outcomes[2].contains("CAR expects a list"),
"{}",
outcomes[2]
);
assert_eq!(outcomes[3], value("(1 1)"));
async fn a_unit_interrupted_before_its_call_puts_back_its_definitions() {
let _ = session.handle_request("(defun f () 1)").await;
let program = Reader::parse("(defun f () 2)").expect("parses");
let compiled = session
.compiler
.compile_eval_with_type(&program, &mut session.symbols)
.expect("compiles");
session.interrupt_handle().interrupt();
let ran = session.run_compiled(&RequestId::Int(1), compiled).await;
assert!(matches!(ran, Err(EvalFailure::Interrupted(_))));
let outcome = session.handle_request("(f)").await;
assert_eq!(
outcome.payload,
ResponsePayload::Value(parse_to_value("1").expect("parses"))