//! `wai-room --version`: this program's own version and the toolchain it belongs to, in the form //! `wai doctor` reads to tell whether it and a `wai` agree. The toolchain's version is //! `wai/wai-rs/Cargo.toml`'s, as this tree states it. use std::path::Path; use std::process::Command; fn run(args: &[&str]) -> (bool, String) { let o = Command::new(env!("CARGO_BIN_EXE_wai-room")).args(args).output().expect("wai-room runs"); (o.status.success(), String::from_utf8(o.stdout).unwrap()) } fn toolchain() -> String { let manifest = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../../wai/wai-rs/Cargo.toml"); let text = std::fs::read_to_string(&manifest).unwrap_or_else(|e| panic!("{}: {e}", manifest.display())); text.lines().find_map(|l| l.strip_prefix("version = \"")?.strip_suffix('"')).expect("a version").to_string() } #[test] fn it_names_itself_and_the_toolchain_it_belongs_to() { let (ok, text) = run(&["--version"]); assert!(ok, "{text}"); assert_eq!(text.trim(), format!("wai-room {}, of the WAI toolchain {}", env!("CARGO_PKG_VERSION"), toolchain())); for args in [&["--version", "--json"][..], &["--json", "--version"]] { let (ok, text) = run(args); assert!(ok, "{text}"); let v: serde_json::Value = serde_json::from_str(&text).unwrap_or_else(|e| panic!("{args:?}: {e}: {text}")); assert_eq!((v["wai"].as_str(), v["op"].as_str(), v["ok"].as_bool()), (Some("envelope/1"), Some("toolchain.show"), Some(true)), "{v}"); assert_eq!(v["data"]["program"], "wai-room"); assert_eq!(v["data"]["version"], env!("CARGO_PKG_VERSION")); assert_eq!(v["data"]["toolchain"].as_str(), Some(toolchain().as_str())); } }