Auto merge of #16655 - servo:jdm-patch-1, r=emilio

Fix broken unit tests

These are tests that only get run on TravisCI, apparently, so they were broken by be0139ff3c and 32c624e585 without anybody noticing.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16655)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-05-03 09:47:44 -05:00 committed by GitHub
commit 3905b5af18
6 changed files with 53 additions and 28 deletions

View file

@ -22,7 +22,7 @@ matrix:
- bash etc/ci/lockfile_changed.sh
- bash etc/ci/manifest_changed.sh
- ./mach cargo test -p selectors
- ./mach cargo test -p style
- ./mach test-unit -p style
cache:
directories:
- .cargo

View file

@ -14,6 +14,8 @@ license = "MPL-2.0"
[lib]
name = "selectors"
path = "lib.rs"
# https://github.com/servo/servo/issues/16710
doctest = false
[dependencies]
bitflags = "0.7"

View file

@ -431,8 +431,11 @@ fn combinator_to_restyle_hint(combinator: Option<Combinator>) -> RestyleHint {
#[derive(Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
struct Sensitivities {
/// The aspects of an selector which are sensitive.
pub struct Sensitivities {
/// The states which are sensitive.
pub states: ElementState,
/// Whether attributes are sensitive.
pub attrs: bool,
}
@ -469,11 +472,13 @@ impl Sensitivities {
/// change may have on the style of elements in the document.
#[derive(Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
struct Dependency {
pub struct Dependency {
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
selector: SelectorInner<SelectorImpl>,
hint: RestyleHint,
sensitivities: Sensitivities,
/// The hint associated with this dependency.
pub hint: RestyleHint,
/// The sensitivities associated with this dependency.
pub sensitivities: Sensitivities,
}
@ -681,27 +686,9 @@ impl DependencySet {
}
}
}
}
#[test]
#[cfg(all(test, feature = "servo"))]
fn smoke_restyle_hints() {
use cssparser::Parser;
use selector_parser::SelectorParser;
use stylesheets::{Origin, Namespaces};
let namespaces = Namespaces::default();
let parser = SelectorParser {
stylesheet_origin: Origin::Author,
namespaces: &namespaces,
};
let mut dependencies = DependencySet::new();
let mut p = Parser::new(":not(:active) ~ label");
let selector = ComplexSelector::parse(&parser, &mut p).unwrap();
dependencies.note_selector(&selector);
assert_eq!(dependencies.len(), 1);
assert_eq!(dependencies.state_deps.len(), 1);
assert!(!dependencies.state_deps[0].sensitivities.states.is_empty());
assert!(dependencies.state_deps[0].hint.contains(RESTYLE_LATER_SIBLINGS));
/// Get the dependencies affected by state.
pub fn get_state_deps(&self) -> &[Dependency] {
&self.state_deps
}
}

View file

@ -231,8 +231,10 @@ class MachCommands(CommandBase):
else:
test_patterns.append(test)
in_crate_packages = []
if not packages:
packages = set(os.listdir(path.join(self.context.topdir, "tests", "unit"))) - set(['.DS_Store'])
in_crate_packages += ["selectors"]
packages.discard('stylo')
@ -255,6 +257,8 @@ class MachCommands(CommandBase):
args = ["cargo", "bench" if bench else "test"]
for crate in packages:
args += ["-p", "%s_tests" % crate]
for crate in in_crate_packages:
args += ["-p", crate]
args += test_patterns
if features:

View file

@ -27,6 +27,7 @@ mod logical_geometry;
mod media_queries;
mod parsing;
mod properties;
mod restyle_hints;
mod rule_tree;
mod size_of;
mod str;

View file

@ -0,0 +1,31 @@
/* 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/. */
#[test]
fn smoke_restyle_hints() {
use cssparser::Parser;
use selectors::parser::SelectorList;
use style::restyle_hints::{DependencySet, RESTYLE_LATER_SIBLINGS};
use style::selector_parser::SelectorParser;
use style::stylesheets::{Origin, Namespaces};
let namespaces = Namespaces::default();
let parser = SelectorParser {
stylesheet_origin: Origin::Author,
namespaces: &namespaces,
};
let mut dependencies = DependencySet::new();
let mut p = Parser::new(":not(:active) ~ label");
let selectors = SelectorList::parse(&parser, &mut p).unwrap();
assert_eq!((selectors.0).len(), 1);
let selector = (selectors.0).first().unwrap();
dependencies.note_selector(selector);
assert_eq!(dependencies.len(), 1);
let state_deps = dependencies.get_state_deps();
assert_eq!(state_deps.len(), 1);
assert!(!state_deps[0].sensitivities.states.is_empty());
assert!(state_deps[0].hint.contains(RESTYLE_LATER_SIBLINGS));
}