diff --git a/compile_state/src/state.rs b/compile_state/src/state.rs index cebd7a0cbb..207fef9e80 100644 --- a/compile_state/src/state.rs +++ b/compile_state/src/state.rs @@ -407,20 +407,21 @@ Multiply a sequence of numbers. (*) will return 1. Section: math Example: -(ns-import 'math) -(test::assert-equal 1 (*)) -(test::assert-equal 5 (* 5)) -(test::assert-equal 5 (* 1 5)) -(test::assert-equal 5.0 (* 1.0 5)) -(test::assert-equal 7.5 (* 1.5 5)) -(test::assert-equal 7.5 (* 1.5 5.0)) -(test::assert-equal 15 (* 3 5)) -(test::assert-equal 8 (* 1 2 4)) -(test::assert-equal 16 (* 2 2 4)) -(test::assert-equal 16.0 (* 2 2.0 4)) -(test::assert-equal 16.0 (* 2.0 2.0 4.0)) -(test::assert-equal 55.0000000001 (* 100 0.55)) -(test::assert-error (* 1 2 4 "5"))"#), +(assert-true #f) +;;(ns-import 'math) +;;(test::assert-equal 1 (*)) +;;(test::assert-equal 5 (* 5)) +;;(test::assert-equal 5 (* 1 5)) +;;(test::assert-equal 5.0 (* 1.0 5)) +;;(test::assert-equal 7.5 (* 1.5 5)) +;;(test::assert-equal 7.5 (* 1.5 5.0)) +;;(test::assert-equal 15 (* 3 5)) +;;(test::assert-equal 8 (* 1 2 4)) +;;(test::assert-equal 16 (* 2 2 4)) +;;(test::assert-equal 16.0 (* 2 2.0 4)) +;;(test::assert-equal 16.0 (* 2.0 2.0 4.0)) +;;(test::assert-equal 55.0000000001 (* 100 0.55)) +;;(test::assert-error (* 1 2 4 "5"))"#), div: add_special(vm, "/", r#"Usage: (/ number+) Divide a sequence of numbers. Requires at least two numbers. diff --git a/lisp/core.slosh b/lisp/core.slosh index b12d5fa47c..4efad7db47 100644 --- a/lisp/core.slosh +++ b/lisp/core.slosh @@ -422,3 +422,7 @@ Example: `(~condition ~(make-action action) ~@(make-cond (first (first others)) (rest (first others)) (rest others)))))) `(if ~@(make-cond (first (first branches)) (rest (first branches)) (rest branches))))))) +#% +asserts true +%# +(def assert-true (fn (x) (= x #t))) diff --git a/lisp/test.slosh b/lisp/test.slosh new file mode 100644 index 0000000000..d54f73b773 --- /dev/null +++ b/lisp/test.slosh @@ -0,0 +1,6 @@ +;; TODO PC add test functions here! and give them the right docs. + +#% +asserts true +%# +(def assert-true (fn (x) (= x #t))) diff --git a/slosh/src/load_eval.rs b/slosh/src/load_eval.rs index 55d2d48be1..69d1aecd46 100644 --- a/slosh/src/load_eval.rs +++ b/slosh/src/load_eval.rs @@ -16,7 +16,7 @@ const fn from_utf8(bytes: &[u8]) -> &str { } } -//const CORE_LISP: &[u8] = include_bytes!("../lisp/core.slosh"); +const TEST_LISP: &str = from_utf8(include_bytes!("../../lisp/test.slosh")); const CORE_LISP: &str = from_utf8(include_bytes!("../../lisp/core.slosh")); const COLORS_LISP: &str = from_utf8(include_bytes!("../../lisp/sh-color.slosh")); pub const SLSHRC: &str = from_utf8(include_bytes!("../../init.slosh")); @@ -117,6 +117,7 @@ pub(crate) fn load_internal(vm: &mut SloshVm, name: &'static str) -> VMResult Reader::from_file(file, vm, name, 1, 0), Err(e) => match name { "core.slosh" => Reader::from_static_string(CORE_LISP, vm, name, 1, 0), + "test.slosh" => Reader::from_static_string(TEST_LISP, vm, name, 1, 0), "sh-color.slosh" => Reader::from_static_string(COLORS_LISP, vm, name, 1, 0), "init.slosh" => Reader::from_static_string(SLSHRC, vm, name, 1, 0), _ => { @@ -126,6 +127,7 @@ pub(crate) fn load_internal(vm: &mut SloshVm, name: &'static str) -> VMResult match name { "core.slosh" => Reader::from_static_string(CORE_LISP, vm, name, 1, 0), + "test.slosh" => Reader::from_static_string(TEST_LISP, vm, name, 1, 0), "sh-color.slosh" => Reader::from_static_string(COLORS_LISP, vm, name, 1, 0), "init.slosh" => Reader::from_static_string(SLSHRC, vm, name, 1, 0), _ => { diff --git a/slosh/src/main.rs b/slosh/src/main.rs index 8bda0910f7..f31d57287c 100644 --- a/slosh/src/main.rs +++ b/slosh/src/main.rs @@ -486,17 +486,19 @@ fn exec_expression(res: String, env: &mut SloshVm) { mod tests { use super::*; use crate::tests::utils::exec; + use builtins::print::{pr, pretty_value}; use compile_state::state::{new_slosh_vm, CompileState, SloshVm, SloshVmTrait}; use lazy_static::lazy_static; use regex::{Regex, RegexBuilder}; use sl_compiler::pass1::pass1; use sl_compiler::{compile, ReadError, Reader}; - use slvm::{Value, RET}; + use slvm::{VMResult, Value, RET}; use std::borrow::Cow; use std::cmp::Ordering; use std::collections::HashSet; use std::error::Error; use std::fmt::{Debug, Display, Formatter}; + use std::io::stdout; use std::sync::Arc; // I didn't really know this was possible but for test utilities just use @@ -554,6 +556,10 @@ mod tests { exemption_set.insert("*int-bits*"); exemption_set.insert("get-prop"); exemption_set.insert("expand-macro"); + + exemption_set.insert("ns-import"); + exemption_set.insert("test::assert-equal"); + exemption_set.insert("test::assert-error"); exemption_set }; } @@ -783,25 +789,47 @@ mod tests { type DocResult = Result; + pub fn no_op(vm: &mut SloshVm, registers: &[Value]) -> VMResult { + Ok(Value::Nil) + } + + pub fn assert_equal(vm: &mut SloshVm, registers: &[Value]) -> VMResult { + Ok(Value::True) + } + + pub fn assert_error(vm: &mut SloshVm, registers: &[Value]) -> VMResult { + Ok(Value::True) + } + #[test] fn test_global_slosh_docs() { let mut env = new_slosh_vm(); set_builtins(&mut env); + env.set_global_builtin("ns-import", no_op); + env.set_global_builtin("test::assert-equal", assert_equal); + env.set_global_builtin("test::assert-error", assert_error); + let mut docs: Vec = vec![]; Namespace::Global.add_docs(&mut docs, &mut env).unwrap(); + println!("Now go through and run tests!"); + + exec(&mut env, "(nil? #f)".to_string()); + for doc in docs { println!("ns: {:?}", doc.namespace); println!(" sym: {}", doc.symbol); println!(" type: {}", doc.symbol_type); - println!(" doc_string: {:?}", doc.doc_string); if let Some(example) = doc.doc_string.example { + println!(" example: {:?}", example); let val = exec(&mut env, example); //TODO PC 2 problems. - // 1. exec_expression doesn't work, and might not w/o editing because it does - // not (by design) show errors, so might need to refactor that. - // 2. there is no assert-equal!? + // 1. trying to add the assert commands but commands in core.slosh + // do not appear to be "in" the environment yet. + // SO... load_internal is called *somehow* in main() but I need to know + // how to load it so I have access to core.slosh and test.slosh + // OR maybe i just load it directly? } } }