Skip to content

Commit

Permalink
Auto merge of #16655 - servo:jdm-patch-1, r=emilio
Browse files Browse the repository at this point in the history
Fix broken unit tests

These are tests that only get run on TravisCI, apparently, so they were broken by be0139f and 32c624e 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 -->
  • Loading branch information
bors-servo committed May 3, 2017
2 parents 8b41c7c + f3f9e28 commit 3905b5a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions components/selectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 13 additions & 26 deletions components/style/restyle_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}


Expand Down Expand Up @@ -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
}
}
4 changes: 4 additions & 0 deletions python/servo/testing_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ def test_unit(self, test_name=None, package=None, bench=False, nocapture=False):
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')

Expand All @@ -255,6 +257,8 @@ def test_unit(self, test_name=None, package=None, bench=False, nocapture=False):
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:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/style/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/style/restyle_hints.rs
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit 3905b5a

Please sign in to comment.