Skip to content

Commit

Permalink
Fix up and run unit tests.
Browse files Browse the repository at this point in the history
This adds the subpackages to `./mach test-unit`.
  • Loading branch information
metajack committed Oct 3, 2014
1 parent 76d1d78 commit 7f6f072
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
3 changes: 2 additions & 1 deletion components/style/selector_matching.rs
Expand Up @@ -999,6 +999,7 @@ mod tests {
use sync::Arc;
use super::{DeclarationBlock, Rule, SelectorMap};
use selectors::LocalName;
use string_cache::Atom;

/// Helper method to get some Rules from selector strings.
/// Each sublist of the result contains the Rules for one StyleRule.
Expand Down Expand Up @@ -1043,7 +1044,7 @@ mod tests {
fn test_get_class_name(){
let rules_list = get_mock_rules([".intro.foo", "#top"]);
assert_eq!(SelectorMap::get_class_name(&rules_list[0][0]), Some(Atom::from_slice("intro")));
assert_eq!(SelectorMap::get_class_name(rules_list.get(1).get(0)), None);
assert_eq!(SelectorMap::get_class_name(&rules_list[1][0]), None);
}

#[test]
Expand Down
9 changes: 5 additions & 4 deletions components/style/selectors.rs
Expand Up @@ -574,6 +574,7 @@ mod tests {
use sync::Arc;
use cssparser;
use namespaces::NamespaceMap;
use string_cache::Atom;
use super::*;

fn parse(input: &str) -> Result<Vec<Selector>, ()> {
Expand Down Expand Up @@ -649,8 +650,8 @@ mod tests {
assert!(parse_ns("[Foo]", &namespaces) == Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(AttrExists(AttrSelector {
name: Atom::from_slice("Foo"),
lower_name: Atom::from_slice("foo"),
name: String::from_str("Foo"),
lower_name: String::from_str("foo"),
namespace: SpecificNamespace(ns!("")),
})),
next: None,
Expand All @@ -664,8 +665,8 @@ mod tests {
assert!(parse_ns("[Foo]", &namespaces) == Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(AttrExists(AttrSelector {
name: Atom::from_slice("Foo"),
lower_name: Atom::from_slice("foo"),
name: String::from_str("Foo"),
lower_name: String::from_str("foo"),
namespace: SpecificNamespace(ns!("")),
})),
next: None,
Expand Down
8 changes: 4 additions & 4 deletions components/util/smallvec.rs
Expand Up @@ -498,7 +498,7 @@ pub mod tests {
let mut v = SmallVec16::new();
v.push("hello".to_string());
v.push("there".to_string());
assert_eq!(v.as_slice(), &["hello".to_string(), "there".to_string()]);
assert_eq!(v.as_slice(), vec!["hello".to_string(), "there".to_string()].as_slice());
}

#[test]
Expand All @@ -508,7 +508,7 @@ pub mod tests {
v.push("there".to_string());
v.push("burma".to_string());
v.push("shave".to_string());
assert_eq!(v.as_slice(), &["hello".to_string(), "there".to_string(), "burma".to_string(), "shave".to_string()]);
assert_eq!(v.as_slice(), vec!["hello".to_string(), "there".to_string(), "burma".to_string(), "shave".to_string()].as_slice());
}

#[test]
Expand All @@ -522,9 +522,9 @@ pub mod tests {
v.push("there".to_string());
v.push("burma".to_string());
v.push("shave".to_string());
assert_eq!(v.as_slice(), &[
assert_eq!(v.as_slice(), vec![
"hello".to_string(), "there".to_string(), "burma".to_string(), "shave".to_string(), "hello".to_string(), "there".to_string(), "burma".to_string(), "shave".to_string(),
]);
].as_slice());
}
}

4 changes: 2 additions & 2 deletions components/util/sort.rs
Expand Up @@ -91,9 +91,9 @@ pub mod test {
let len: uint = rng.gen();
let mut v: Vec<int> = rng.gen_iter::<int>().take((len % 32) + 1).collect();
fn compare_ints(a: &int, b: &int) -> Ordering { a.cmp(b) }
sort::quicksort_by(v.as_slice_mut(), compare_ints);
sort::quicksort_by(v.as_mut_slice(), compare_ints);
for i in range(0, v.len() - 1) {
assert!(v.get(i) <= v.get(i + 1))
assert!(v[i] <= v[i + 1])
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions components/util/vec.rs
Expand Up @@ -11,7 +11,7 @@ pub trait Comparator<K,T> {
}

pub trait BinarySearchMethods<'a, T: Ord + PartialOrd + PartialEq> {
fn binary_search(&self, key: &T) -> Option<&'a T>;
fn binary_search_(&self, key: &T) -> Option<&'a T>;
fn binary_search_index(&self, key: &T) -> Option<uint>;
}

Expand All @@ -20,7 +20,7 @@ pub trait FullBinarySearchMethods<T> {
}

impl<'a, T: Ord + PartialOrd + PartialEq> BinarySearchMethods<'a, T> for &'a [T] {
fn binary_search(&self, key: &T) -> Option<&'a T> {
fn binary_search_(&self, key: &T) -> Option<&'a T> {
self.binary_search_index(key).map(|i| &self[i])
}

Expand Down Expand Up @@ -65,7 +65,7 @@ impl<T:PartialEq + PartialOrd + Ord> Comparator<T,T> for DefaultComparator {
fn test_find_all_elems<T: PartialEq + PartialOrd + Eq + Ord>(arr: &[T]) {
let mut i = 0;
while i < arr.len() {
assert!(test_match(&arr[i], arr.binary_search(&arr[i])));
assert!(test_match(&arr[i], arr.binary_search_(&arr[i])));
i += 1;
}
}
Expand All @@ -74,9 +74,9 @@ fn test_find_all_elems<T: PartialEq + PartialOrd + Eq + Ord>(arr: &[T]) {
fn test_miss_all_elems<T: PartialEq + PartialOrd + Eq + Ord>(arr: &[T], misses: &[T]) {
let mut i = 0;
while i < misses.len() {
let res = arr.binary_search(&misses[i]);
let res = arr.binary_search_(&misses[i]);
debug!("{:?} == {:?} ?", misses[i], res);
assert!(!test_match(&misses[i], arr.binary_search(&misses[i])));
assert!(!test_match(&misses[i], arr.binary_search_(&misses[i])));
i += 1;
}
}
Expand Down
25 changes: 15 additions & 10 deletions python/servo/testing_commands.py
Expand Up @@ -54,22 +54,27 @@ def test(self):
print("Tests completed in %0.2fs" % elapsed)

@Command('test-unit',
description='Run libservo unit tests',
description='Run unit tests',
category='testing',
allow_all_args=True)
@CommandArgument('test_name', default=None, nargs="...",
help="Only run tests that match this pattern")
@CommandArgument(
'params', default=None, nargs="...",
help="Command-line arguments to be passed to the test harness")
def test_unit(self, test_name=None, params=None):
if params is None:
params = []
if test_name is not None:
params.append(test_name)
def test_unit(self, test_name=None):
if test_name is None:
test_name = []
self.ensure_bootstrapped()
self.ensure_built_tests()
return self.run_test("servo", params)

ret = self.run_test("servo", test_name) != 0

def cargo_test(component):
return 0 != subprocess.call(
["cargo", "test", "-p", component], env=self.build_env())

for component in os.listdir("components"):
ret = ret or cargo_test(component)

return ret

@Command('test-ref',
description='Run the reference tests',
Expand Down

5 comments on commit 7f6f072

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from mbrubeck
at metajack@7f6f072

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging metajack/servo/fixup-unit-tests = 7f6f072 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metajack/servo/fixup-unit-tests = 7f6f072 merged ok, testing candidate = d4e977a

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d4e977a

Please sign in to comment.