//! The CLI opens every readable format (PDF, .ai, images) through the engine's `document.open`. // Integration tests: unwrapping and panicking on failure is fine here, unlike in shipped code (AGENTS.md › Robustness). #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] use std::process::Command; use serde_json::Value; const BIN: &str = env!("CARGO_BIN_EXE_vectorcraft-cli"); fn tmp(name: &str) -> String { let dir = std::env::temp_dir().join(format!("vectorcraft-cli-fileio-{}", std::process::id())); std::fs::create_dir_all(&dir).unwrap(); dir.join(name).to_string_lossy().to_string() } fn ok(args: &[&str]) -> String { let out = Command::new(BIN).args(args).output().unwrap(); assert!(out.status.success(), "{args:?}: {}", String::from_utf8_lossy(&out.stderr)); String::from_utf8(out.stdout).unwrap() } /// `run` a new `width`×`height` document with a rectangle and export it to `out`. fn make(out: &str, width: u32, height: u32) { ok(&[ "run", "--cmd", "file.new", "--params", &format!(r#"{{"width":{width},"height":{height},"artboards":2}}"#), "--cmd", "shape.rectangle", "--params", r#"{"x":1,"y":1,"width":2,"height":1}"#, "--export", out, ]); } fn info(file: &str) -> Value { serde_json::from_str(&ok(&["info", file])).unwrap() } #[test] fn convert_pdf_to_svg_and_info_on_ai() { let pdf = tmp("in.pdf"); make(&pdf, 120, 80); let svg = tmp("out.svg"); ok(&["convert", &pdf, &svg]); assert!(std::fs::read_to_string(&svg).unwrap().contains(""#, ) .unwrap(); let png = tmp("missing-link.png"); let out: Value = serde_json::from_str(ok(&["convert", &svg, &png]).trim()).unwrap(); let w = out["importWarnings"].as_array().unwrap_or_else(|| panic!("{out}")); assert!(w.iter().any(|w| w.as_str().unwrap().contains("nowhere-to-be-found.png")), "{out}"); }