mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Make mach test-unit
not recompile components after mach build
Previously, the `tests` feature flag of the `embedder_traits` crate caused it and every crate recursively depending on it to be built twice. This feature flag was used to provide a specific set of "resources" when running tests. Instead, this commits overrides the `main()` function of the test harness to change resources at runtime before running any test. This is done by adding a dependency that has `name = "test"` in its `[lib]` section of `Cargo.toml`. This overrides the crate found by `extern crate test;` in code generated by `rustc --test`.
This commit is contained in:
parent
76ddbe4d7a
commit
1f7ebfc8a2
17 changed files with 50 additions and 42 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -2316,6 +2316,7 @@ dependencies = [
|
||||||
"servo_channel 0.0.1",
|
"servo_channel 0.0.1",
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
"servo_url 0.0.1",
|
"servo_url 0.0.1",
|
||||||
|
"std_test_override 0.0.1",
|
||||||
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2355,6 +2356,7 @@ dependencies = [
|
||||||
"servo_arc 0.1.1",
|
"servo_arc 0.1.1",
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
"servo_url 0.0.1",
|
"servo_url 0.0.1",
|
||||||
|
"std_test_override 0.0.1",
|
||||||
"url 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"uuid 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uuid 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"webrender_api 0.57.2 (git+https://github.com/servo/webrender)",
|
"webrender_api 0.57.2 (git+https://github.com/servo/webrender)",
|
||||||
|
@ -3392,6 +3394,7 @@ dependencies = [
|
||||||
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_geometry 0.0.1",
|
"servo_geometry 0.0.1",
|
||||||
"servo_url 0.0.1",
|
"servo_url 0.0.1",
|
||||||
|
"std_test_override 0.0.1",
|
||||||
"url 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3525,6 +3528,13 @@ name = "stable_deref_trait"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "std_test_override"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"embedder_traits 0.0.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "string_cache"
|
name = "string_cache"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
|
@ -3647,6 +3657,7 @@ dependencies = [
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
"servo_url 0.0.1",
|
"servo_url 0.0.1",
|
||||||
"size_of_test 0.0.1",
|
"size_of_test 0.0.1",
|
||||||
|
"std_test_override 0.0.1",
|
||||||
"style 0.0.1",
|
"style 0.0.1",
|
||||||
"style_traits 0.0.1",
|
"style_traits 0.0.1",
|
||||||
]
|
]
|
||||||
|
|
|
@ -19,6 +19,3 @@ log = "0.4"
|
||||||
servo_config = {path = "../config"}
|
servo_config = {path = "../config"}
|
||||||
servo_rand = {path = "../rand"}
|
servo_rand = {path = "../rand"}
|
||||||
uuid = {version = "0.6", features = ["v4"]}
|
uuid = {version = "0.6", features = ["v4"]}
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"]}
|
|
||||||
|
|
|
@ -14,6 +14,3 @@ ipc-channel = "0.11"
|
||||||
regex = "1.0"
|
regex = "1.0"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
embedder_traits = { path = "../embedder_traits" }
|
embedder_traits = { path = "../embedder_traits" }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
|
||||||
|
|
|
@ -37,6 +37,3 @@ webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
toml = "0.4.5"
|
toml = "0.4.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"]}
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ url = "1.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.5"
|
env_logger = "0.5"
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
std_test_override = { path = "../std_test_override" }
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
dirs = "1.0"
|
dirs = "1.0"
|
||||||
|
|
|
@ -44,6 +44,3 @@ webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
||||||
[target.'cfg(all(not(target_os = "windows"), not(target_os = "ios")))'.dependencies]
|
[target.'cfg(all(not(target_os = "windows"), not(target_os = "ios")))'.dependencies]
|
||||||
gaol = {git = "https://github.com/servo/gaol"}
|
gaol = {git = "https://github.com/servo/gaol"}
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
|
||||||
|
|
|
@ -9,9 +9,6 @@ publish = false
|
||||||
name = "embedder_traits"
|
name = "embedder_traits"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
[features]
|
|
||||||
tests = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ipc-channel = "0.11"
|
ipc-channel = "0.11"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
|
|
|
@ -3,25 +3,21 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::RwLock;
|
use std::sync::{Once, RwLock};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RES: RwLock<Option<Box<ResourceReaderMethods + Sync + Send>>> = RwLock::new({
|
static ref RES: RwLock<Option<Box<ResourceReaderMethods + Sync + Send>>> = RwLock::new(None);
|
||||||
#[cfg(not(feature = "tests"))]
|
|
||||||
{
|
|
||||||
None
|
|
||||||
}
|
|
||||||
#[cfg(feature = "tests")]
|
|
||||||
{
|
|
||||||
Some(resources_for_tests())
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(reader: Box<ResourceReaderMethods + Sync + Send>) {
|
pub fn set(reader: Box<ResourceReaderMethods + Sync + Send>) {
|
||||||
*RES.write().unwrap() = Some(reader);
|
*RES.write().unwrap() = Some(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_for_tests() {
|
||||||
|
static ONCE: Once = Once::new();
|
||||||
|
ONCE.call_once(|| set(resources_for_tests()));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn read_bytes(res: Resource) -> Vec<u8> {
|
pub fn read_bytes(res: Resource) -> Vec<u8> {
|
||||||
RES.read()
|
RES.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -71,7 +67,6 @@ pub trait ResourceReaderMethods {
|
||||||
fn sandbox_access_files_dirs(&self) -> Vec<PathBuf>;
|
fn sandbox_access_files_dirs(&self) -> Vec<PathBuf>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tests")]
|
|
||||||
fn resources_for_tests() -> Box<ResourceReaderMethods + Sync + Send> {
|
fn resources_for_tests() -> Box<ResourceReaderMethods + Sync + Send> {
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
|
@ -53,6 +53,3 @@ servo_url = {path = "../url"}
|
||||||
style = {path = "../style"}
|
style = {path = "../style"}
|
||||||
style_traits = {path = "../style_traits"}
|
style_traits = {path = "../style_traits"}
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
ws = { version = "0.7", features = ["ssl"] }
|
ws = { version = "0.7", features = ["ssl"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
std_test_override = { path = "../std_test_override" }
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "main"
|
name = "main"
|
||||||
|
|
|
@ -33,4 +33,4 @@ uuid = {version = "0.6", features = ["v4", "serde"]}
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
std_test_override = { path = "../std_test_override" }
|
||||||
|
|
|
@ -109,6 +109,3 @@ webvr_traits = {path = "../webvr_traits"}
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "ios"))'.dependencies]
|
[target.'cfg(not(target_os = "ios"))'.dependencies]
|
||||||
mozangle = "0.1"
|
mozangle = "0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
|
||||||
|
|
|
@ -36,6 +36,3 @@ time = "0.1.12"
|
||||||
url = "1.2"
|
url = "1.2"
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
webvr_traits = {path = "../webvr_traits"}
|
webvr_traits = {path = "../webvr_traits"}
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"]}
|
|
||||||
|
|
|
@ -72,6 +72,3 @@ webvr_traits = {path = "../webvr_traits"}
|
||||||
|
|
||||||
[target.'cfg(all(not(target_os = "windows"), not(target_os = "ios")))'.dependencies]
|
[target.'cfg(all(not(target_os = "windows"), not(target_os = "ios")))'.dependencies]
|
||||||
gaol = {git = "https://github.com/servo/gaol"}
|
gaol = {git = "https://github.com/servo/gaol"}
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
embedder_traits = { path = "../embedder_traits", features = ["tests"] }
|
|
||||||
|
|
13
components/std_test_override/Cargo.toml
Normal file
13
components/std_test_override/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "std_test_override"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = ["The Servo Project Developers"]
|
||||||
|
license = "MPL-2.0"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "test"
|
||||||
|
path = "lib.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
embedder_traits = { path = "../embedder_traits" }
|
15
components/std_test_override/lib.rs
Normal file
15
components/std_test_override/lib.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#![feature(test)]
|
||||||
|
|
||||||
|
extern crate embedder_traits;
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
|
pub use test::*;
|
||||||
|
|
||||||
|
pub fn test_main_static(tests: &[&TestDescAndFn]) {
|
||||||
|
embedder_traits::resources::set_for_tests();
|
||||||
|
test::test_main_static(tests);
|
||||||
|
}
|
|
@ -26,3 +26,4 @@ servo_url = {path = "../../../components/url"}
|
||||||
size_of_test = {path = "../../../components/size_of_test"}
|
size_of_test = {path = "../../../components/size_of_test"}
|
||||||
style = {path = "../../../components/style"}
|
style = {path = "../../../components/style"}
|
||||||
style_traits = {path = "../../../components/style_traits"}
|
style_traits = {path = "../../../components/style_traits"}
|
||||||
|
std_test_override = { path = "../../../components/std_test_override" }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue