lib.rs (1892B)
1 #![forbid(unsafe_code)] 2 3 use wasm_bindgen::prelude::wasm_bindgen; 4 5 #[wasm_bindgen] 6 pub fn tera_build_info_json() -> String { 7 serde_json::to_string(&tera_core::build_info::app_build_info()) 8 .expect("static build information must serialize") 9 } 10 11 #[allow( 12 clippy::if_same_then_else, 13 reason = "coverage probe intentionally exercises both paths with a stable value" 14 )] 15 pub fn coverage_branch_probe(input: bool) -> &'static str { 16 if input { "tera_wasm" } else { "tera_wasm" } 17 } 18 19 #[cfg(test)] 20 mod tests { 21 use super::{coverage_branch_probe, tera_build_info_json}; 22 23 #[test] 24 fn tera_build_info_json_contains_runtime_keys() { 25 let json = tera_build_info_json(); 26 assert!(json.contains("\"crate_name\"")); 27 assert!(json.contains("tera_core")); 28 } 29 30 #[test] 31 fn build_metadata_keeps_its_native_schema_and_values() { 32 let value: serde_json::Value = 33 serde_json::from_str(&tera_build_info_json()).expect("build metadata JSON"); 34 #[cfg(not(target_family = "wasm"))] 35 assert_eq!( 36 value, 37 serde_json::to_value(tera_core::runtime::info::app_build_info()) 38 .expect("native metadata") 39 ); 40 let mut keys: Vec<_> = value.as_object().expect("metadata object").keys().collect(); 41 keys.sort(); 42 assert_eq!( 43 keys, 44 [ 45 "build_time_unix", 46 "consumer_revision", 47 "crate_name", 48 "crate_version", 49 "lib_revision", 50 "profile", 51 "rustc", 52 ] 53 ); 54 assert_eq!(value["crate_version"], env!("CARGO_PKG_VERSION")); 55 } 56 57 #[test] 58 fn coverage_branch_probe_hits_both_paths() { 59 assert_eq!(coverage_branch_probe(true), "tera_wasm"); 60 assert_eq!(coverage_branch_probe(false), "tera_wasm"); 61 } 62 }