From c615a0dabc8828a6c63af83746c428c3d2bb0b7e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 20 Sep 2016 20:22:36 +0530 Subject: [PATCH 1/2] Add unit test crate for stylo --- ports/geckolib/Cargo.lock | 12 ++++++++++++ ports/geckolib/Cargo.toml | 3 +++ python/servo/testing_commands.py | 22 +++++++++++++++++++++- tests/unit/stylo/Cargo.toml | 16 ++++++++++++++++ tests/unit/stylo/lib.rs | 10 ++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/unit/stylo/Cargo.toml create mode 100644 tests/unit/stylo/lib.rs diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock index dd84fdf5284..4bb97da9835 100644 --- a/ports/geckolib/Cargo.lock +++ b/ports/geckolib/Cargo.lock @@ -14,6 +14,7 @@ dependencies = [ "selectors 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "style_traits 0.0.1", + "stylo_tests 0.0.1", "url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -52,6 +53,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -393,6 +395,16 @@ dependencies = [ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "stylo_tests" +version = "0.0.1" +dependencies = [ + "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "style 0.0.1", + "style_traits 0.0.1", +] + [[package]] name = "thread-id" version = "2.0.0" diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index bcf38096e85..604411df56b 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -23,3 +23,6 @@ selectors = "0.13" style = {path = "../../components/style", features = ["gecko"]} style_traits = {path = "../../components/style_traits"} url = "1.2" + +[dev-dependencies] +stylo_tests = {path = "../../tests/unit/stylo"} \ No newline at end of file diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 97bf8635190..7e146afc055 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -25,7 +25,7 @@ from mach.decorators import ( Command, ) -from servo.command_base import CommandBase, call, check_call, host_triple +from servo.command_base import CommandBase, call, cd, check_call, host_triple from wptrunner import wptcommandline from update import updatecommandline from servo_tidy import tidy @@ -232,6 +232,26 @@ class MachCommands(CommandBase): if result != 0: return result + @Command('test-stylo', + description='Run stylo unit tests', + category='testing') + def test_unit(self, test_name=None, package=None): + if test_name is None: + test_name = [] + + self.set_use_stable_rust() + self.ensure_bootstrapped() + + env = self.build_env() + env["RUST_BACKTRACE"] = "1" + env["CARGO_TARGET_DIR"] = path.join(self.context.topdir, "target", "geckolib").encode("UTF-8") + + with cd(path.join("ports", "geckolib")): + result = call(["cargo", "test", "-p", "stylo_tests"], env=env) + + if result != 0: + return result + @Command('test-compiletest', description='Run compiletests', category='testing') diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml new file mode 100644 index 00000000000..e64d2de3c2b --- /dev/null +++ b/tests/unit/stylo/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "stylo_tests" +version = "0.0.1" +authors = ["The Servo Project Developers"] +license = "MPL-2.0" + +[lib] +name = "stylo_tests" +path = "lib.rs" +doctest = false + +[dependencies] +app_units = "0.3" +cssparser = {version = "0.7", features = ["heap_size"]} +style = {path = "../../../components/style", features = ["gecko"]} +style_traits = {path = "../../../components/style_traits"} diff --git a/tests/unit/stylo/lib.rs b/tests/unit/stylo/lib.rs new file mode 100644 index 00000000000..3af0f5c54ee --- /dev/null +++ b/tests/unit/stylo/lib.rs @@ -0,0 +1,10 @@ +extern crate app_units; +extern crate cssparser; +extern crate style; +extern crate style_traits; + +#[test] +fn test_test() { + // do nothing + // this is a temporary test testing that the test runs +} \ No newline at end of file From 1d497828a76ae0739463ef6a196fa4b98b06173c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 20 Sep 2016 20:38:16 +0530 Subject: [PATCH 2/2] Move sanity checks to stylo tests --- ports/geckolib/Cargo.lock | 1 + ports/geckolib/Cargo.toml | 2 +- ports/geckolib/lib.rs | 1 - python/servo/testing_commands.py | 7 +++---- tests/unit/stylo/Cargo.toml | 1 + tests/unit/stylo/lib.rs | 11 ++++++----- {ports/geckolib => tests/unit/stylo}/sanity_checks.rs | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) rename {ports/geckolib => tests/unit/stylo}/sanity_checks.rs (96%) diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock index 4bb97da9835..8581961e329 100644 --- a/ports/geckolib/Cargo.lock +++ b/ports/geckolib/Cargo.lock @@ -401,6 +401,7 @@ version = "0.0.1" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gecko_bindings 0.0.1", "style 0.0.1", "style_traits 0.0.1", ] diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index 604411df56b..7a6b83d1e18 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -25,4 +25,4 @@ style_traits = {path = "../../components/style_traits"} url = "1.2" [dev-dependencies] -stylo_tests = {path = "../../tests/unit/stylo"} \ No newline at end of file +stylo_tests = {path = "../../tests/unit/stylo"} diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index 7bfea1b9bcd..337332c4da8 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -22,7 +22,6 @@ mod snapshot; mod snapshot_helpers; #[allow(non_snake_case)] pub mod glue; -mod sanity_checks; mod traversal; mod wrapper; diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 7e146afc055..a3206b745f3 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -208,6 +208,8 @@ class MachCommands(CommandBase): if not packages: packages = set(os.listdir(path.join(self.context.topdir, "tests", "unit"))) + packages.remove('stylo') + args = ["cargo", "test"] for crate in packages: args += ["-p", "%s_tests" % crate] @@ -235,10 +237,7 @@ class MachCommands(CommandBase): @Command('test-stylo', description='Run stylo unit tests', category='testing') - def test_unit(self, test_name=None, package=None): - if test_name is None: - test_name = [] - + def test_stylo(self): self.set_use_stable_rust() self.ensure_bootstrapped() diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml index e64d2de3c2b..7989417eb8b 100644 --- a/tests/unit/stylo/Cargo.toml +++ b/tests/unit/stylo/Cargo.toml @@ -12,5 +12,6 @@ doctest = false [dependencies] app_units = "0.3" cssparser = {version = "0.7", features = ["heap_size"]} +gecko_bindings = {path = "../../../ports/geckolib/gecko_bindings"} style = {path = "../../../components/style", features = ["gecko"]} style_traits = {path = "../../../components/style_traits"} diff --git a/tests/unit/stylo/lib.rs b/tests/unit/stylo/lib.rs index 3af0f5c54ee..62e96c3588f 100644 --- a/tests/unit/stylo/lib.rs +++ b/tests/unit/stylo/lib.rs @@ -1,10 +1,11 @@ +/* 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/. */ + extern crate app_units; extern crate cssparser; +extern crate gecko_bindings; extern crate style; extern crate style_traits; -#[test] -fn test_test() { - // do nothing - // this is a temporary test testing that the test runs -} \ No newline at end of file +mod sanity_checks; diff --git a/ports/geckolib/sanity_checks.rs b/tests/unit/stylo/sanity_checks.rs similarity index 96% rename from ports/geckolib/sanity_checks.rs rename to tests/unit/stylo/sanity_checks.rs index 8809b6a644a..74890856f80 100644 --- a/ports/geckolib/sanity_checks.rs +++ b/tests/unit/stylo/sanity_checks.rs @@ -62,7 +62,7 @@ fn assert_basic_pseudo_elements() { }; } - include!("../../components/style/generated/gecko_pseudo_element_helper.rs"); + include!("../../../components/style/generated/gecko_pseudo_element_helper.rs"); assert!(saw_before); assert!(saw_after);