diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 21b1955664d..a984dcf45a4 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -8,18 +8,22 @@ dependencies = [ "devtools 0.0.1", "devtools_traits 0.0.1", "gfx 0.0.1", + "gfx_tests 0.0.1", "glutin_app 0.0.1", "layout 0.0.1", "msg 0.0.1", "net 0.0.1", + "net_tests 0.0.1", "net_traits 0.0.1", "png 0.1.0 (git+https://github.com/servo/rust-png)", "profile 0.0.1", "script 0.0.1", + "script_tests 0.0.1", + "style_tests 0.0.1", "time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", - "unit_tests 0.0.1", "url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)", "util 0.0.1", + "util_tests 0.0.1", "webdriver_server 0.0.1", ] @@ -346,6 +350,13 @@ dependencies = [ "util 0.0.1", ] +[[package]] +name = "gfx_tests" +version = "0.0.1" +dependencies = [ + "gfx 0.0.1", +] + [[package]] name = "gl_common" version = "0.0.4" @@ -661,6 +672,19 @@ dependencies = [ "util 0.0.1", ] +[[package]] +name = "net_tests" +version = "0.0.1" +dependencies = [ + "cookie 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "net 0.0.1", + "net_traits 0.0.1", + "profile 0.0.1", + "url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)", + "util 0.0.1", +] + [[package]] name = "net_traits" version = "0.0.1" @@ -824,6 +848,13 @@ dependencies = [ "uuid 0.1.11 (git+https://github.com/rust-lang/uuid)", ] +[[package]] +name = "script_tests" +version = "0.0.1" +dependencies = [ + "script 0.0.1", +] + [[package]] name = "script_traits" version = "0.0.1" @@ -905,6 +936,20 @@ dependencies = [ "util 0.0.1", ] +[[package]] +name = "style_tests" +version = "0.0.1" +dependencies = [ + "cssparser 0.2.0 (git+https://github.com/servo/rust-cssparser)", + "geom 0.1.0 (git+https://github.com/servo/rust-geom)", + "selectors 0.1.0 (git+https://github.com/servo/rust-selectors)", + "string_cache 0.0.0 (git+https://github.com/servo/string-cache)", + "string_cache_plugin 0.0.0 (git+https://github.com/servo/string-cache)", + "style 0.0.1", + "url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)", + "util 0.0.1", +] + [[package]] name = "task_info" version = "0.0.1" @@ -928,27 +973,6 @@ name = "unicase" version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unit_tests" -version = "0.0.1" -dependencies = [ - "cookie 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.2.0 (git+https://github.com/servo/rust-cssparser)", - "geom 0.1.0 (git+https://github.com/servo/rust-geom)", - "gfx 0.0.1", - "hyper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "net 0.0.1", - "net_traits 0.0.1", - "profile 0.0.1", - "script 0.0.1", - "selectors 0.1.0 (git+https://github.com/servo/rust-selectors)", - "string_cache 0.0.0 (git+https://github.com/servo/string-cache)", - "string_cache_plugin 0.0.0 (git+https://github.com/servo/string-cache)", - "style 0.0.1", - "url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)", - "util 0.0.1", -] - [[package]] name = "url" version = "0.2.23" @@ -987,6 +1011,14 @@ dependencies = [ "time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "util_tests" +version = "0.0.1" +dependencies = [ + "geom 0.1.0 (git+https://github.com/servo/rust-geom)", + "util 0.0.1", +] + [[package]] name = "uuid" version = "0.1.11" diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index f8d3fa3aa3e..24ab504b303 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -16,8 +16,20 @@ test = false doc = false bench = false -[dev-dependencies.unit_tests] -path = "../../tests/unit" +[dev-dependencies.gfx_tests] +path = "../../tests/unit/gfx" + +[dev-dependencies.net_tests] +path = "../../tests/unit/net" + +[dev-dependencies.script_tests] +path = "../../tests/unit/script" + +[dev-dependencies.style_tests] +path = "../../tests/unit/style" + +[dev-dependencies.util_tests] +path = "../../tests/unit/util" [[test]] name = "reftest" diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index b93d3689700..81361b0081f 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -101,17 +101,26 @@ 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") - def test_unit(self, test_name=None, component=None, package=None): + def test_unit(self, test_name=None, package=None): if test_name is None: test_name = [] self.ensure_bootstrapped() - return 0 != subprocess.call( - ["cargo", "test", "-p", "unit_tests"] - + test_name, env=self.build_env(), cwd=self.servo_crate()) + if package: + packages = [package] + else: + packages = os.listdir(path.join(self.context.topdir, "tests", "unit")) + + for crate in packages: + result = subprocess.call( + ["cargo", "test", "-p", "%s_tests" % crate] + test_name, + env=self.build_env(), cwd=self.servo_crate()) + if result != 0: + return result @Command('test-ref', description='Run the reference tests', diff --git a/tests/unit/gfx/Cargo.toml b/tests/unit/gfx/Cargo.toml new file mode 100644 index 00000000000..24e43ff3def --- /dev/null +++ b/tests/unit/gfx/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "gfx_tests" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "gfx_tests" +path = "lib.rs" +doctest = false + +[dependencies.gfx] +path = "../../../components/gfx" diff --git a/tests/unit/gfx/mod.rs b/tests/unit/gfx/lib.rs similarity index 81% rename from tests/unit/gfx/mod.rs rename to tests/unit/gfx/lib.rs index 4d160f2a8dc..9a5040b6fe1 100644 --- a/tests/unit/gfx/mod.rs +++ b/tests/unit/gfx/lib.rs @@ -2,4 +2,6 @@ * 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/. */ -mod text_util; +extern crate gfx; + +#[cfg(test)] mod text_util; diff --git a/tests/unit/net/Cargo.toml b/tests/unit/net/Cargo.toml new file mode 100644 index 00000000000..390d6f8ba01 --- /dev/null +++ b/tests/unit/net/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "net_tests" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "net_tests" +path = "lib.rs" +doctest = false + +[dependencies.net] +path = "../../../components/net" + +[dependencies.net_traits] +path = "../../../components/net_traits" + +[dependencies.profile] +path = "../../../components/profile" + +[dependencies.util] +path = "../../../components/util" + +[dependencies] +cookie = "*" +hyper = "*" +url = "*" diff --git a/tests/unit/net/lib.rs b/tests/unit/net/lib.rs new file mode 100644 index 00000000000..d38edca2617 --- /dev/null +++ b/tests/unit/net/lib.rs @@ -0,0 +1,17 @@ +/* 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/. */ + +#![cfg_attr(test, feature(net, alloc, path, io))] + +extern crate net; +extern crate net_traits; +extern crate profile; +extern crate url; +extern crate util; + +#[cfg(test)] mod cookie; +#[cfg(test)] mod data_loader; +#[cfg(test)] mod image_cache_task; +#[cfg(test)] mod mime_classifier; +#[cfg(test)] mod resource_task; diff --git a/tests/unit/net/mime_classifier.rs b/tests/unit/net/mime_classifier.rs index e56e76d1cb3..8bba57290c5 100644 --- a/tests/unit/net/mime_classifier.rs +++ b/tests/unit/net/mime_classifier.rs @@ -23,7 +23,7 @@ fn read_file(path: &path::Path) -> io::Result> { fn test_sniff_mp4_matcher() { let matcher = Mp4Matcher; - let p = PathBuf::new("../../tests/unit/net/parsable_mime/video/mp4/test.mp4"); + let p = PathBuf::new("parsable_mime/video/mp4/test.mp4"); let read_result = read_file(&p); match read_result { @@ -43,7 +43,7 @@ fn test_sniff_full(filename_orig: &path::Path,type_string: &str,subtype_string: let current_working_directory = env::current_dir().unwrap(); println!("The current directory is {}", current_working_directory.display()); - let mut filename = PathBuf::new("../../tests/unit/net/parsable_mime/"); + let mut filename = PathBuf::new("parsable_mime/"); filename.push(filename_orig); let classifier = MIMEClassifier::new(); diff --git a/tests/unit/net/mod.rs b/tests/unit/net/mod.rs deleted file mode 100644 index 0d304270422..00000000000 --- a/tests/unit/net/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -/* 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/. */ - -mod cookie; -mod data_loader; -mod image_cache_task; -mod mime_classifier; -mod resource_task; diff --git a/tests/unit/script/Cargo.toml b/tests/unit/script/Cargo.toml new file mode 100644 index 00000000000..759e0581545 --- /dev/null +++ b/tests/unit/script/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "script_tests" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "script_tests" +path = "lib.rs" +doctest = false + +[dependencies.script] +path = "../../../components/script" diff --git a/tests/unit/script/mod.rs b/tests/unit/script/lib.rs similarity index 65% rename from tests/unit/script/mod.rs rename to tests/unit/script/lib.rs index 1631a9adc8c..3073fcb8588 100644 --- a/tests/unit/script/mod.rs +++ b/tests/unit/script/lib.rs @@ -2,5 +2,7 @@ * 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/. */ -#[cfg(target_pointer_width = "64")] mod size_of; -mod textinput; +extern crate script; + +#[cfg(all(test, target_pointer_width = "64"))] mod size_of; +#[cfg(test)] mod textinput; diff --git a/tests/unit/Cargo.toml b/tests/unit/style/Cargo.toml similarity index 57% rename from tests/unit/Cargo.toml rename to tests/unit/style/Cargo.toml index 3c3c80a3e4b..64e34f2bd03 100644 --- a/tests/unit/Cargo.toml +++ b/tests/unit/style/Cargo.toml @@ -1,50 +1,33 @@ [package] -name = "unit_tests" +name = "style_tests" version = "0.0.1" authors = ["The Servo Project Developers"] [lib] -name = "unit_tests" +name = "style_tests" path = "lib.rs" doctest = false -[dependencies.util] -path = "../../components/util" - -[dependencies.gfx] -path = "../../components/gfx" - -[dependencies.net] -path = "../../components/net" - -[dependencies.net_traits] -path = "../../components/net_traits" - -[dependencies.profile] -path = "../../components/profile" - [dependencies.style] -path = "../../components/style" +path = "../../../components/style" -[dependencies.script] -path = "../../components/script" - -[dependencies.geom] -git = "https://github.com/servo/rust-geom" - -[dependencies.cssparser] -git = "https://github.com/servo/rust-cssparser" - -[dependencies.selectors] -git = "https://github.com/servo/rust-selectors" - -[dependencies.string_cache] -git = "https://github.com/servo/string-cache" +[dependencies.util] +path = "../../../components/util" [dependencies.string_cache_plugin] git = "https://github.com/servo/string-cache" +[dependencies.string_cache] +git = "https://github.com/servo/string-cache" + +[dependencies.geom] +git = "https://github.com/servo/rust-geom" + +[dependencies.selectors] +git = "https://github.com/servo/rust-selectors" + +[dependencies.cssparser] +git = "https://github.com/servo/rust-cssparser" + [dependencies] -cookie = "*" url = "*" -hyper = "0.3" diff --git a/tests/unit/lib.rs b/tests/unit/style/lib.rs similarity index 50% rename from tests/unit/lib.rs rename to tests/unit/style/lib.rs index 05542a17840..9e379d1336b 100644 --- a/tests/unit/lib.rs +++ b/tests/unit/style/lib.rs @@ -3,25 +3,26 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #![feature(plugin)] -#![cfg_attr(test, feature(net, alloc, path, io))] - #![plugin(string_cache_plugin)] extern crate cssparser; extern crate geom; -extern crate gfx; -extern crate net; -extern crate net_traits; -extern crate profile; -extern crate script; extern crate selectors; extern crate string_cache; extern crate style; -extern crate util; extern crate url; +extern crate util; -#[cfg(test)] #[path="gfx/mod.rs"] mod gfx_tests; -#[cfg(test)] #[path="net/mod.rs"] mod net_tests; -#[cfg(test)] #[path="script/mod.rs"] mod script_tests; -#[cfg(test)] #[path="style/mod.rs"] mod style_tests; -#[cfg(test)] #[path="util/mod.rs"] mod util_tests; + +#[cfg(test)] mod stylesheets; +#[cfg(test)] mod media_queries; + +#[cfg(test)] mod writing_modes { + use util::logical_geometry::WritingMode; + use style::properties::{INITIAL_VALUES, get_writing_mode}; + + #[test] + fn initial_writing_mode_is_empty() { + assert_eq!(get_writing_mode(INITIAL_VALUES.get_inheritedbox()), WritingMode::empty()) + } +} diff --git a/tests/unit/style/mod.rs b/tests/unit/style/mod.rs deleted file mode 100644 index a2af201f7c3..00000000000 --- a/tests/unit/style/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -/* 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 util::logical_geometry::WritingMode; -use style::properties::{INITIAL_VALUES, get_writing_mode}; - - -mod stylesheets; -mod media_queries; - - -#[test] -fn initial_writing_mode_is_empty() { - assert_eq!(get_writing_mode(INITIAL_VALUES.get_inheritedbox()), WritingMode::empty()) -} diff --git a/tests/unit/util/Cargo.toml b/tests/unit/util/Cargo.toml new file mode 100644 index 00000000000..48df1b5aedb --- /dev/null +++ b/tests/unit/util/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "util_tests" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "util_tests" +path = "lib.rs" +doctest = false + +[dependencies.util] +path = "../../../components/util" + +[dependencies.geom] +git = "https://github.com/servo/rust-geom" diff --git a/tests/unit/util/mod.rs b/tests/unit/util/lib.rs similarity index 59% rename from tests/unit/util/mod.rs rename to tests/unit/util/lib.rs index 756af732b67..07ce741d972 100644 --- a/tests/unit/util/mod.rs +++ b/tests/unit/util/lib.rs @@ -2,7 +2,10 @@ * 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/. */ -mod cache; -mod logical_geometry; -mod task; -mod vec; +extern crate util; +extern crate geom; + +#[cfg(test)] mod cache; +#[cfg(test)] mod logical_geometry; +#[cfg(test)] mod task; +#[cfg(test)] mod vec;