Skip to content

Rename assert to enforce, add debug_assert #12108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Rename uses of assert_eq! to fail_unless_eq!.
  • Loading branch information
huonw committed Feb 22, 2014
commit e32253d54768c454bf1106105f44c7124d6b1ef0
10 changes: 5 additions & 5 deletions src/doc/guide-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ into a single value:
~~~
let xs = [1, 9, 2, 3, 14, 12];
let result = xs.iter().fold(0, |accumulator, item| accumulator - *item);
assert_eq!(result, -41);
fail_unless_eq!(result, -41);
~~~

Most adaptors return an adaptor object implementing the `Iterator` trait itself:
Expand All @@ -165,7 +165,7 @@ Most adaptors return an adaptor object implementing the `Iterator` trait itself:
let xs = [1, 9, 2, 3, 14, 12];
let ys = [5, 2, 1, 8];
let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
assert_eq!(sum, 57);
fail_unless_eq!(sum, 57);
~~~

Some iterator adaptors may return `None` before exhausting the underlying
Expand Down Expand Up @@ -200,7 +200,7 @@ let mut calls = 0;
it.next();
}

assert_eq!(calls, 3);
fail_unless_eq!(calls, 3);
~~~

## For loops
Expand Down Expand Up @@ -266,7 +266,7 @@ Iterators offer generic conversion to containers with the `collect` adaptor:
~~~
let xs = [0, 1, 1, 2, 3, 5, 8];
let ys = xs.rev_iter().skip(1).map(|&x| x * 2).collect::<~[int]>();
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
fail_unless_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
~~~

The method requires a type hint for the container type, if the surrounding code
Expand Down Expand Up @@ -384,7 +384,7 @@ the trailing underscore is a workaround for issue #5898 and will be removed.
~~~
let mut ys = [1, 2, 3, 4, 5];
ys.mut_iter().reverse_();
assert_eq!(ys, [5, 4, 3, 2, 1]);
fail_unless_eq!(ys, [5, 4, 3, 2, 1]);
~~~

## Random-access iterators
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -3009,7 +3009,7 @@ on `x: &int` are equivalent:
let y = match *x { 0 => "zero", _ => "some" };
let z = match x { &0 => "zero", _ => "some" };

assert_eq!(y, z);
fail_unless_eq!(y, z);
~~~~

A pattern that's just an identifier, like `Nil` in the previous example,
Expand Down
8 changes: 4 additions & 4 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ struct Foo {
d: u32
}

assert_eq!(size_of::<Foo>(), size_of::<u32>() * 4);
fail_unless_eq!(size_of::<Foo>(), size_of::<u32>() * 4);

struct Bar {
a: Foo,
Expand All @@ -1017,7 +1017,7 @@ struct Bar {
d: Foo
}

assert_eq!(size_of::<Bar>(), size_of::<u32>() * 16);
fail_unless_eq!(size_of::<Bar>(), size_of::<u32>() * 16);
~~~

Our previous attempt at defining the `List` type included an `u32` and a `List`
Expand Down Expand Up @@ -1677,7 +1677,7 @@ let x = Rc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let y = x.clone(); // a new owner
let z = x; // this moves `x` into `z`, rather than creating a new owner

assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
fail_unless_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

// the variable is mutable, but not the contents of the box
let mut a = Rc::new([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
Expand All @@ -1696,7 +1696,7 @@ let x = Gc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let y = x; // does not perform a move, unlike with `Rc`
let z = x;

assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
fail_unless_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
~~~

With shared ownership, mutability cannot be inherited so the boxes are always immutable. However,
Expand Down
48 changes: 24 additions & 24 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl BigBitv {
op: |uint, uint| -> uint)
-> bool {
let len = b.storage.len();
assert_eq!(self.storage.len(), len);
fail_unless_eq!(self.storage.len(), len);
let mut changed = false;
for (i, (a, b)) in self.storage.mut_iter()
.zip(b.storage.iter())
Expand Down Expand Up @@ -517,7 +517,7 @@ impl Bitv {
* Both the bitvector and vector must have the same length.
*/
pub fn eq_vec(&self, v: &[bool]) -> bool {
assert_eq!(self.nbits, v.len());
fail_unless_eq!(self.nbits, v.len());
let mut i = 0;
while i < self.nbits {
if self.get(i) != v[i] { return false; }
Expand Down Expand Up @@ -955,10 +955,10 @@ mod tests {
#[test]
fn test_to_str() {
let zerolen = Bitv::new(0u, false);
assert_eq!(zerolen.to_str(), ~"");
fail_unless_eq!(zerolen.to_str(), ~"");

let eightbits = Bitv::new(8u, false);
assert_eq!(eightbits.to_str(), ~"00000000");
fail_unless_eq!(eightbits.to_str(), ~"00000000");
}

#[test]
Expand All @@ -981,7 +981,7 @@ mod tests {
let mut b = bitv::Bitv::new(2, false);
b.set(0, true);
b.set(1, false);
assert_eq!(b.to_str(), ~"10");
fail_unless_eq!(b.to_str(), ~"10");
}

#[test]
Expand Down Expand Up @@ -1292,19 +1292,19 @@ mod tests {
fn test_from_bytes() {
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
let str = ~"10110110" + "00000000" + "11111111";
assert_eq!(bitv.to_str(), str);
fail_unless_eq!(bitv.to_str(), str);
}

#[test]
fn test_to_bytes() {
let mut bv = Bitv::new(3, true);
bv.set(1, false);
assert_eq!(bv.to_bytes(), ~[0b10100000]);
fail_unless_eq!(bv.to_bytes(), ~[0b10100000]);

let mut bv = Bitv::new(9, false);
bv.set(2, true);
bv.set(8, true);
assert_eq!(bv.to_bytes(), ~[0b00100000, 0b10000000]);
fail_unless_eq!(bv.to_bytes(), ~[0b00100000, 0b10000000]);
}

#[test]
Expand All @@ -1316,7 +1316,7 @@ mod tests {
#[test]
fn test_to_bools() {
let bools = ~[false, false, true, false, false, true, true, false];
assert_eq!(from_bytes([0b00100110]).to_bools(), bools);
fail_unless_eq!(from_bytes([0b00100110]).to_bools(), bools);
}

#[test]
Expand All @@ -1325,7 +1325,7 @@ mod tests {
let bitv = from_bools(bools);

for (act, &ex) in bitv.iter().zip(bools.iter()) {
assert_eq!(ex, act);
fail_unless_eq!(ex, act);
}
}

Expand All @@ -1335,7 +1335,7 @@ mod tests {
let bitv = BitvSet::from_bitv(from_bools(bools));

let idxs: ~[uint] = bitv.iter().collect();
assert_eq!(idxs, ~[0, 2, 3]);
fail_unless_eq!(idxs, ~[0, 2, 3]);
}

#[test]
Expand All @@ -1345,8 +1345,8 @@ mod tests {
for &b in bools.iter() {
for &l in lengths.iter() {
let bitset = BitvSet::from_bitv(Bitv::new(l, b));
assert_eq!(bitset.contains(&1u), b)
assert_eq!(bitset.contains(&(l-1u)), b)
fail_unless_eq!(bitset.contains(&1u), b)
fail_unless_eq!(bitset.contains(&(l-1u)), b)
fail_unless!(!bitset.contains(&l))
}
}
Expand Down Expand Up @@ -1407,7 +1407,7 @@ mod tests {
fail_unless!(b.insert(400));
fail_unless!(!b.insert(400));
fail_unless!(b.contains(&400));
assert_eq!(b.len(), 2);
fail_unless_eq!(b.len(), 2);
}

#[test]
Expand All @@ -1431,11 +1431,11 @@ mod tests {
let mut i = 0;
let expected = [3, 5, 11, 77];
a.intersection(&b, |x| {
assert_eq!(*x, expected[i]);
fail_unless_eq!(*x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
fail_unless_eq!(i, expected.len());
}

#[test]
Expand All @@ -1455,11 +1455,11 @@ mod tests {
let mut i = 0;
let expected = [1, 5, 500];
a.difference(&b, |x| {
assert_eq!(*x, expected[i]);
fail_unless_eq!(*x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
fail_unless_eq!(i, expected.len());
}

#[test]
Expand All @@ -1481,11 +1481,11 @@ mod tests {
let mut i = 0;
let expected = [1, 5, 11, 14, 220];
a.symmetric_difference(&b, |x| {
assert_eq!(*x, expected[i]);
fail_unless_eq!(*x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
fail_unless_eq!(i, expected.len());
}

#[test]
Expand All @@ -1510,11 +1510,11 @@ mod tests {
let mut i = 0;
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160];
a.union(&b, |x| {
assert_eq!(*x, expected[i]);
fail_unless_eq!(*x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
fail_unless_eq!(i, expected.len());
}

#[test]
Expand All @@ -1529,7 +1529,7 @@ mod tests {

fail_unless!(a.insert(1000));
fail_unless!(a.remove(&1000));
assert_eq!(a.capacity(), uint::BITS);
fail_unless_eq!(a.capacity(), uint::BITS);
}

#[test]
Expand All @@ -1542,7 +1542,7 @@ mod tests {

let mut b = a.clone();

assert_eq!(&a, &b);
fail_unless_eq!(&a, &b);

fail_unless!(b.remove(&1));
fail_unless!(a.contains(&1));
Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,13 +781,13 @@ mod test_btree {
#[test]
fn bsearch_test_one() {
let b = BTree::new(1, ~"abc", 2);
assert_eq!(Some(1), b.root.bsearch_node(2));
fail_unless_eq!(Some(1), b.root.bsearch_node(2));
}

#[test]
fn bsearch_test_two() {
let b = BTree::new(1, ~"abc", 2);
assert_eq!(Some(0), b.root.bsearch_node(0));
fail_unless_eq!(Some(0), b.root.bsearch_node(0));
}

#[test]
Expand All @@ -798,7 +798,7 @@ mod test_btree {
let leaf_elt_4 = LeafElt::new(5, ~"ddd");
let n = Node::new_leaf(~[leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4]);
let b = BTree::new_with_node_len(n, 3, 2);
assert_eq!(Some(2), b.root.bsearch_node(3));
fail_unless_eq!(Some(2), b.root.bsearch_node(3));
}

#[test]
Expand All @@ -809,15 +809,15 @@ mod test_btree {
let leaf_elt_4 = LeafElt::new(5, ~"ddd");
let n = Node::new_leaf(~[leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4]);
let b = BTree::new_with_node_len(n, 3, 2);
assert_eq!(Some(4), b.root.bsearch_node(800));
fail_unless_eq!(Some(4), b.root.bsearch_node(800));
}

//Tests the functionality of the get method.
#[test]
fn get_test() {
let b = BTree::new(1, ~"abc", 2);
let val = b.get(1);
assert_eq!(val, Some(~"abc"));
fail_unless_eq!(val, Some(~"abc"));
}

//Tests the BTree's clone() method.
Expand Down Expand Up @@ -856,7 +856,7 @@ mod test_btree {
#[test]
fn btree_tostr_test() {
let b = BTree::new(1, ~"abc", 2);
assert_eq!(b.to_str(), ~"Key: 1, value: abc;")
fail_unless_eq!(b.to_str(), ~"Key: 1, value: abc;")
}

}
Loading