scaffolding.rs (2236B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 use serde_json::{self, Value}; 6 use std::env; 7 use std::fs::{remove_file, File}; 8 use std::path::Path; 9 use std::process::Command; 10 11 #[test] 12 fn properties_list_json() { 13 let top = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()) 14 .join("..") 15 .join("..") 16 .join(".."); 17 let json = top 18 .join("target") 19 .join("doc") 20 .join("servo") 21 .join("css-properties.json"); 22 if json.exists() { 23 remove_file(&json).unwrap() 24 } 25 let python = env::var("PYTHON").ok().unwrap_or_else(find_python); 26 let script = top 27 .join("components") 28 .join("style") 29 .join("properties") 30 .join("build.py"); 31 let status = Command::new(python) 32 .arg(&script) 33 .arg("servo") 34 .arg("html") 35 .arg("regular") 36 .status() 37 .unwrap(); 38 assert!(status.success(), "{:?}", status); 39 40 let properties: Value = serde_json::from_reader(File::open(json).unwrap()).unwrap(); 41 assert!(properties.as_object().unwrap().len() > 100); 42 assert!(properties.as_object().unwrap().contains_key("margin")); 43 assert!(properties.as_object().unwrap().contains_key("margin-top")); 44 } 45 46 #[cfg(windows)] 47 fn find_python() -> String { 48 if Command::new("python2.7.exe") 49 .arg("--version") 50 .output() 51 .is_ok() 52 { 53 return "python2.7.exe".to_owned(); 54 } 55 56 if Command::new("python27.exe") 57 .arg("--version") 58 .output() 59 .is_ok() 60 { 61 return "python27.exe".to_owned(); 62 } 63 64 if Command::new("python.exe").arg("--version").output().is_ok() { 65 return "python.exe".to_owned(); 66 } 67 68 panic!("Can't find python (tried python27.exe and python.exe)! Try fixing PATH or setting the PYTHON env var"); 69 } 70 71 #[cfg(not(windows))] 72 fn find_python() -> String { 73 if Command::new("python2.7") 74 .arg("--version") 75 .output() 76 .unwrap() 77 .status 78 .success() 79 { 80 "python2.7" 81 } else { 82 "python" 83 } 84 .to_owned() 85 }