mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01: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
|
@ -3,25 +3,21 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::{Once, RwLock};
|
||||
|
||||
lazy_static! {
|
||||
static ref RES: RwLock<Option<Box<ResourceReaderMethods + Sync + Send>>> = RwLock::new({
|
||||
#[cfg(not(feature = "tests"))]
|
||||
{
|
||||
None
|
||||
}
|
||||
#[cfg(feature = "tests")]
|
||||
{
|
||||
Some(resources_for_tests())
|
||||
}
|
||||
});
|
||||
static ref RES: RwLock<Option<Box<ResourceReaderMethods + Sync + Send>>> = RwLock::new(None);
|
||||
}
|
||||
|
||||
pub fn set(reader: Box<ResourceReaderMethods + Sync + Send>) {
|
||||
*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> {
|
||||
RES.read()
|
||||
.unwrap()
|
||||
|
@ -71,7 +67,6 @@ pub trait ResourceReaderMethods {
|
|||
fn sandbox_access_files_dirs(&self) -> Vec<PathBuf>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "tests")]
|
||||
fn resources_for_tests() -> Box<ResourceReaderMethods + Sync + Send> {
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue