servo: Merge #10855 - Make css-properties.json checking a proper unit test (from servo:unit); r=nox
authorSimon Sapin <simon.sapin@exyr.org>
Thu, 28 Apr 2016 07:16:57 -0700
changeset 338651 8ca048b2f6cc2ee151fc4ac825f1e676b308e60e
parent 338650 8ae346b2cc146dfc0e5551d997443d7efdc9b9a4
child 338652 8d84ca13b2932cb4a2b106ad33b9d5d99268e082
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
servo: Merge #10855 - Make css-properties.json checking a proper unit test (from servo:unit); r=nox Source-Repo: https://github.com/servo/servo Source-Revision: 55d14ffe001189a648c79512753fb9260a4b4c5d
servo/components/servo/Cargo.lock
servo/python/servo/testing_commands.py
servo/tests/unit/style/Cargo.toml
servo/tests/unit/style/lib.rs
servo/tests/unit/style/properties.rs
--- a/servo/components/servo/Cargo.lock
+++ b/servo/components/servo/Cargo.lock
@@ -2099,16 +2099,17 @@ dependencies = [
 name = "style_tests"
 version = "0.0.1"
 dependencies = [
  "app_units 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "cssparser 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "msg 0.0.1",
  "plugins 0.0.1",
+ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
  "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
  "style 0.0.1",
  "style_traits 0.0.1",
  "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "util 0.0.1",
 ]
 
--- a/servo/python/servo/testing_commands.py
+++ b/servo/python/servo/testing_commands.py
@@ -9,18 +9,16 @@
 
 from __future__ import print_function, unicode_literals
 
 import argparse
 import re
 import sys
 import os
 import os.path as path
-import subprocess
-import json
 from collections import OrderedDict
 from time import time
 
 from mach.registrar import Registrar
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
@@ -136,18 +134,16 @@ class MachCommands(CommandBase):
 
     @Command('test-unit',
              description='Run unit tests',
              category='testing')
     @CommandArgument('--package', '-p', default=None, help="Specific package to test")
     @CommandArgument('test_name', nargs=argparse.REMAINDER,
                      help="Only run tests that match this pattern or file path")
     def test_unit(self, test_name=None, package=None):
-        check_css_properties_json(self.context.topdir)
-
         if test_name is None:
             test_name = []
 
         self.ensure_bootstrapped()
 
         if package:
             packages = {package}
         else:
@@ -652,28 +648,8 @@ testing/web-platform/mozilla/tests for S
             if kwargs["release"]:
                 args.append("--release")
             args.append(test_path)
             wpt_kwargs = vars(p.parse_args(args))
             self.context.commands.dispatch("test-wpt", self.context, **wpt_kwargs)
 
         if editor:
             proc.wait()
-
-
-def check_css_properties_json(topdir):
-    print("Testing generation of css-properties.json...")
-    filename = path.join(topdir, "target", "doc", "servo", "css-properties.json")
-
-    if path.exists(filename):
-        os.remove(filename)
-    subprocess.check_call([
-        sys.executable,
-        path.join(topdir, "components", "style", "properties", "build.py"),
-        "servo",
-        "html",
-    ])
-    properties = json.load(open(filename))
-
-    assert len(properties) >= 100
-    assert "margin-top" in properties
-    assert "margin" in properties
-    print("OK")
--- a/servo/tests/unit/style/Cargo.toml
+++ b/servo/tests/unit/style/Cargo.toml
@@ -15,8 +15,9 @@ style = {path = "../../../components/sty
 style_traits = {path = "../../../components/style_traits"}
 util = {path = "../../../components/util"}
 app_units = {version = "0.2.3", features = ["plugins"]}
 cssparser = {version = "0.5.4", features = ["heap_size"]}
 euclid = {version = "0.6.4", features = ["plugins"]}
 selectors = {version = "0.5", features = ["heap_size"]}
 string_cache = {version = "0.2.12", features = ["heap_size"]}
 url = {version = "1.0.0", features = ["heap_size"]}
+rustc-serialize = "0.3"
--- a/servo/tests/unit/style/lib.rs
+++ b/servo/tests/unit/style/lib.rs
@@ -5,26 +5,28 @@
 #![feature(plugin)]
 #![cfg_attr(test, feature(core_intrinsics))]
 #![plugin(plugins)]
 
 extern crate app_units;
 extern crate cssparser;
 extern crate euclid;
 extern crate msg;
+extern crate rustc_serialize;
 extern crate selectors;
 #[macro_use(atom, ns)] extern crate string_cache;
 extern crate style;
 extern crate style_traits;
 extern crate url;
 extern crate util;
 
 #[cfg(test)] mod attr;
 #[cfg(test)] mod logical_geometry;
 #[cfg(test)] mod media_queries;
+#[cfg(test)] mod properties;
 #[cfg(test)] mod stylesheets;
 #[cfg(test)] mod viewport;
 
 #[cfg(test)] mod writing_modes {
     use style::logical_geometry::WritingMode;
     use style::properties::{INITIAL_SERVO_VALUES, ComputedValues, get_writing_mode};
 
     #[test]
new file mode 100644
--- /dev/null
+++ b/servo/tests/unit/style/properties.rs
@@ -0,0 +1,53 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use rustc_serialize::json::Json;
+use std::env;
+use std::fs::{File, remove_file};
+use std::path::Path;
+use std::process::Command;
+
+#[test]
+fn properties_list_json() {
+    let top = Path::new(file!()).parent().unwrap().join("..").join("..").join("..");
+    let json = top.join("target").join("doc").join("servo").join("css-properties.json");
+    if json.exists() {
+        remove_file(&json).unwrap()
+    }
+    let python = env::var("PYTHON").ok().unwrap_or_else(find_python);
+    let script = top.join("components").join("style").join("properties").join("build.py");
+    let status = Command::new(python)
+        .arg(&script)
+        .arg("servo")
+        .arg("html")
+        .status()
+        .unwrap();
+    assert!(status.success());
+    let properties = Json::from_reader(&mut File::open(json).unwrap()).unwrap();
+    assert!(properties.as_object().unwrap().len() > 100);
+    assert!(properties.find("margin").is_some());
+    assert!(properties.find("margin-top").is_some());
+}
+
+#[cfg(windows)]
+fn find_python() -> String {
+    if Command::new("python27.exe").arg("--version").output().is_ok() {
+        return "python27.exe".to_owned();
+    }
+
+    if Command::new("python.exe").arg("--version").output().is_ok() {
+        return "python.exe".to_owned();
+    }
+
+    panic!("Can't find python (tried python27.exe and python.exe)! Try fixing PATH or setting the PYTHON env var");
+}
+
+#[cfg(not(windows))]
+fn find_python() -> String {
+    if Command::new("python2.7").arg("--version").output().unwrap().status.success() {
+        "python2.7"
+    } else {
+        "python"
+    }.to_owned()
+}