use std::fs;
use assert_cmd::Command;
use predicates::prelude::*;
#[test]
fn wisp_init_scaffolds_partials() {
let dir = tempfile::tempdir().unwrap();
Command::cargo_bin("secunit")
.unwrap()
.arg("-C")
.arg(dir.path())
.args(["wisp", "init"])
.assert()
.success();
let tpl = dir.path().join("templates/wisp");
for name in [
"theme.typ",
"header.typ",
"footer.typ",
"cover.typ",
"toc.typ",
"logo.svg",
] {
assert!(
tpl.join(name).exists(),
"missing scaffolded partial: {name}"
);
}
}
#[test]
fn wisp_init_is_idempotent() {
let dir = tempfile::tempdir().unwrap();
let run = || {
Command::cargo_bin("secunit")
.unwrap()
.arg("-C")
.arg(dir.path())
.args(["wisp", "init"])
.assert()
.success()
};
run();
run().stdout(predicate::str::contains("skipped"));
}
#[test]
fn wisp_export_requires_partials() {
let dir = tempfile::tempdir().unwrap();
fs::create_dir_all(dir.path().join("security")).unwrap();
fs::write(
dir.path().join("security/policy.md"),
"# Access Control\n\nUsers shall authenticate.\n",
)
.unwrap();
Command::cargo_bin("secunit")
.unwrap()
.arg("-C")
.arg(dir.path())
.args(["wisp", "export", "-o"])
.arg(dir.path().join("out.pdf"))
.assert()
.failure()
.stderr(predicate::str::contains("wisp init"));
}
#[test]
fn wisp_export_emits_typst_document() {
let dir = tempfile::tempdir().unwrap();
fs::create_dir_all(dir.path().join("security")).unwrap();
fs::write(
dir.path().join("security/policy.md"),
"# Access Control Policy\n\nUsers shall authenticate.\n\n## Scope\n\nAll systems.\n",
)
.unwrap();
Command::cargo_bin("secunit")
.unwrap()
.arg("-C")
.arg(dir.path())
.args(["wisp", "init"])
.assert()
.success();
let out = dir.path().join("out.pdf");
Command::cargo_bin("secunit")
.unwrap()
.arg("-C")
.arg(dir.path())
.args(["wisp", "export", "-o"])
.arg(&out)
.assert()
.success();
let typ = fs::read_to_string(dir.path().join("out.typ")).expect("emitted main.typ");
assert!(typ.contains("= Access Control Policy"), "heading converted");
assert!(typ.contains("== Scope"), "subheading converted");
assert!(typ.contains("#wisp-cover(ctx)"), "cover wired");
assert!(typ.contains("#wisp-toc(ctx)"), "toc wired");
assert!(typ.contains("#import \"theme.typ\""), "imports partials");
}