#[must_use]
pub fn os() -> &'static str {
std::env::consts::OS
}
#[must_use]
pub fn arch() -> &'static str {
match std::env::consts::ARCH {
"aarch64" => "arm64",
"x86" => "x86",
other => other,
}
}
#[must_use]
pub fn echo() -> serde_json::Value {
serde_json::json!({ "os": os(), "arch": arch() })
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::panic)]
use super::*;
#[test]
fn the_echo_has_exactly_the_two_members_the_consumer_compares() {
let echo = echo();
let object = echo.as_object().unwrap();
let mut keys: Vec<&str> = object.keys().map(String::as_str).collect();
keys.sort_unstable();
assert_eq!(keys, vec!["arch", "os"]);
}
#[test]
fn the_names_are_the_consumers_spellings_not_rusts() {
assert_ne!(arch(), "aarch64");
assert_ne!(os(), "darwin");
}
#[test]
fn this_host_reports_one_of_the_three_supported_systems() {
assert!(
matches!(os(), "linux" | "macos" | "windows"),
"unexpected os {}",
os()
);
}
}