Lines
100 %
Functions
Branches
//! Plan 0014 Stage 0 (ISS-027, ISS-054, ISS-056, ISS-057): what the `nms`
//! command line shows for a condition, a void program, a PRINT, and where
//! `--compile` writes.
use std::path::PathBuf;
use std::process::{Command, Output};
fn nms(args: &[&str]) -> Output {
Command::new(env!("CARGO_BIN_EXE_nms"))
.args(args)
.output()
.expect("invoke nms")
}
fn stdout(out: &Output) -> String {
String::from_utf8_lossy(&out.stdout).into_owned()
fn stderr(out: &Output) -> String {
String::from_utf8_lossy(&out.stderr).into_owned()
#[test]
fn an_uncaught_condition_prints_its_code_and_message() {
let out = nms(&["-e", r#"(error 'boom "m")"#]);
assert!(!out.status.success());
assert!(stderr(&out).contains("BOOM: m"), "{}", stderr(&out));
fn a_quote_form_condition_code_is_the_same_as_the_reader_quote() {
let out = nms(&["-e", r#"(error (quote boom) "m")"#]);
fn a_void_program_is_not_an_error() {
let out = nms(&["-e", "(defvar *x* 1)"]);
assert!(out.status.success(), "{}", stderr(&out));
assert_eq!(stdout(&out), "");
fn print_output_is_echoed_before_the_value() {
let out = nms(&["-e", r#"(progn (print "x") 5)"#]);
assert_eq!(stdout(&out), "x\n5\n");
fn compile_writes_to_the_output_path() {
let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("nms-compile-output");
let source = dir.join("prog.nms");
let target = dir.join("out").join("prog.bin");
std::fs::create_dir_all(dir.join("out")).unwrap();
std::fs::write(&source, "(+ 1 2)").unwrap();
let out = nms(&[
"--compile",
source.to_str().unwrap(),
"--output",
target.to_str().unwrap(),
]);
assert!(target.exists(), "the bytecode lands at --output");
assert!(
!source.with_extension("wasm").exists(),
"nothing beside the source"
);
std::fs::remove_dir_all(&dir).ok();
fn compile_reports_a_script_compile_error() {
let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("nms-compile-error");
let source = dir.join("bad.nms");
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(&source, "(unclosed").unwrap();
let out = nms(&["--compile", source.to_str().unwrap()]);
stderr(&out).starts_with("script compile error: "),
"{}",
stderr(&out)