1
Fork 0

librustc: Convert all uses of assert over to fail_unless!

This commit is contained in:
Patrick Walton 2013-03-06 13:58:02 -08:00
parent 0ea031bcb8
commit d7e74b5e91
817 changed files with 6378 additions and 6335 deletions

View file

@ -205,7 +205,7 @@ grammar as double-quoted strings. Other tokens have exact rules given.
The keywords are the following strings: The keywords are the following strings:
~~~~~~~~ {.keyword} ~~~~~~~~ {.keyword}
as assert as
break break
const copy const copy
do drop do drop
@ -2000,7 +2000,7 @@ let v = ~[1,2,3];
mutate(copy v); // Pass a copy mutate(copy v); // Pass a copy
assert v[0] == 1; // Original was not modified fail_unless!(v[0] == 1); // Original was not modified
~~~~ ~~~~
### Unary move expressions ### Unary move expressions
@ -2450,17 +2450,6 @@ In the future, logging will move into a library, and will no longer be a core ex
It is therefore recommended to use the macro forms of logging (`error!`, `debug!`, etc.) to minimize disruption in code that uses logging. It is therefore recommended to use the macro forms of logging (`error!`, `debug!`, etc.) to minimize disruption in code that uses logging.
### Assert expressions
~~~~~~~~{.ebnf .gram}
assert_expr : "assert" expr ;
~~~~~~~~
> **Note:** In future versions of Rust, `assert` will be changed from a full expression to a macro.
An `assert` expression causes the program to fail if its `expr` argument evaluates to `false`.
The failure carries string representation of the false expression.
# Type system # Type system
## Types ## Types
@ -2560,7 +2549,7 @@ An example of a tuple type and its use:
type Pair<'self> = (int,&'self str); type Pair<'self> = (int,&'self str);
let p: Pair<'static> = (10,"hello"); let p: Pair<'static> = (10,"hello");
let (a, b) = p; let (a, b) = p;
assert b != "world"; fail_unless!(b != "world");
~~~~ ~~~~
@ -2581,7 +2570,7 @@ An example of a vector type and its use:
~~~~ ~~~~
let v: &[int] = &[7, 5, 3]; let v: &[int] = &[7, 5, 3];
let i: int = v[2]; let i: int = v[2];
assert (i == 3); fail_unless!(i == 3);
~~~~ ~~~~
All accessible elements of a vector are always initialized, and access to a vector is always bounds-checked. All accessible elements of a vector are always initialized, and access to a vector is always bounds-checked.
@ -2986,7 +2975,7 @@ example of an _implicit dereference_ operation performed on box values:
~~~~~~~~ ~~~~~~~~
struct Foo { y: int } struct Foo { y: int }
let x = @Foo{y: 10}; let x = @Foo{y: 10};
assert x.y == 10; fail_unless!(x.y == 10);
~~~~~~~~ ~~~~~~~~
Other operations act on box values as single-word-sized address values. For Other operations act on box values as single-word-sized address values. For

View file

@ -239,7 +239,7 @@ fn unix_time_in_microseconds() -> u64 {
} }
} }
# fn main() { assert fmt!("%?", unix_time_in_microseconds()) != ~""; } # fn main() { fail_unless!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
~~~~ ~~~~
The `#[nolink]` attribute indicates that there's no foreign library to The `#[nolink]` attribute indicates that there's no foreign library to

View file

@ -297,9 +297,9 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );
Rust has a built-in mechanism for raising exceptions. The `fail!()` macro Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
(which can also be written with an error string as an argument: `fail!( (which can also be written with an error string as an argument: `fail!(
~reason)`) and the `assert` construct (which effectively calls `fail!()` if a ~reason)`) and the `fail_unless!` construct (which effectively calls `fail!()`
boolean expression is false) are both ways to raise exceptions. When a task if a boolean expression is false) are both ways to raise exceptions. When a
raises an exception the task unwinds its stack---running destructors and task raises an exception the task unwinds its stack---running destructors and
freeing memory along the way---and then exits. Unlike exceptions in C++, freeing memory along the way---and then exits. Unlike exceptions in C++,
exceptions in Rust are unrecoverable within a single task: once a task fails, exceptions in Rust are unrecoverable within a single task: once a task fails,
there is no way to "catch" the exception. there is no way to "catch" the exception.
@ -339,7 +339,7 @@ let result: Result<int, ()> = do task::try {
fail!(~"oops!"); fail!(~"oops!");
} }
}; };
assert result.is_err(); fail_unless!(result.is_err());
~~~ ~~~
Unlike `spawn`, the function spawned using `try` may return a value, Unlike `spawn`, the function spawned using `try` may return a value,
@ -401,7 +401,7 @@ do spawn { // Bidirectionally linked
// Wait for the supervised child task to exist. // Wait for the supervised child task to exist.
let message = receiver.recv(); let message = receiver.recv();
// Kill both it and the parent task. // Kill both it and the parent task.
assert message != 42; fail_unless!(message != 42);
} }
do try { // Unidirectionally linked do try { // Unidirectionally linked
sender.send(42); sender.send(42);
@ -507,13 +507,13 @@ do spawn {
}; };
from_child.send(22); from_child.send(22);
assert from_child.recv() == ~"22"; fail_unless!(from_child.recv() == ~"22");
from_child.send(23); from_child.send(23);
from_child.send(0); from_child.send(0);
assert from_child.recv() == ~"23"; fail_unless!(from_child.recv() == ~"23");
assert from_child.recv() == ~"0"; fail_unless!(from_child.recv() == ~"0");
# } # }
~~~~ ~~~~

View file

@ -381,7 +381,7 @@ expression to the given type.
~~~~ ~~~~
let x: float = 4.0; let x: float = 4.0;
let y: uint = x as uint; let y: uint = x as uint;
assert y == 4u; fail_unless!(y == 4u);
~~~~ ~~~~
## Syntax extensions ## Syntax extensions
@ -849,8 +849,8 @@ Ending the function with a semicolon like so is equivalent to returning `()`.
fn line(a: int, b: int, x: int) -> int { a * x + b } fn line(a: int, b: int, x: int) -> int { a * x + b }
fn oops(a: int, b: int, x: int) -> () { a * x + b; } fn oops(a: int, b: int, x: int) -> () { a * x + b; }
assert 8 == line(5, 3, 1); fail_unless!(8 == line(5, 3, 1));
assert () == oops(5, 3, 1); fail_unless!(() == oops(5, 3, 1));
~~~~ ~~~~
As with `match` expressions and `let` bindings, function arguments support As with `match` expressions and `let` bindings, function arguments support
@ -1000,7 +1000,7 @@ let x = ~10;
let y = copy x; let y = copy x;
let z = *x + *y; let z = *x + *y;
assert z == 20; fail_unless!(z == 20);
~~~~ ~~~~
When they do not contain any managed boxes, owned boxes can be sent When they do not contain any managed boxes, owned boxes can be sent
@ -1327,8 +1327,8 @@ and [`core::str`]. Here are some examples.
let crayons = [Almond, AntiqueBrass, Apricot]; let crayons = [Almond, AntiqueBrass, Apricot];
// Check the length of the vector // Check the length of the vector
assert crayons.len() == 3; fail_unless!(crayons.len() == 3);
assert !crayons.is_empty(); fail_unless!(!crayons.is_empty());
// Iterate over a vector, obtaining a pointer to each element // Iterate over a vector, obtaining a pointer to each element
for crayons.each |crayon| { for crayons.each |crayon| {

View file

@ -63,7 +63,7 @@ pub fn parse_config(args: ~[~str]) -> config {
getopts::optopt(~"logfile"), getopts::optopt(~"logfile"),
getopts::optflag(~"jit")]; getopts::optflag(~"jit")];
assert !args.is_empty(); fail_unless!(!args.is_empty());
let args_ = vec::tail(args); let args_ = vec::tail(args);
let matches = let matches =
&match getopts::getopts(args_, opts) { &match getopts::getopts(args_, opts) {

View file

@ -25,7 +25,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
let mut env = os::env(); let mut env = os::env();
// Make sure we include the aux directory in the path // Make sure we include the aux directory in the path
assert prog.ends_with(~".exe"); fail_unless!(prog.ends_with(~".exe"));
let aux_path = prog.slice(0u, prog.len() - 4u) + ~".libaux"; let aux_path = prog.slice(0u, prog.len() - 4u) + ~".libaux";
env = do vec::map(env) |pair| { env = do vec::map(env) |pair| {

View file

@ -292,31 +292,31 @@ pub fn test() {
} }
} }
assert seq_range(10, 15) == @[10, 11, 12, 13, 14]; fail_unless!(seq_range(10, 15) == @[10, 11, 12, 13, 14]);
assert from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]; fail_unless!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
assert from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]; fail_unless!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
} }
#[test] #[test]
pub fn append_test() { pub fn append_test() {
assert @[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]; fail_unless!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
} }
#[test] #[test]
pub fn test_from_owned() { pub fn test_from_owned() {
assert from_owned::<int>(~[]) == @[]; fail_unless!(from_owned::<int>(~[]) == @[]);
assert from_owned(~[true]) == @[true]; fail_unless!(from_owned(~[true]) == @[true]);
assert from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]; fail_unless!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
assert from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]; fail_unless!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
assert from_owned(~[~[42]]) == @[~[42]]; fail_unless!(from_owned(~[~[42]]) == @[~[42]]);
} }
#[test] #[test]
pub fn test_from_slice() { pub fn test_from_slice() {
assert from_slice::<int>([]) == @[]; fail_unless!(from_slice::<int>([]) == @[]);
assert from_slice([true]) == @[true]; fail_unless!(from_slice([true]) == @[true]);
assert from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]; fail_unless!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
assert from_slice([@"abc", @"123"]) == @[@"abc", @"123"]; fail_unless!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
assert from_slice([@[42]]) == @[@[42]]; fail_unless!(from_slice([@[42]]) == @[@[42]]);
} }

View file

@ -86,20 +86,20 @@ pub fn test_bool_from_str() {
use from_str::FromStr; use from_str::FromStr;
do all_values |v| { do all_values |v| {
assert Some(v) == FromStr::from_str(to_str(v)) fail_unless!(Some(v) == FromStr::from_str(to_str(v)))
} }
} }
#[test] #[test]
pub fn test_bool_to_str() { pub fn test_bool_to_str() {
assert to_str(false) == ~"false"; fail_unless!(to_str(false) == ~"false");
assert to_str(true) == ~"true"; fail_unless!(to_str(true) == ~"true");
} }
#[test] #[test]
pub fn test_bool_to_bit() { pub fn test_bool_to_bit() {
do all_values |v| { do all_values |v| {
assert to_bit(v) == if is_true(v) { 1u8 } else { 0u8 }; fail_unless!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
} }
} }

View file

@ -48,7 +48,7 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
* *
* # Example * # Example
* *
* assert transmute("L") == ~[76u8, 0u8]; * fail_unless!(transmute("L") == ~[76u8, 0u8]);
*/ */
#[inline(always)] #[inline(always)]
pub unsafe fn transmute<L, G>(thing: L) -> G { pub unsafe fn transmute<L, G>(thing: L) -> G {
@ -112,7 +112,7 @@ pub mod tests {
#[test] #[test]
pub fn test_reinterpret_cast() { pub fn test_reinterpret_cast() {
assert 1u == unsafe { reinterpret_cast(&1) }; fail_unless!(1u == unsafe { reinterpret_cast(&1) });
} }
#[test] #[test]
@ -123,8 +123,8 @@ pub mod tests {
let ptr: *int = transmute(box); // refcount 2 let ptr: *int = transmute(box); // refcount 2
let _box1: @~str = reinterpret_cast(&ptr); let _box1: @~str = reinterpret_cast(&ptr);
let _box2: @~str = reinterpret_cast(&ptr); let _box2: @~str = reinterpret_cast(&ptr);
assert *_box1 == ~"box box box"; fail_unless!(*_box1 == ~"box box box");
assert *_box2 == ~"box box box"; fail_unless!(*_box2 == ~"box box box");
// Will destroy _box1 and _box2. Without the bump, this would // Will destroy _box1 and _box2. Without the bump, this would
// use-after-free. With too many bumps, it would leak. // use-after-free. With too many bumps, it would leak.
} }
@ -136,7 +136,7 @@ pub mod tests {
unsafe { unsafe {
let x = @100u8; let x = @100u8;
let x: *BoxRepr = transmute(x); let x: *BoxRepr = transmute(x);
assert (*x).data == 100; fail_unless!((*x).data == 100);
let _x: @int = transmute(x); let _x: @int = transmute(x);
} }
} }
@ -144,7 +144,7 @@ pub mod tests {
#[test] #[test]
pub fn test_transmute2() { pub fn test_transmute2() {
unsafe { unsafe {
assert ~[76u8, 0u8] == transmute(~"L"); fail_unless!(~[76u8, 0u8] == transmute(~"L"));
} }
} }
} }

View file

@ -65,12 +65,12 @@ pub impl<T> Cell<T> {
#[test] #[test]
fn test_basic() { fn test_basic() {
let value_cell = Cell(~10); let value_cell = Cell(~10);
assert !value_cell.is_empty(); fail_unless!(!value_cell.is_empty());
let value = value_cell.take(); let value = value_cell.take();
assert value == ~10; fail_unless!(value == ~10);
assert value_cell.is_empty(); fail_unless!(value_cell.is_empty());
value_cell.put_back(value); value_cell.put_back(value);
assert !value_cell.is_empty(); fail_unless!(!value_cell.is_empty());
} }
#[test] #[test]

View file

@ -200,7 +200,7 @@ pub pure fn escape_unicode(c: char) -> ~str {
let (c, pad) = (if c <= '\xff' { ('x', 2u) } let (c, pad) = (if c <= '\xff' { ('x', 2u) }
else if c <= '\uffff' { ('u', 4u) } else if c <= '\uffff' { ('u', 4u) }
else { ('U', 8u) }); else { ('U', 8u) });
assert str::len(s) <= pad; fail_unless!(str::len(s) <= pad);
let mut out = ~"\\"; let mut out = ~"\\";
unsafe { unsafe {
str::push_str(&mut out, str::from_char(c)); str::push_str(&mut out, str::from_char(c));
@ -258,91 +258,91 @@ impl Eq for char {
#[test] #[test]
fn test_is_lowercase() { fn test_is_lowercase() {
assert is_lowercase('a'); fail_unless!(is_lowercase('a'));
assert is_lowercase('ö'); fail_unless!(is_lowercase('ö'));
assert is_lowercase('ß'); fail_unless!(is_lowercase('ß'));
assert !is_lowercase('Ü'); fail_unless!(!is_lowercase('Ü'));
assert !is_lowercase('P'); fail_unless!(!is_lowercase('P'));
} }
#[test] #[test]
fn test_is_uppercase() { fn test_is_uppercase() {
assert !is_uppercase('h'); fail_unless!(!is_uppercase('h'));
assert !is_uppercase('ä'); fail_unless!(!is_uppercase('ä'));
assert !is_uppercase('ß'); fail_unless!(!is_uppercase('ß'));
assert is_uppercase('Ö'); fail_unless!(is_uppercase('Ö'));
assert is_uppercase('T'); fail_unless!(is_uppercase('T'));
} }
#[test] #[test]
fn test_is_whitespace() { fn test_is_whitespace() {
assert is_whitespace(' '); fail_unless!(is_whitespace(' '));
assert is_whitespace('\u2007'); fail_unless!(is_whitespace('\u2007'));
assert is_whitespace('\t'); fail_unless!(is_whitespace('\t'));
assert is_whitespace('\n'); fail_unless!(is_whitespace('\n'));
assert !is_whitespace('a'); fail_unless!(!is_whitespace('a'));
assert !is_whitespace('_'); fail_unless!(!is_whitespace('_'));
assert !is_whitespace('\u0000'); fail_unless!(!is_whitespace('\u0000'));
} }
#[test] #[test]
fn test_to_digit() { fn test_to_digit() {
assert to_digit('0', 10u) == Some(0u); fail_unless!(to_digit('0', 10u) == Some(0u));
assert to_digit('1', 2u) == Some(1u); fail_unless!(to_digit('1', 2u) == Some(1u));
assert to_digit('2', 3u) == Some(2u); fail_unless!(to_digit('2', 3u) == Some(2u));
assert to_digit('9', 10u) == Some(9u); fail_unless!(to_digit('9', 10u) == Some(9u));
assert to_digit('a', 16u) == Some(10u); fail_unless!(to_digit('a', 16u) == Some(10u));
assert to_digit('A', 16u) == Some(10u); fail_unless!(to_digit('A', 16u) == Some(10u));
assert to_digit('b', 16u) == Some(11u); fail_unless!(to_digit('b', 16u) == Some(11u));
assert to_digit('B', 16u) == Some(11u); fail_unless!(to_digit('B', 16u) == Some(11u));
assert to_digit('z', 36u) == Some(35u); fail_unless!(to_digit('z', 36u) == Some(35u));
assert to_digit('Z', 36u) == Some(35u); fail_unless!(to_digit('Z', 36u) == Some(35u));
assert to_digit(' ', 10u).is_none(); fail_unless!(to_digit(' ', 10u).is_none());
assert to_digit('$', 36u).is_none(); fail_unless!(to_digit('$', 36u).is_none());
} }
#[test] #[test]
fn test_is_ascii() { fn test_is_ascii() {
assert str::all(~"banana", is_ascii); fail_unless!(str::all(~"banana", is_ascii));
assert ! str::all(~"ประเทศไทย中华Việt Nam", is_ascii); fail_unless!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
} }
#[test] #[test]
fn test_is_digit() { fn test_is_digit() {
assert is_digit('2'); fail_unless!(is_digit('2'));
assert is_digit('7'); fail_unless!(is_digit('7'));
assert ! is_digit('c'); fail_unless!(! is_digit('c'));
assert ! is_digit('i'); fail_unless!(! is_digit('i'));
assert ! is_digit('z'); fail_unless!(! is_digit('z'));
assert ! is_digit('Q'); fail_unless!(! is_digit('Q'));
} }
#[test] #[test]
fn test_escape_default() { fn test_escape_default() {
assert escape_default('\n') == ~"\\n"; fail_unless!(escape_default('\n') == ~"\\n");
assert escape_default('\r') == ~"\\r"; fail_unless!(escape_default('\r') == ~"\\r");
assert escape_default('\'') == ~"\\'"; fail_unless!(escape_default('\'') == ~"\\'");
assert escape_default('"') == ~"\\\""; fail_unless!(escape_default('"') == ~"\\\"");
assert escape_default(' ') == ~" "; fail_unless!(escape_default(' ') == ~" ");
assert escape_default('a') == ~"a"; fail_unless!(escape_default('a') == ~"a");
assert escape_default('~') == ~"~"; fail_unless!(escape_default('~') == ~"~");
assert escape_default('\x00') == ~"\\x00"; fail_unless!(escape_default('\x00') == ~"\\x00");
assert escape_default('\x1f') == ~"\\x1f"; fail_unless!(escape_default('\x1f') == ~"\\x1f");
assert escape_default('\x7f') == ~"\\x7f"; fail_unless!(escape_default('\x7f') == ~"\\x7f");
assert escape_default('\xff') == ~"\\xff"; fail_unless!(escape_default('\xff') == ~"\\xff");
assert escape_default('\u011b') == ~"\\u011b"; fail_unless!(escape_default('\u011b') == ~"\\u011b");
assert escape_default('\U0001d4b6') == ~"\\U0001d4b6"; fail_unless!(escape_default('\U0001d4b6') == ~"\\U0001d4b6");
} }
#[test] #[test]
fn test_escape_unicode() { fn test_escape_unicode() {
assert escape_unicode('\x00') == ~"\\x00"; fail_unless!(escape_unicode('\x00') == ~"\\x00");
assert escape_unicode('\n') == ~"\\x0a"; fail_unless!(escape_unicode('\n') == ~"\\x0a");
assert escape_unicode(' ') == ~"\\x20"; fail_unless!(escape_unicode(' ') == ~"\\x20");
assert escape_unicode('a') == ~"\\x61"; fail_unless!(escape_unicode('a') == ~"\\x61");
assert escape_unicode('\u011b') == ~"\\u011b"; fail_unless!(escape_unicode('\u011b') == ~"\\u011b");
assert escape_unicode('\U0001d4b6') == ~"\\U0001d4b6"; fail_unless!(escape_unicode('\U0001d4b6') == ~"\\U0001d4b6");
} }

View file

@ -172,10 +172,10 @@ pub pure fn max<T:Ord>(v1: T, v2: T) -> T {
mod test { mod test {
#[test] #[test]
fn test_int() { fn test_int() {
assert 5.cmp(&10) == Less; fail_unless!(5.cmp(&10) == Less);
assert 10.cmp(&5) == Greater; fail_unless!(10.cmp(&5) == Greater);
assert 5.cmp(&5) == Equal; fail_unless!(5.cmp(&5) == Equal);
assert (-5).cmp(&12) == Less; fail_unless!((-5).cmp(&12) == Less);
assert 12.cmp(-5) == Greater; fail_unless!(12.cmp(-5) == Greater);
} }
} }

View file

@ -464,6 +464,6 @@ pub mod test {
let _chan = chan; let _chan = chan;
} }
assert !port.peek(); fail_unless!(!port.peek());
} }
} }

View file

@ -124,7 +124,7 @@ mod test {
trouble(1); trouble(1);
} }
assert inner_trapped; fail_unless!(inner_trapped);
} }
#[test] #[test]
@ -140,7 +140,7 @@ mod test {
trouble(1); trouble(1);
} }
assert outer_trapped; fail_unless!(outer_trapped);
} }
fn nested_reraise_trap_test_inner() { fn nested_reraise_trap_test_inner() {
@ -157,7 +157,7 @@ mod test {
trouble(1); trouble(1);
} }
assert inner_trapped; fail_unless!(inner_trapped);
} }
#[test] #[test]
@ -172,7 +172,7 @@ mod test {
nested_reraise_trap_test_inner(); nested_reraise_trap_test_inner();
} }
assert outer_trapped; fail_unless!(outer_trapped);
} }
#[test] #[test]
@ -187,6 +187,6 @@ mod test {
trouble(1); trouble(1);
} }
assert trapped; fail_unless!(trapped);
} }
} }

View file

@ -170,7 +170,7 @@ priv impl<T> DList<T> {
// Remove a node from the list. // Remove a node from the list.
fn unlink(@mut self, nobe: @mut DListNode<T>) { fn unlink(@mut self, nobe: @mut DListNode<T>) {
self.assert_mine(nobe); self.assert_mine(nobe);
assert self.size > 0; fail_unless!(self.size > 0);
self.link(nobe.prev, nobe.next); self.link(nobe.prev, nobe.next);
nobe.prev = None; // Release extraneous references. nobe.prev = None; // Release extraneous references.
nobe.next = None; nobe.next = None;
@ -192,7 +192,7 @@ priv impl<T> DList<T> {
nobe: DListLink<T>, nobe: DListLink<T>,
neighbour: @mut DListNode<T>) { neighbour: @mut DListNode<T>) {
self.assert_mine(neighbour); self.assert_mine(neighbour);
assert self.size > 0; fail_unless!(self.size > 0);
self.link(neighbour.prev, nobe); self.link(neighbour.prev, nobe);
self.link(nobe, Some(neighbour)); self.link(nobe, Some(neighbour));
self.size += 1; self.size += 1;
@ -201,7 +201,7 @@ priv impl<T> DList<T> {
neighbour: @mut DListNode<T>, neighbour: @mut DListNode<T>,
nobe: DListLink<T>) { nobe: DListLink<T>) {
self.assert_mine(neighbour); self.assert_mine(neighbour);
assert self.size > 0; fail_unless!(self.size > 0);
self.link(nobe, neighbour.next); self.link(nobe, neighbour.next);
self.link(Some(neighbour), nobe); self.link(Some(neighbour), nobe);
self.size += 1; self.size += 1;
@ -409,7 +409,7 @@ pub impl<T> DList<T> {
/// Check data structure integrity. O(n). /// Check data structure integrity. O(n).
fn assert_consistent(@mut self) { fn assert_consistent(@mut self) {
if self.hd.is_none() || self.tl.is_none() { if self.hd.is_none() || self.tl.is_none() {
assert self.hd.is_none() && self.tl.is_none(); fail_unless!(self.hd.is_none() && self.tl.is_none());
} }
// iterate forwards // iterate forwards
let mut count = 0; let mut count = 0;
@ -417,7 +417,7 @@ pub impl<T> DList<T> {
let mut rabbit = link; let mut rabbit = link;
while link.is_some() { while link.is_some() {
let nobe = link.get(); let nobe = link.get();
assert nobe.linked; fail_unless!(nobe.linked);
// check cycle // check cycle
if rabbit.is_some() { if rabbit.is_some() {
rabbit = rabbit.get().next; rabbit = rabbit.get().next;
@ -426,19 +426,19 @@ pub impl<T> DList<T> {
rabbit = rabbit.get().next; rabbit = rabbit.get().next;
} }
if rabbit.is_some() { if rabbit.is_some() {
assert !managed::mut_ptr_eq(rabbit.get(), nobe); fail_unless!(!managed::mut_ptr_eq(rabbit.get(), nobe));
} }
// advance // advance
link = nobe.next_link(); link = nobe.next_link();
count += 1; count += 1;
} }
assert count == self.len(); fail_unless!(count == self.len());
// iterate backwards - some of this is probably redundant. // iterate backwards - some of this is probably redundant.
link = self.peek_tail_n(); link = self.peek_tail_n();
rabbit = link; rabbit = link;
while link.is_some() { while link.is_some() {
let nobe = link.get(); let nobe = link.get();
assert nobe.linked; fail_unless!(nobe.linked);
// check cycle // check cycle
if rabbit.is_some() { if rabbit.is_some() {
rabbit = rabbit.get().prev; rabbit = rabbit.get().prev;
@ -447,13 +447,13 @@ pub impl<T> DList<T> {
rabbit = rabbit.get().prev; rabbit = rabbit.get().prev;
} }
if rabbit.is_some() { if rabbit.is_some() {
assert !managed::mut_ptr_eq(rabbit.get(), nobe); fail_unless!(!managed::mut_ptr_eq(rabbit.get(), nobe));
} }
// advance // advance
link = nobe.prev_link(); link = nobe.prev_link();
count -= 1; count -= 1;
} }
assert count == 0; fail_unless!(count == 0);
} }
} }
@ -513,66 +513,66 @@ mod tests {
let ab = from_vec(~[a,b]); let ab = from_vec(~[a,b]);
let cd = from_vec(~[c,d]); let cd = from_vec(~[c,d]);
let abcd = concat(concat(from_vec(~[ab,cd]))); let abcd = concat(concat(from_vec(~[ab,cd])));
abcd.assert_consistent(); assert abcd.len() == 8; abcd.assert_consistent(); fail_unless!(abcd.len() == 8);
abcd.assert_consistent(); assert abcd.pop().get() == 1; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 1);
abcd.assert_consistent(); assert abcd.pop().get() == 2; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 2);
abcd.assert_consistent(); assert abcd.pop().get() == 3; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 3);
abcd.assert_consistent(); assert abcd.pop().get() == 4; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 4);
abcd.assert_consistent(); assert abcd.pop().get() == 5; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 5);
abcd.assert_consistent(); assert abcd.pop().get() == 6; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 6);
abcd.assert_consistent(); assert abcd.pop().get() == 7; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 7);
abcd.assert_consistent(); assert abcd.pop().get() == 8; abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 8);
abcd.assert_consistent(); assert abcd.is_empty(); abcd.assert_consistent(); fail_unless!(abcd.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append() { pub fn test_dlist_append() {
let a = from_vec(~[1,2,3]); let a = from_vec(~[1,2,3]);
let b = from_vec(~[4,5,6]); let b = from_vec(~[4,5,6]);
a.append(b); a.append(b);
assert a.len() == 6; fail_unless!(a.len() == 6);
assert b.len() == 0; fail_unless!(b.len() == 0);
b.assert_consistent(); b.assert_consistent();
a.assert_consistent(); assert a.pop().get() == 1; a.assert_consistent(); fail_unless!(a.pop().get() == 1);
a.assert_consistent(); assert a.pop().get() == 2; a.assert_consistent(); fail_unless!(a.pop().get() == 2);
a.assert_consistent(); assert a.pop().get() == 3; a.assert_consistent(); fail_unless!(a.pop().get() == 3);
a.assert_consistent(); assert a.pop().get() == 4; a.assert_consistent(); fail_unless!(a.pop().get() == 4);
a.assert_consistent(); assert a.pop().get() == 5; a.assert_consistent(); fail_unless!(a.pop().get() == 5);
a.assert_consistent(); assert a.pop().get() == 6; a.assert_consistent(); fail_unless!(a.pop().get() == 6);
a.assert_consistent(); assert a.is_empty(); a.assert_consistent(); fail_unless!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append_empty() { pub fn test_dlist_append_empty() {
let a = from_vec(~[1,2,3]); let a = from_vec(~[1,2,3]);
let b = DList::<int>(); let b = DList::<int>();
a.append(b); a.append(b);
assert a.len() == 3; fail_unless!(a.len() == 3);
assert b.len() == 0; fail_unless!(b.len() == 0);
b.assert_consistent(); b.assert_consistent();
a.assert_consistent(); assert a.pop().get() == 1; a.assert_consistent(); fail_unless!(a.pop().get() == 1);
a.assert_consistent(); assert a.pop().get() == 2; a.assert_consistent(); fail_unless!(a.pop().get() == 2);
a.assert_consistent(); assert a.pop().get() == 3; a.assert_consistent(); fail_unless!(a.pop().get() == 3);
a.assert_consistent(); assert a.is_empty(); a.assert_consistent(); fail_unless!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append_to_empty() { pub fn test_dlist_append_to_empty() {
let a = DList::<int>(); let a = DList::<int>();
let b = from_vec(~[4,5,6]); let b = from_vec(~[4,5,6]);
a.append(b); a.append(b);
assert a.len() == 3; fail_unless!(a.len() == 3);
assert b.len() == 0; fail_unless!(b.len() == 0);
b.assert_consistent(); b.assert_consistent();
a.assert_consistent(); assert a.pop().get() == 4; a.assert_consistent(); fail_unless!(a.pop().get() == 4);
a.assert_consistent(); assert a.pop().get() == 5; a.assert_consistent(); fail_unless!(a.pop().get() == 5);
a.assert_consistent(); assert a.pop().get() == 6; a.assert_consistent(); fail_unless!(a.pop().get() == 6);
a.assert_consistent(); assert a.is_empty(); a.assert_consistent(); fail_unless!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append_two_empty() { pub fn test_dlist_append_two_empty() {
let a = DList::<int>(); let a = DList::<int>();
let b = DList::<int>(); let b = DList::<int>();
a.append(b); a.append(b);
assert a.len() == 0; fail_unless!(a.len() == 0);
assert b.len() == 0; fail_unless!(b.len() == 0);
b.assert_consistent(); b.assert_consistent();
a.assert_consistent(); a.assert_consistent();
} }
@ -595,34 +595,34 @@ mod tests {
let a = from_vec(~[1,2,3]); let a = from_vec(~[1,2,3]);
let b = from_vec(~[4,5,6]); let b = from_vec(~[4,5,6]);
b.prepend(a); b.prepend(a);
assert a.len() == 0; fail_unless!(a.len() == 0);
assert b.len() == 6; fail_unless!(b.len() == 6);
a.assert_consistent(); a.assert_consistent();
b.assert_consistent(); assert b.pop().get() == 1; b.assert_consistent(); fail_unless!(b.pop().get() == 1);
b.assert_consistent(); assert b.pop().get() == 2; b.assert_consistent(); fail_unless!(b.pop().get() == 2);
b.assert_consistent(); assert b.pop().get() == 3; b.assert_consistent(); fail_unless!(b.pop().get() == 3);
b.assert_consistent(); assert b.pop().get() == 4; b.assert_consistent(); fail_unless!(b.pop().get() == 4);
b.assert_consistent(); assert b.pop().get() == 5; b.assert_consistent(); fail_unless!(b.pop().get() == 5);
b.assert_consistent(); assert b.pop().get() == 6; b.assert_consistent(); fail_unless!(b.pop().get() == 6);
b.assert_consistent(); assert b.is_empty(); b.assert_consistent(); fail_unless!(b.is_empty());
} }
#[test] #[test]
pub fn test_dlist_reverse() { pub fn test_dlist_reverse() {
let a = from_vec(~[5,4,3,2,1]); let a = from_vec(~[5,4,3,2,1]);
a.reverse(); a.reverse();
assert a.len() == 5; fail_unless!(a.len() == 5);
a.assert_consistent(); assert a.pop().get() == 1; a.assert_consistent(); fail_unless!(a.pop().get() == 1);
a.assert_consistent(); assert a.pop().get() == 2; a.assert_consistent(); fail_unless!(a.pop().get() == 2);
a.assert_consistent(); assert a.pop().get() == 3; a.assert_consistent(); fail_unless!(a.pop().get() == 3);
a.assert_consistent(); assert a.pop().get() == 4; a.assert_consistent(); fail_unless!(a.pop().get() == 4);
a.assert_consistent(); assert a.pop().get() == 5; a.assert_consistent(); fail_unless!(a.pop().get() == 5);
a.assert_consistent(); assert a.is_empty(); a.assert_consistent(); fail_unless!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_reverse_empty() { pub fn test_dlist_reverse_empty() {
let a = DList::<int>(); let a = DList::<int>();
a.reverse(); a.reverse();
assert a.len() == 0; fail_unless!(a.len() == 0);
a.assert_consistent(); a.assert_consistent();
} }
#[test] #[test]
@ -633,94 +633,94 @@ mod tests {
a.insert_before(3, nobe); a.insert_before(3, nobe);
} }
} }
assert a.len() == 6; fail_unless!(a.len() == 6);
a.assert_consistent(); assert a.pop().get() == 1; a.assert_consistent(); fail_unless!(a.pop().get() == 1);
a.assert_consistent(); assert a.pop().get() == 2; a.assert_consistent(); fail_unless!(a.pop().get() == 2);
a.assert_consistent(); assert a.pop().get() == 3; a.assert_consistent(); fail_unless!(a.pop().get() == 3);
a.assert_consistent(); assert a.pop().get() == 4; a.assert_consistent(); fail_unless!(a.pop().get() == 4);
a.assert_consistent(); assert a.pop().get() == 3; a.assert_consistent(); fail_unless!(a.pop().get() == 3);
a.assert_consistent(); assert a.pop().get() == 5; a.assert_consistent(); fail_unless!(a.pop().get() == 5);
a.assert_consistent(); assert a.is_empty(); a.assert_consistent(); fail_unless!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_clear() { pub fn test_dlist_clear() {
let a = from_vec(~[5,4,3,2,1]); let a = from_vec(~[5,4,3,2,1]);
a.clear(); a.clear();
assert a.len() == 0; fail_unless!(a.len() == 0);
a.assert_consistent(); a.assert_consistent();
} }
#[test] #[test]
pub fn test_dlist_is_empty() { pub fn test_dlist_is_empty() {
let empty = DList::<int>(); let empty = DList::<int>();
let full1 = from_vec(~[1,2,3]); let full1 = from_vec(~[1,2,3]);
assert empty.is_empty(); fail_unless!(empty.is_empty());
assert !full1.is_empty(); fail_unless!(!full1.is_empty());
} }
#[test] #[test]
pub fn test_dlist_head_tail() { pub fn test_dlist_head_tail() {
let l = from_vec(~[1,2,3]); let l = from_vec(~[1,2,3]);
assert l.head() == 1; fail_unless!(l.head() == 1);
assert l.tail() == 3; fail_unless!(l.tail() == 3);
assert l.len() == 3; fail_unless!(l.len() == 3);
} }
#[test] #[test]
pub fn test_dlist_pop() { pub fn test_dlist_pop() {
let l = from_vec(~[1,2,3]); let l = from_vec(~[1,2,3]);
assert l.pop().get() == 1; fail_unless!(l.pop().get() == 1);
assert l.tail() == 3; fail_unless!(l.tail() == 3);
assert l.head() == 2; fail_unless!(l.head() == 2);
assert l.pop().get() == 2; fail_unless!(l.pop().get() == 2);
assert l.tail() == 3; fail_unless!(l.tail() == 3);
assert l.head() == 3; fail_unless!(l.head() == 3);
assert l.pop().get() == 3; fail_unless!(l.pop().get() == 3);
assert l.is_empty(); fail_unless!(l.is_empty());
assert l.pop().is_none(); fail_unless!(l.pop().is_none());
} }
#[test] #[test]
pub fn test_dlist_pop_tail() { pub fn test_dlist_pop_tail() {
let l = from_vec(~[1,2,3]); let l = from_vec(~[1,2,3]);
assert l.pop_tail().get() == 3; fail_unless!(l.pop_tail().get() == 3);
assert l.tail() == 2; fail_unless!(l.tail() == 2);
assert l.head() == 1; fail_unless!(l.head() == 1);
assert l.pop_tail().get() == 2; fail_unless!(l.pop_tail().get() == 2);
assert l.tail() == 1; fail_unless!(l.tail() == 1);
assert l.head() == 1; fail_unless!(l.head() == 1);
assert l.pop_tail().get() == 1; fail_unless!(l.pop_tail().get() == 1);
assert l.is_empty(); fail_unless!(l.is_empty());
assert l.pop_tail().is_none(); fail_unless!(l.pop_tail().is_none());
} }
#[test] #[test]
pub fn test_dlist_push() { pub fn test_dlist_push() {
let l = DList::<int>(); let l = DList::<int>();
l.push(1); l.push(1);
assert l.head() == 1; fail_unless!(l.head() == 1);
assert l.tail() == 1; fail_unless!(l.tail() == 1);
l.push(2); l.push(2);
assert l.head() == 1; fail_unless!(l.head() == 1);
assert l.tail() == 2; fail_unless!(l.tail() == 2);
l.push(3); l.push(3);
assert l.head() == 1; fail_unless!(l.head() == 1);
assert l.tail() == 3; fail_unless!(l.tail() == 3);
assert l.len() == 3; fail_unless!(l.len() == 3);
} }
#[test] #[test]
pub fn test_dlist_push_head() { pub fn test_dlist_push_head() {
let l = DList::<int>(); let l = DList::<int>();
l.push_head(3); l.push_head(3);
assert l.head() == 3; fail_unless!(l.head() == 3);
assert l.tail() == 3; fail_unless!(l.tail() == 3);
l.push_head(2); l.push_head(2);
assert l.head() == 2; fail_unless!(l.head() == 2);
assert l.tail() == 3; fail_unless!(l.tail() == 3);
l.push_head(1); l.push_head(1);
assert l.head() == 1; fail_unless!(l.head() == 1);
assert l.tail() == 3; fail_unless!(l.tail() == 3);
assert l.len() == 3; fail_unless!(l.len() == 3);
} }
#[test] #[test]
pub fn test_dlist_foldl() { pub fn test_dlist_foldl() {
let l = from_vec(vec::from_fn(101, |x|x)); let l = from_vec(vec::from_fn(101, |x|x));
assert iter::foldl(&l, 0, |accum,elem| *accum+*elem) == 5050; fail_unless!(iter::foldl(&l, 0, |accum,elem| *accum+*elem) == 5050);
} }
#[test] #[test]
pub fn test_dlist_break_early() { pub fn test_dlist_break_early() {
@ -730,7 +730,7 @@ mod tests {
x += 1; x += 1;
if (*i == 3) { break; } if (*i == 3) { break; }
} }
assert x == 3; fail_unless!(x == 3);
} }
#[test] #[test]
pub fn test_dlist_remove_head() { pub fn test_dlist_remove_head() {
@ -738,14 +738,14 @@ mod tests {
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
l.assert_consistent(); let _three = l.push_n(3); l.assert_consistent(); let _three = l.push_n(3);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); l.remove(one); l.assert_consistent(); l.remove(one);
l.assert_consistent(); assert l.len() == 2; l.assert_consistent(); fail_unless!(l.len() == 2);
l.assert_consistent(); assert l.head() == 2; l.assert_consistent(); fail_unless!(l.head() == 2);
l.assert_consistent(); assert l.tail() == 3; l.assert_consistent(); fail_unless!(l.tail() == 3);
l.assert_consistent(); assert l.pop().get() == 2; l.assert_consistent(); fail_unless!(l.pop().get() == 2);
l.assert_consistent(); assert l.pop().get() == 3; l.assert_consistent(); fail_unless!(l.pop().get() == 3);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_mid() { pub fn test_dlist_remove_mid() {
@ -753,14 +753,14 @@ mod tests {
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
l.assert_consistent(); let _three = l.push_n(3); l.assert_consistent(); let _three = l.push_n(3);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); l.remove(two); l.assert_consistent(); l.remove(two);
l.assert_consistent(); assert l.len() == 2; l.assert_consistent(); fail_unless!(l.len() == 2);
l.assert_consistent(); assert l.head() == 1; l.assert_consistent(); fail_unless!(l.head() == 1);
l.assert_consistent(); assert l.tail() == 3; l.assert_consistent(); fail_unless!(l.tail() == 3);
l.assert_consistent(); assert l.pop().get() == 1; l.assert_consistent(); fail_unless!(l.pop().get() == 1);
l.assert_consistent(); assert l.pop().get() == 3; l.assert_consistent(); fail_unless!(l.pop().get() == 3);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_tail() { pub fn test_dlist_remove_tail() {
@ -768,14 +768,14 @@ mod tests {
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
l.assert_consistent(); let three = l.push_n(3); l.assert_consistent(); let three = l.push_n(3);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); l.remove(three); l.assert_consistent(); l.remove(three);
l.assert_consistent(); assert l.len() == 2; l.assert_consistent(); fail_unless!(l.len() == 2);
l.assert_consistent(); assert l.head() == 1; l.assert_consistent(); fail_unless!(l.head() == 1);
l.assert_consistent(); assert l.tail() == 2; l.assert_consistent(); fail_unless!(l.tail() == 2);
l.assert_consistent(); assert l.pop().get() == 1; l.assert_consistent(); fail_unless!(l.pop().get() == 1);
l.assert_consistent(); assert l.pop().get() == 2; l.assert_consistent(); fail_unless!(l.pop().get() == 2);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_one_two() { pub fn test_dlist_remove_one_two() {
@ -783,15 +783,15 @@ mod tests {
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
l.assert_consistent(); let _three = l.push_n(3); l.assert_consistent(); let _three = l.push_n(3);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); l.remove(one); l.assert_consistent(); l.remove(one);
l.assert_consistent(); l.remove(two); l.assert_consistent(); l.remove(two);
// and through and through, the vorpal blade went snicker-snack // and through and through, the vorpal blade went snicker-snack
l.assert_consistent(); assert l.len() == 1; l.assert_consistent(); fail_unless!(l.len() == 1);
l.assert_consistent(); assert l.head() == 3; l.assert_consistent(); fail_unless!(l.head() == 3);
l.assert_consistent(); assert l.tail() == 3; l.assert_consistent(); fail_unless!(l.tail() == 3);
l.assert_consistent(); assert l.pop().get() == 3; l.assert_consistent(); fail_unless!(l.pop().get() == 3);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_one_three() { pub fn test_dlist_remove_one_three() {
@ -799,14 +799,14 @@ mod tests {
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
l.assert_consistent(); let three = l.push_n(3); l.assert_consistent(); let three = l.push_n(3);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); l.remove(one); l.assert_consistent(); l.remove(one);
l.assert_consistent(); l.remove(three); l.assert_consistent(); l.remove(three);
l.assert_consistent(); assert l.len() == 1; l.assert_consistent(); fail_unless!(l.len() == 1);
l.assert_consistent(); assert l.head() == 2; l.assert_consistent(); fail_unless!(l.head() == 2);
l.assert_consistent(); assert l.tail() == 2; l.assert_consistent(); fail_unless!(l.tail() == 2);
l.assert_consistent(); assert l.pop().get() == 2; l.assert_consistent(); fail_unless!(l.pop().get() == 2);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_two_three() { pub fn test_dlist_remove_two_three() {
@ -814,14 +814,14 @@ mod tests {
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
l.assert_consistent(); let three = l.push_n(3); l.assert_consistent(); let three = l.push_n(3);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); l.remove(two); l.assert_consistent(); l.remove(two);
l.assert_consistent(); l.remove(three); l.assert_consistent(); l.remove(three);
l.assert_consistent(); assert l.len() == 1; l.assert_consistent(); fail_unless!(l.len() == 1);
l.assert_consistent(); assert l.head() == 1; l.assert_consistent(); fail_unless!(l.head() == 1);
l.assert_consistent(); assert l.tail() == 1; l.assert_consistent(); fail_unless!(l.tail() == 1);
l.assert_consistent(); assert l.pop().get() == 1; l.assert_consistent(); fail_unless!(l.pop().get() == 1);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_all() { pub fn test_dlist_remove_all() {
@ -829,12 +829,12 @@ mod tests {
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
l.assert_consistent(); let three = l.push_n(3); l.assert_consistent(); let three = l.push_n(3);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); l.remove(two); l.assert_consistent(); l.remove(two);
l.assert_consistent(); l.remove(three); l.assert_consistent(); l.remove(three);
l.assert_consistent(); l.remove(one); // Twenty-three is number one! l.assert_consistent(); l.remove(one); // Twenty-three is number one!
l.assert_consistent(); assert l.peek().is_none(); l.assert_consistent(); fail_unless!(l.peek().is_none());
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_n_before() { pub fn test_dlist_insert_n_before() {
@ -842,15 +842,15 @@ mod tests {
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
l.assert_consistent(); let three = new_dlist_node(3); l.assert_consistent(); let three = new_dlist_node(3);
l.assert_consistent(); assert l.len() == 2; l.assert_consistent(); fail_unless!(l.len() == 2);
l.assert_consistent(); l.insert_n_before(three, two); l.assert_consistent(); l.insert_n_before(three, two);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); assert l.head() == 1; l.assert_consistent(); fail_unless!(l.head() == 1);
l.assert_consistent(); assert l.tail() == 2; l.assert_consistent(); fail_unless!(l.tail() == 2);
l.assert_consistent(); assert l.pop().get() == 1; l.assert_consistent(); fail_unless!(l.pop().get() == 1);
l.assert_consistent(); assert l.pop().get() == 3; l.assert_consistent(); fail_unless!(l.pop().get() == 3);
l.assert_consistent(); assert l.pop().get() == 2; l.assert_consistent(); fail_unless!(l.pop().get() == 2);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_n_after() { pub fn test_dlist_insert_n_after() {
@ -858,45 +858,45 @@ mod tests {
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
l.assert_consistent(); let three = new_dlist_node(3); l.assert_consistent(); let three = new_dlist_node(3);
l.assert_consistent(); assert l.len() == 2; l.assert_consistent(); fail_unless!(l.len() == 2);
l.assert_consistent(); l.insert_n_after(three, one); l.assert_consistent(); l.insert_n_after(three, one);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); assert l.head() == 1; l.assert_consistent(); fail_unless!(l.head() == 1);
l.assert_consistent(); assert l.tail() == 2; l.assert_consistent(); fail_unless!(l.tail() == 2);
l.assert_consistent(); assert l.pop().get() == 1; l.assert_consistent(); fail_unless!(l.pop().get() == 1);
l.assert_consistent(); assert l.pop().get() == 3; l.assert_consistent(); fail_unless!(l.pop().get() == 3);
l.assert_consistent(); assert l.pop().get() == 2; l.assert_consistent(); fail_unless!(l.pop().get() == 2);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_before_head() { pub fn test_dlist_insert_before_head() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
l.assert_consistent(); assert l.len() == 2; l.assert_consistent(); fail_unless!(l.len() == 2);
l.assert_consistent(); l.insert_before(3, one); l.assert_consistent(); l.insert_before(3, one);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); assert l.head() == 3; l.assert_consistent(); fail_unless!(l.head() == 3);
l.assert_consistent(); assert l.tail() == 2; l.assert_consistent(); fail_unless!(l.tail() == 2);
l.assert_consistent(); assert l.pop().get() == 3; l.assert_consistent(); fail_unless!(l.pop().get() == 3);
l.assert_consistent(); assert l.pop().get() == 1; l.assert_consistent(); fail_unless!(l.pop().get() == 1);
l.assert_consistent(); assert l.pop().get() == 2; l.assert_consistent(); fail_unless!(l.pop().get() == 2);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_after_tail() { pub fn test_dlist_insert_after_tail() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
l.assert_consistent(); assert l.len() == 2; l.assert_consistent(); fail_unless!(l.len() == 2);
l.assert_consistent(); l.insert_after(3, two); l.assert_consistent(); l.insert_after(3, two);
l.assert_consistent(); assert l.len() == 3; l.assert_consistent(); fail_unless!(l.len() == 3);
l.assert_consistent(); assert l.head() == 1; l.assert_consistent(); fail_unless!(l.head() == 1);
l.assert_consistent(); assert l.tail() == 3; l.assert_consistent(); fail_unless!(l.tail() == 3);
l.assert_consistent(); assert l.pop().get() == 1; l.assert_consistent(); fail_unless!(l.pop().get() == 1);
l.assert_consistent(); assert l.pop().get() == 2; l.assert_consistent(); fail_unless!(l.pop().get() == 2);
l.assert_consistent(); assert l.pop().get() == 3; l.assert_consistent(); fail_unless!(l.pop().get() == 3);
l.assert_consistent(); assert l.is_empty(); l.assert_consistent(); fail_unless!(l.is_empty());
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_asymmetric_link() { pub fn test_dlist_asymmetric_link() {

View file

@ -176,7 +176,7 @@ fn test_either_left() {
let val = Left(10); let val = Left(10);
fn f_left(x: &int) -> bool { *x == 10 } fn f_left(x: &int) -> bool { *x == 10 }
fn f_right(_x: &uint) -> bool { false } fn f_right(_x: &uint) -> bool { false }
assert (either(f_left, f_right, &val)); fail_unless!((either(f_left, f_right, &val)));
} }
#[test] #[test]
@ -184,84 +184,84 @@ fn test_either_right() {
let val = Right(10u); let val = Right(10u);
fn f_left(_x: &int) -> bool { false } fn f_left(_x: &int) -> bool { false }
fn f_right(x: &uint) -> bool { *x == 10u } fn f_right(x: &uint) -> bool { *x == 10u }
assert (either(f_left, f_right, &val)); fail_unless!((either(f_left, f_right, &val)));
} }
#[test] #[test]
fn test_lefts() { fn test_lefts() {
let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)];
let result = lefts(input); let result = lefts(input);
assert (result == ~[10, 12, 14]); fail_unless!((result == ~[10, 12, 14]));
} }
#[test] #[test]
fn test_lefts_none() { fn test_lefts_none() {
let input: ~[Either<int, int>] = ~[Right(10), Right(10)]; let input: ~[Either<int, int>] = ~[Right(10), Right(10)];
let result = lefts(input); let result = lefts(input);
assert (vec::len(result) == 0u); fail_unless!((vec::len(result) == 0u));
} }
#[test] #[test]
fn test_lefts_empty() { fn test_lefts_empty() {
let input: ~[Either<int, int>] = ~[]; let input: ~[Either<int, int>] = ~[];
let result = lefts(input); let result = lefts(input);
assert (vec::len(result) == 0u); fail_unless!((vec::len(result) == 0u));
} }
#[test] #[test]
fn test_rights() { fn test_rights() {
let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)];
let result = rights(input); let result = rights(input);
assert (result == ~[11, 13]); fail_unless!((result == ~[11, 13]));
} }
#[test] #[test]
fn test_rights_none() { fn test_rights_none() {
let input: ~[Either<int, int>] = ~[Left(10), Left(10)]; let input: ~[Either<int, int>] = ~[Left(10), Left(10)];
let result = rights(input); let result = rights(input);
assert (vec::len(result) == 0u); fail_unless!((vec::len(result) == 0u));
} }
#[test] #[test]
fn test_rights_empty() { fn test_rights_empty() {
let input: ~[Either<int, int>] = ~[]; let input: ~[Either<int, int>] = ~[];
let result = rights(input); let result = rights(input);
assert (vec::len(result) == 0u); fail_unless!((vec::len(result) == 0u));
} }
#[test] #[test]
fn test_partition() { fn test_partition() {
let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)];
let (lefts, rights) = partition(input); let (lefts, rights) = partition(input);
assert (lefts[0] == 10); fail_unless!((lefts[0] == 10));
assert (lefts[1] == 12); fail_unless!((lefts[1] == 12));
assert (lefts[2] == 14); fail_unless!((lefts[2] == 14));
assert (rights[0] == 11); fail_unless!((rights[0] == 11));
assert (rights[1] == 13); fail_unless!((rights[1] == 13));
} }
#[test] #[test]
fn test_partition_no_lefts() { fn test_partition_no_lefts() {
let input: ~[Either<int, int>] = ~[Right(10), Right(11)]; let input: ~[Either<int, int>] = ~[Right(10), Right(11)];
let (lefts, rights) = partition(input); let (lefts, rights) = partition(input);
assert (vec::len(lefts) == 0u); fail_unless!((vec::len(lefts) == 0u));
assert (vec::len(rights) == 2u); fail_unless!((vec::len(rights) == 2u));
} }
#[test] #[test]
fn test_partition_no_rights() { fn test_partition_no_rights() {
let input: ~[Either<int, int>] = ~[Left(10), Left(11)]; let input: ~[Either<int, int>] = ~[Left(10), Left(11)];
let (lefts, rights) = partition(input); let (lefts, rights) = partition(input);
assert (vec::len(lefts) == 2u); fail_unless!((vec::len(lefts) == 2u));
assert (vec::len(rights) == 0u); fail_unless!((vec::len(rights) == 0u));
} }
#[test] #[test]
fn test_partition_empty() { fn test_partition_empty() {
let input: ~[Either<int, int>] = ~[]; let input: ~[Either<int, int>] = ~[];
let (lefts, rights) = partition(input); let (lefts, rights) = partition(input);
assert (vec::len(lefts) == 0u); fail_unless!((vec::len(lefts) == 0u));
assert (vec::len(rights) == 0u); fail_unless!((vec::len(rights) == 0u));
} }
// //

View file

@ -54,7 +54,7 @@ pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] {
len as size_t, len as size_t,
ptr::addr_of(&outsz), ptr::addr_of(&outsz),
lz_norm); lz_norm);
assert res as int != 0; fail_unless!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8, let out = vec::raw::from_buf_raw(res as *u8,
outsz as uint); outsz as uint);
libc::free(res); libc::free(res);
@ -72,7 +72,7 @@ pub fn inflate_bytes(bytes: &[const u8]) -> ~[u8] {
len as size_t, len as size_t,
ptr::addr_of(&outsz), ptr::addr_of(&outsz),
0); 0);
assert res as int != 0; fail_unless!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8, let out = vec::raw::from_buf_raw(res as *u8,
outsz as uint); outsz as uint);
libc::free(res); libc::free(res);
@ -101,6 +101,6 @@ fn test_flate_round_trip() {
debug!("%u bytes deflated to %u (%.1f%% size)", debug!("%u bytes deflated to %u (%.1f%% size)",
in.len(), cmp.len(), in.len(), cmp.len(),
100.0 * ((cmp.len() as float) / (in.len() as float))); 100.0 * ((cmp.len() as float) / (in.len() as float)));
assert(in == out); fail_unless!((in == out));
} }
} }

View file

@ -458,7 +458,7 @@ pub fn test_siphash() {
let vec = u8to64_le!(vecs[t], 0); let vec = u8to64_le!(vecs[t], 0);
let out = buf.hash_keyed(k0, k1); let out = buf.hash_keyed(k0, k1);
debug!("got %?, expected %?", out, vec); debug!("got %?, expected %?", out, vec);
assert vec == out; fail_unless!(vec == out);
stream_full.reset(); stream_full.reset();
stream_full.input(buf); stream_full.input(buf);
@ -467,7 +467,7 @@ pub fn test_siphash() {
let v = to_hex_str(&vecs[t]); let v = to_hex_str(&vecs[t]);
debug!("%d: (%s) => inc=%s full=%s", t, v, i, f); debug!("%d: (%s) => inc=%s full=%s", t, v, i, f);
assert f == i && f == v; fail_unless!(f == i && f == v);
buf += ~[t as u8]; buf += ~[t as u8];
stream_inc.input(~[t as u8]); stream_inc.input(~[t as u8]);
@ -479,20 +479,20 @@ pub fn test_siphash() {
#[test] #[cfg(target_arch = "arm")] #[test] #[cfg(target_arch = "arm")]
pub fn test_hash_uint() { pub fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64; let val = 0xdeadbeef_deadbeef_u64;
assert (val as u64).hash() != (val as uint).hash(); fail_unless!((val as u64).hash() != (val as uint).hash());
assert (val as u32).hash() == (val as uint).hash(); fail_unless!((val as u32).hash() == (val as uint).hash());
} }
#[test] #[cfg(target_arch = "x86_64")] #[test] #[cfg(target_arch = "x86_64")]
pub fn test_hash_uint() { pub fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64; let val = 0xdeadbeef_deadbeef_u64;
assert (val as u64).hash() == (val as uint).hash(); fail_unless!((val as u64).hash() == (val as uint).hash());
assert (val as u32).hash() != (val as uint).hash(); fail_unless!((val as u32).hash() != (val as uint).hash());
} }
#[test] #[cfg(target_arch = "x86")] #[test] #[cfg(target_arch = "x86")]
pub fn test_hash_uint() { pub fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64; let val = 0xdeadbeef_deadbeef_u64;
assert (val as u64).hash() != (val as uint).hash(); fail_unless!((val as u64).hash() != (val as uint).hash());
assert (val as u32).hash() == (val as uint).hash(); fail_unless!((val as u32).hash() == (val as uint).hash());
} }
#[test] #[test]
@ -507,17 +507,17 @@ pub fn test_hash_idempotent() {
pub fn test_hash_no_bytes_dropped_64() { pub fn test_hash_no_bytes_dropped_64() {
let val = 0xdeadbeef_deadbeef_u64; let val = 0xdeadbeef_deadbeef_u64;
assert val.hash() != zero_byte(val, 0).hash(); fail_unless!(val.hash() != zero_byte(val, 0).hash());
assert val.hash() != zero_byte(val, 1).hash(); fail_unless!(val.hash() != zero_byte(val, 1).hash());
assert val.hash() != zero_byte(val, 2).hash(); fail_unless!(val.hash() != zero_byte(val, 2).hash());
assert val.hash() != zero_byte(val, 3).hash(); fail_unless!(val.hash() != zero_byte(val, 3).hash());
assert val.hash() != zero_byte(val, 4).hash(); fail_unless!(val.hash() != zero_byte(val, 4).hash());
assert val.hash() != zero_byte(val, 5).hash(); fail_unless!(val.hash() != zero_byte(val, 5).hash());
assert val.hash() != zero_byte(val, 6).hash(); fail_unless!(val.hash() != zero_byte(val, 6).hash());
assert val.hash() != zero_byte(val, 7).hash(); fail_unless!(val.hash() != zero_byte(val, 7).hash());
fn zero_byte(val: u64, byte: uint) -> u64 { fn zero_byte(val: u64, byte: uint) -> u64 {
assert byte < 8; fail_unless!(byte < 8);
val & !(0xff << (byte * 8)) val & !(0xff << (byte * 8))
} }
} }
@ -526,13 +526,13 @@ pub fn test_hash_no_bytes_dropped_64() {
pub fn test_hash_no_bytes_dropped_32() { pub fn test_hash_no_bytes_dropped_32() {
let val = 0xdeadbeef_u32; let val = 0xdeadbeef_u32;
assert val.hash() != zero_byte(val, 0).hash(); fail_unless!(val.hash() != zero_byte(val, 0).hash());
assert val.hash() != zero_byte(val, 1).hash(); fail_unless!(val.hash() != zero_byte(val, 1).hash());
assert val.hash() != zero_byte(val, 2).hash(); fail_unless!(val.hash() != zero_byte(val, 2).hash());
assert val.hash() != zero_byte(val, 3).hash(); fail_unless!(val.hash() != zero_byte(val, 3).hash());
fn zero_byte(val: u32, byte: uint) -> u32 { fn zero_byte(val: u32, byte: uint) -> u32 {
assert byte < 4; fail_unless!(byte < 4);
val & !(0xff << (byte * 8)) val & !(0xff << (byte * 8))
} }
} }

View file

@ -642,119 +642,119 @@ pub mod linear {
#[test] #[test]
pub fn test_insert() { pub fn test_insert() {
let mut m = LinearMap::new(); let mut m = LinearMap::new();
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
assert m.insert(2, 4); fail_unless!(m.insert(2, 4));
assert *m.get(&1) == 2; fail_unless!(*m.get(&1) == 2);
assert *m.get(&2) == 4; fail_unless!(*m.get(&2) == 4);
} }
#[test] #[test]
pub fn test_insert_overwrite() { pub fn test_insert_overwrite() {
let mut m = LinearMap::new(); let mut m = LinearMap::new();
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
assert *m.get(&1) == 2; fail_unless!(*m.get(&1) == 2);
assert !m.insert(1, 3); fail_unless!(!m.insert(1, 3));
assert *m.get(&1) == 3; fail_unless!(*m.get(&1) == 3);
} }
#[test] #[test]
pub fn test_insert_conflicts() { pub fn test_insert_conflicts() {
let mut m = linear::linear_map_with_capacity(4); let mut m = linear::linear_map_with_capacity(4);
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
assert m.insert(5, 3); fail_unless!(m.insert(5, 3));
assert m.insert(9, 4); fail_unless!(m.insert(9, 4));
assert *m.get(&9) == 4; fail_unless!(*m.get(&9) == 4);
assert *m.get(&5) == 3; fail_unless!(*m.get(&5) == 3);
assert *m.get(&1) == 2; fail_unless!(*m.get(&1) == 2);
} }
#[test] #[test]
pub fn test_conflict_remove() { pub fn test_conflict_remove() {
let mut m = linear::linear_map_with_capacity(4); let mut m = linear::linear_map_with_capacity(4);
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
assert m.insert(5, 3); fail_unless!(m.insert(5, 3));
assert m.insert(9, 4); fail_unless!(m.insert(9, 4));
assert m.remove(&1); fail_unless!(m.remove(&1));
assert *m.get(&9) == 4; fail_unless!(*m.get(&9) == 4);
assert *m.get(&5) == 3; fail_unless!(*m.get(&5) == 3);
} }
#[test] #[test]
pub fn test_is_empty() { pub fn test_is_empty() {
let mut m = linear::linear_map_with_capacity(4); let mut m = linear::linear_map_with_capacity(4);
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
assert !m.is_empty(); fail_unless!(!m.is_empty());
assert m.remove(&1); fail_unless!(m.remove(&1));
assert m.is_empty(); fail_unless!(m.is_empty());
} }
#[test] #[test]
pub fn test_pop() { pub fn test_pop() {
let mut m = LinearMap::new(); let mut m = LinearMap::new();
m.insert(1, 2); m.insert(1, 2);
assert m.pop(&1) == Some(2); fail_unless!(m.pop(&1) == Some(2));
assert m.pop(&1) == None; fail_unless!(m.pop(&1) == None);
} }
#[test] #[test]
pub fn test_swap() { pub fn test_swap() {
let mut m = LinearMap::new(); let mut m = LinearMap::new();
assert m.swap(1, 2) == None; fail_unless!(m.swap(1, 2) == None);
assert m.swap(1, 3) == Some(2); fail_unless!(m.swap(1, 3) == Some(2));
assert m.swap(1, 4) == Some(3); fail_unless!(m.swap(1, 4) == Some(3));
} }
#[test] #[test]
pub fn test_find_or_insert() { pub fn test_find_or_insert() {
let mut m = LinearMap::new::<int, int>(); let mut m = LinearMap::new::<int, int>();
assert m.find_or_insert(1, 2) == &2; fail_unless!(m.find_or_insert(1, 2) == &2);
assert m.find_or_insert(1, 3) == &2; fail_unless!(m.find_or_insert(1, 3) == &2);
} }
#[test] #[test]
pub fn test_find_or_insert_with() { pub fn test_find_or_insert_with() {
let mut m = LinearMap::new::<int, int>(); let mut m = LinearMap::new::<int, int>();
assert m.find_or_insert_with(1, |_| 2) == &2; fail_unless!(m.find_or_insert_with(1, |_| 2) == &2);
assert m.find_or_insert_with(1, |_| 3) == &2; fail_unless!(m.find_or_insert_with(1, |_| 3) == &2);
} }
#[test] #[test]
pub fn test_consume() { pub fn test_consume() {
let mut m = LinearMap::new(); let mut m = LinearMap::new();
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
assert m.insert(2, 3); fail_unless!(m.insert(2, 3));
let mut m2 = LinearMap::new(); let mut m2 = LinearMap::new();
do m.consume |k, v| { do m.consume |k, v| {
m2.insert(k, v); m2.insert(k, v);
} }
assert m.len() == 0; fail_unless!(m.len() == 0);
assert m2.len() == 2; fail_unless!(m2.len() == 2);
assert m2.get(&1) == &2; fail_unless!(m2.get(&1) == &2);
assert m2.get(&2) == &3; fail_unless!(m2.get(&2) == &3);
} }
#[test] #[test]
pub fn test_iterate() { pub fn test_iterate() {
let mut m = linear::linear_map_with_capacity(4); let mut m = linear::linear_map_with_capacity(4);
for uint::range(0, 32) |i| { for uint::range(0, 32) |i| {
assert m.insert(i, i*2); fail_unless!(m.insert(i, i*2));
} }
let mut observed = 0; let mut observed = 0;
for m.each |&(k, v)| { for m.each |&(k, v)| {
assert *v == *k * 2; fail_unless!(*v == *k * 2);
observed |= (1 << *k); observed |= (1 << *k);
} }
assert observed == 0xFFFF_FFFF; fail_unless!(observed == 0xFFFF_FFFF);
} }
#[test] #[test]
pub fn test_find() { pub fn test_find() {
let mut m = LinearMap::new(); let mut m = LinearMap::new();
assert m.find(&1).is_none(); fail_unless!(m.find(&1).is_none());
m.insert(1, 2); m.insert(1, 2);
match m.find(&1) { match m.find(&1) {
None => fail!(), None => fail!(),
Some(v) => assert *v == 2 Some(v) => fail_unless!(*v == 2)
} }
} }
@ -769,19 +769,19 @@ pub mod linear {
m2.insert(1, 2); m2.insert(1, 2);
m2.insert(2, 3); m2.insert(2, 3);
assert m1 != m2; fail_unless!(m1 != m2);
m2.insert(3, 4); m2.insert(3, 4);
assert m1 == m2; fail_unless!(m1 == m2);
} }
#[test] #[test]
pub fn test_expand() { pub fn test_expand() {
let mut m = LinearMap::new(); let mut m = LinearMap::new();
assert m.len() == 0; fail_unless!(m.len() == 0);
assert m.is_empty(); fail_unless!(m.is_empty());
let mut i = 0u; let mut i = 0u;
let old_resize_at = m.resize_at; let old_resize_at = m.resize_at;
@ -790,8 +790,8 @@ pub mod linear {
i += 1; i += 1;
} }
assert m.len() == i; fail_unless!(m.len() == i);
assert !m.is_empty(); fail_unless!(!m.is_empty());
} }
} }
@ -805,51 +805,51 @@ pub mod linear {
fn test_disjoint() { fn test_disjoint() {
let mut xs = linear::LinearSet::new(); let mut xs = linear::LinearSet::new();
let mut ys = linear::LinearSet::new(); let mut ys = linear::LinearSet::new();
assert xs.is_disjoint(&ys); fail_unless!(xs.is_disjoint(&ys));
assert ys.is_disjoint(&xs); fail_unless!(ys.is_disjoint(&xs));
assert xs.insert(5); fail_unless!(xs.insert(5));
assert ys.insert(11); fail_unless!(ys.insert(11));
assert xs.is_disjoint(&ys); fail_unless!(xs.is_disjoint(&ys));
assert ys.is_disjoint(&xs); fail_unless!(ys.is_disjoint(&xs));
assert xs.insert(7); fail_unless!(xs.insert(7));
assert xs.insert(19); fail_unless!(xs.insert(19));
assert xs.insert(4); fail_unless!(xs.insert(4));
assert ys.insert(2); fail_unless!(ys.insert(2));
assert ys.insert(-11); fail_unless!(ys.insert(-11));
assert xs.is_disjoint(&ys); fail_unless!(xs.is_disjoint(&ys));
assert ys.is_disjoint(&xs); fail_unless!(ys.is_disjoint(&xs));
assert ys.insert(7); fail_unless!(ys.insert(7));
assert !xs.is_disjoint(&ys); fail_unless!(!xs.is_disjoint(&ys));
assert !ys.is_disjoint(&xs); fail_unless!(!ys.is_disjoint(&xs));
} }
#[test] #[test]
fn test_subset_and_superset() { fn test_subset_and_superset() {
let mut a = linear::LinearSet::new(); let mut a = linear::LinearSet::new();
assert a.insert(0); fail_unless!(a.insert(0));
assert a.insert(5); fail_unless!(a.insert(5));
assert a.insert(11); fail_unless!(a.insert(11));
assert a.insert(7); fail_unless!(a.insert(7));
let mut b = linear::LinearSet::new(); let mut b = linear::LinearSet::new();
assert b.insert(0); fail_unless!(b.insert(0));
assert b.insert(7); fail_unless!(b.insert(7));
assert b.insert(19); fail_unless!(b.insert(19));
assert b.insert(250); fail_unless!(b.insert(250));
assert b.insert(11); fail_unless!(b.insert(11));
assert b.insert(200); fail_unless!(b.insert(200));
assert !a.is_subset(&b); fail_unless!(!a.is_subset(&b));
assert !a.is_superset(&b); fail_unless!(!a.is_superset(&b));
assert !b.is_subset(&a); fail_unless!(!b.is_subset(&a));
assert !b.is_superset(&a); fail_unless!(!b.is_superset(&a));
assert b.insert(5); fail_unless!(b.insert(5));
assert a.is_subset(&b); fail_unless!(a.is_subset(&b));
assert !a.is_superset(&b); fail_unless!(!a.is_superset(&b));
assert !b.is_subset(&a); fail_unless!(!b.is_subset(&a));
assert b.is_superset(&a); fail_unless!(b.is_superset(&a));
} }
#[test] #[test]
@ -857,29 +857,29 @@ pub mod linear {
let mut a = linear::LinearSet::new(); let mut a = linear::LinearSet::new();
let mut b = linear::LinearSet::new(); let mut b = linear::LinearSet::new();
assert a.insert(11); fail_unless!(a.insert(11));
assert a.insert(1); fail_unless!(a.insert(1));
assert a.insert(3); fail_unless!(a.insert(3));
assert a.insert(77); fail_unless!(a.insert(77));
assert a.insert(103); fail_unless!(a.insert(103));
assert a.insert(5); fail_unless!(a.insert(5));
assert a.insert(-5); fail_unless!(a.insert(-5));
assert b.insert(2); fail_unless!(b.insert(2));
assert b.insert(11); fail_unless!(b.insert(11));
assert b.insert(77); fail_unless!(b.insert(77));
assert b.insert(-9); fail_unless!(b.insert(-9));
assert b.insert(-42); fail_unless!(b.insert(-42));
assert b.insert(5); fail_unless!(b.insert(5));
assert b.insert(3); fail_unless!(b.insert(3));
let mut i = 0; let mut i = 0;
let expected = [3, 5, 11, 77]; let expected = [3, 5, 11, 77];
for a.intersection(&b) |x| { for a.intersection(&b) |x| {
assert vec::contains(expected, x); fail_unless!(vec::contains(expected, x));
i += 1 i += 1
} }
assert i == expected.len(); fail_unless!(i == expected.len());
} }
#[test] #[test]
@ -887,22 +887,22 @@ pub mod linear {
let mut a = linear::LinearSet::new(); let mut a = linear::LinearSet::new();
let mut b = linear::LinearSet::new(); let mut b = linear::LinearSet::new();
assert a.insert(1); fail_unless!(a.insert(1));
assert a.insert(3); fail_unless!(a.insert(3));
assert a.insert(5); fail_unless!(a.insert(5));
assert a.insert(9); fail_unless!(a.insert(9));
assert a.insert(11); fail_unless!(a.insert(11));
assert b.insert(3); fail_unless!(b.insert(3));
assert b.insert(9); fail_unless!(b.insert(9));
let mut i = 0; let mut i = 0;
let expected = [1, 5, 11]; let expected = [1, 5, 11];
for a.difference(&b) |x| { for a.difference(&b) |x| {
assert vec::contains(expected, x); fail_unless!(vec::contains(expected, x));
i += 1 i += 1
} }
assert i == expected.len(); fail_unless!(i == expected.len());
} }
#[test] #[test]
@ -910,25 +910,25 @@ pub mod linear {
let mut a = linear::LinearSet::new(); let mut a = linear::LinearSet::new();
let mut b = linear::LinearSet::new(); let mut b = linear::LinearSet::new();
assert a.insert(1); fail_unless!(a.insert(1));
assert a.insert(3); fail_unless!(a.insert(3));
assert a.insert(5); fail_unless!(a.insert(5));
assert a.insert(9); fail_unless!(a.insert(9));
assert a.insert(11); fail_unless!(a.insert(11));
assert b.insert(-2); fail_unless!(b.insert(-2));
assert b.insert(3); fail_unless!(b.insert(3));
assert b.insert(9); fail_unless!(b.insert(9));
assert b.insert(14); fail_unless!(b.insert(14));
assert b.insert(22); fail_unless!(b.insert(22));
let mut i = 0; let mut i = 0;
let expected = [-2, 1, 5, 11, 14, 22]; let expected = [-2, 1, 5, 11, 14, 22];
for a.symmetric_difference(&b) |x| { for a.symmetric_difference(&b) |x| {
assert vec::contains(expected, x); fail_unless!(vec::contains(expected, x));
i += 1 i += 1
} }
assert i == expected.len(); fail_unless!(i == expected.len());
} }
#[test] #[test]
@ -936,29 +936,29 @@ pub mod linear {
let mut a = linear::LinearSet::new(); let mut a = linear::LinearSet::new();
let mut b = linear::LinearSet::new(); let mut b = linear::LinearSet::new();
assert a.insert(1); fail_unless!(a.insert(1));
assert a.insert(3); fail_unless!(a.insert(3));
assert a.insert(5); fail_unless!(a.insert(5));
assert a.insert(9); fail_unless!(a.insert(9));
assert a.insert(11); fail_unless!(a.insert(11));
assert a.insert(16); fail_unless!(a.insert(16));
assert a.insert(19); fail_unless!(a.insert(19));
assert a.insert(24); fail_unless!(a.insert(24));
assert b.insert(-2); fail_unless!(b.insert(-2));
assert b.insert(1); fail_unless!(b.insert(1));
assert b.insert(5); fail_unless!(b.insert(5));
assert b.insert(9); fail_unless!(b.insert(9));
assert b.insert(13); fail_unless!(b.insert(13));
assert b.insert(19); fail_unless!(b.insert(19));
let mut i = 0; let mut i = 0;
let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]; let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24];
for a.union(&b) |x| { for a.union(&b) |x| {
assert vec::contains(expected, x); fail_unless!(vec::contains(expected, x));
i += 1 i += 1
} }
assert i == expected.len(); fail_unless!(i == expected.len());
} }
} }
} }

View file

@ -247,7 +247,7 @@ impl<T:Reader> ReaderUtil for T {
let w = str::utf8_char_width(b0); let w = str::utf8_char_width(b0);
let end = i + w; let end = i + w;
i += 1; i += 1;
assert (w > 0); fail_unless!((w > 0));
if w == 1 { if w == 1 {
chars.push(b0 as char); chars.push(b0 as char);
loop; loop;
@ -260,8 +260,8 @@ impl<T:Reader> ReaderUtil for T {
while i < end { while i < end {
let next = bytes[i] as int; let next = bytes[i] as int;
i += 1; i += 1;
assert (next > -1); fail_unless!((next > -1));
assert (next & 192 == 128); fail_unless!((next & 192 == 128));
val <<= 6; val <<= 6;
val += (next & 63) as uint; val += (next & 63) as uint;
} }
@ -302,7 +302,7 @@ impl<T:Reader> ReaderUtil for T {
if vec::len(c) == 0 { if vec::len(c) == 0 {
return -1 as char; // FIXME will this stay valid? // #2004 return -1 as char; // FIXME will this stay valid? // #2004
} }
assert(vec::len(c) == 1); fail_unless!((vec::len(c) == 1));
return c[0]; return c[0];
} }
@ -337,7 +337,7 @@ impl<T:Reader> ReaderUtil for T {
// FIXME int reading methods need to deal with eof - issue #2004 // FIXME int reading methods need to deal with eof - issue #2004
fn read_le_uint_n(&self, nbytes: uint) -> u64 { fn read_le_uint_n(&self, nbytes: uint) -> u64 {
assert nbytes > 0 && nbytes <= 8; fail_unless!(nbytes > 0 && nbytes <= 8);
let mut val = 0u64, pos = 0, i = nbytes; let mut val = 0u64, pos = 0, i = nbytes;
while i > 0 { while i > 0 {
@ -353,7 +353,7 @@ impl<T:Reader> ReaderUtil for T {
} }
fn read_be_uint_n(&self, nbytes: uint) -> u64 { fn read_be_uint_n(&self, nbytes: uint) -> u64 {
assert nbytes > 0 && nbytes <= 8; fail_unless!(nbytes > 0 && nbytes <= 8);
let mut val = 0u64, i = nbytes; let mut val = 0u64, i = nbytes;
while i > 0 { while i > 0 {
@ -483,7 +483,7 @@ impl Reader for *libc::FILE {
fn read(&self, bytes: &mut [u8], len: uint) -> uint { fn read(&self, bytes: &mut [u8], len: uint) -> uint {
unsafe { unsafe {
do vec::as_mut_buf(bytes) |buf_p, buf_len| { do vec::as_mut_buf(bytes) |buf_p, buf_len| {
assert buf_len >= len; fail_unless!(buf_len >= len);
let count = libc::fread(buf_p as *mut c_void, 1u as size_t, let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
len as size_t, *self); len as size_t, *self);
@ -504,9 +504,9 @@ impl Reader for *libc::FILE {
} }
fn seek(&self, offset: int, whence: SeekStyle) { fn seek(&self, offset: int, whence: SeekStyle) {
unsafe { unsafe {
assert libc::fseek(*self, fail_unless!(libc::fseek(*self,
offset as c_long, offset as c_long,
convert_whence(whence)) == 0 as c_int; convert_whence(whence)) == 0 as c_int);
} }
} }
fn tell(&self) -> uint { fn tell(&self) -> uint {
@ -692,9 +692,9 @@ impl Writer for *libc::FILE {
} }
fn seek(&self, offset: int, whence: SeekStyle) { fn seek(&self, offset: int, whence: SeekStyle) {
unsafe { unsafe {
assert libc::fseek(*self, fail_unless!(libc::fseek(*self,
offset as c_long, offset as c_long,
convert_whence(whence)) == 0 as c_int; convert_whence(whence)) == 0 as c_int);
} }
} }
fn tell(&self) -> uint { fn tell(&self) -> uint {
@ -821,7 +821,7 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
pub fn u64_to_le_bytes<T>(n: u64, size: uint, pub fn u64_to_le_bytes<T>(n: u64, size: uint,
f: fn(v: &[u8]) -> T) -> T { f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u; fail_unless!(size <= 8u);
match size { match size {
1u => f(&[n as u8]), 1u => f(&[n as u8]),
2u => f(&[n as u8, 2u => f(&[n as u8,
@ -853,7 +853,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
pub fn u64_to_be_bytes<T>(n: u64, size: uint, pub fn u64_to_be_bytes<T>(n: u64, size: uint,
f: fn(v: &[u8]) -> T) -> T { f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u; fail_unless!(size <= 8u);
match size { match size {
1u => f(&[n as u8]), 1u => f(&[n as u8]),
2u => f(&[(n >> 8) as u8, 2u => f(&[(n >> 8) as u8,
@ -886,7 +886,7 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint,
pub fn u64_from_be_bytes(data: &[const u8], pub fn u64_from_be_bytes(data: &[const u8],
start: uint, size: uint) -> u64 { start: uint, size: uint) -> u64 {
let mut sz = size; let mut sz = size;
assert (sz <= 8u); fail_unless!((sz <= 8u));
let mut val = 0_u64; let mut val = 0_u64;
let mut pos = start; let mut pos = start;
while sz > 0u { while sz > 0u {
@ -1163,7 +1163,7 @@ pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
// Make sure the vector has a trailing null and is proper utf8. // Make sure the vector has a trailing null and is proper utf8.
v.push(0); v.push(0);
} }
assert str::is_utf8(v); fail_unless!(str::is_utf8(v));
unsafe { ::cast::transmute(v) } unsafe { ::cast::transmute(v) }
} }
@ -1235,7 +1235,7 @@ pub mod fsync {
None => (), None => (),
Some(level) => { Some(level) => {
// fail hard if not succesful // fail hard if not succesful
assert((self.arg.fsync_fn)(self.arg.val, level) != -1); fail_unless!(((self.arg.fsync_fn)(self.arg.val, level) != -1));
} }
} }
} }
@ -1320,14 +1320,14 @@ mod tests {
let inp: io::Reader = result::get(&io::file_reader(tmpfile)); let inp: io::Reader = result::get(&io::file_reader(tmpfile));
let frood2: ~str = inp.read_c_str(); let frood2: ~str = inp.read_c_str();
log(debug, copy frood2); log(debug, copy frood2);
assert frood == frood2; fail_unless!(frood == frood2);
} }
#[test] #[test]
fn test_readchars_empty() { fn test_readchars_empty() {
do io::with_str_reader(~"") |inp| { do io::with_str_reader(~"") |inp| {
let res : ~[char] = inp.read_chars(128); let res : ~[char] = inp.read_chars(128);
assert(vec::len(res) == 0); fail_unless!((vec::len(res) == 0));
} }
} }
@ -1335,7 +1335,7 @@ mod tests {
fn test_read_line_utf8() { fn test_read_line_utf8() {
do io::with_str_reader(~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| { do io::with_str_reader(~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| {
let line = inp.read_line(); let line = inp.read_line();
assert line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤"; fail_unless!(line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤");
} }
} }
@ -1352,10 +1352,10 @@ mod tests {
do io::with_str_reader(s) |inp| { do io::with_str_reader(s) |inp| {
let res : ~[char] = inp.read_chars(len); let res : ~[char] = inp.read_chars(len);
if (len <= vec::len(ivals)) { if (len <= vec::len(ivals)) {
assert(vec::len(res) == len); fail_unless!((vec::len(res) == len));
} }
assert(vec::slice(ivals, 0u, vec::len(res)) == fail_unless!(vec::slice(ivals, 0u, vec::len(res)) ==
vec::map(res, |x| *x as int)); vec::map(res, |x| *x as int));
} }
} }
let mut i = 0; let mut i = 0;
@ -1371,7 +1371,7 @@ mod tests {
fn test_readchar() { fn test_readchar() {
do io::with_str_reader(~"") |inp| { do io::with_str_reader(~"") |inp| {
let res : char = inp.read_char(); let res : char = inp.read_char();
assert(res as int == 29983); fail_unless!((res as int == 29983));
} }
} }
@ -1379,7 +1379,7 @@ mod tests {
fn test_readchar_empty() { fn test_readchar_empty() {
do io::with_str_reader(~"") |inp| { do io::with_str_reader(~"") |inp| {
let res : char = inp.read_char(); let res : char = inp.read_char();
assert(res as int == -1); fail_unless!((res as int == -1));
} }
} }
@ -1387,7 +1387,7 @@ mod tests {
fn file_reader_not_exist() { fn file_reader_not_exist() {
match io::file_reader(&Path("not a file")) { match io::file_reader(&Path("not a file")) {
result::Err(copy e) => { result::Err(copy e) => {
assert e == ~"error opening not a file"; fail_unless!(e == ~"error opening not a file");
} }
result::Ok(_) => fail!() result::Ok(_) => fail!()
} }
@ -1428,7 +1428,7 @@ mod tests {
fn file_writer_bad_name() { fn file_writer_bad_name() {
match io::file_writer(&Path("?/?"), ~[]) { match io::file_writer(&Path("?/?"), ~[]) {
result::Err(copy e) => { result::Err(copy e) => {
assert str::starts_with(e, "error opening"); fail_unless!(str::starts_with(e, "error opening"));
} }
result::Ok(_) => fail!() result::Ok(_) => fail!()
} }
@ -1438,7 +1438,7 @@ mod tests {
fn buffered_file_writer_bad_name() { fn buffered_file_writer_bad_name() {
match io::buffered_file_writer(&Path("?/?")) { match io::buffered_file_writer(&Path("?/?")) {
result::Err(copy e) => { result::Err(copy e) => {
assert str::starts_with(e, "error opening"); fail_unless!(str::starts_with(e, "error opening"));
} }
result::Ok(_) => fail!() result::Ok(_) => fail!()
} }
@ -1448,17 +1448,17 @@ mod tests {
fn bytes_buffer_overwrite() { fn bytes_buffer_overwrite() {
let wr = BytesWriter(); let wr = BytesWriter();
wr.write(~[0u8, 1u8, 2u8, 3u8]); wr.write(~[0u8, 1u8, 2u8, 3u8]);
assert wr.bytes.borrow(|bytes| bytes == ~[0u8, 1u8, 2u8, 3u8]); fail_unless!(wr.bytes.borrow(|bytes| bytes == ~[0u8, 1u8, 2u8, 3u8]));
wr.seek(-2, SeekCur); wr.seek(-2, SeekCur);
wr.write(~[4u8, 5u8, 6u8, 7u8]); wr.write(~[4u8, 5u8, 6u8, 7u8]);
assert wr.bytes.borrow(|bytes| bytes == fail_unless!(wr.bytes.borrow(|bytes| bytes ==
~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]); ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]));
wr.seek(-2, SeekEnd); wr.seek(-2, SeekEnd);
wr.write(~[8u8]); wr.write(~[8u8]);
wr.seek(1, SeekSet); wr.seek(1, SeekSet);
wr.write(~[9u8]); wr.write(~[9u8]);
assert wr.bytes.borrow(|bytes| bytes == fail_unless!(wr.bytes.borrow(|bytes| bytes ==
~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]); ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]));
} }
#[test] #[test]
@ -1478,7 +1478,7 @@ mod tests {
{ {
let file = io::file_reader(&path).get(); let file = io::file_reader(&path).get();
for uints.each |i| { for uints.each |i| {
assert file.read_le_u64() == *i; fail_unless!(file.read_le_u64() == *i);
} }
} }
} }
@ -1500,7 +1500,7 @@ mod tests {
{ {
let file = io::file_reader(&path).get(); let file = io::file_reader(&path).get();
for uints.each |i| { for uints.each |i| {
assert file.read_be_u64() == *i; fail_unless!(file.read_be_u64() == *i);
} }
} }
} }
@ -1524,7 +1524,7 @@ mod tests {
for ints.each |i| { for ints.each |i| {
// this tests that the sign extension is working // this tests that the sign extension is working
// (comparing the values as i32 would not test this) // (comparing the values as i32 would not test this)
assert file.read_be_int_n(4) == *i as i64; fail_unless!(file.read_be_int_n(4) == *i as i64);
} }
} }
} }
@ -1543,7 +1543,7 @@ mod tests {
{ {
let file = io::file_reader(&path).get(); let file = io::file_reader(&path).get();
let f = file.read_be_f32(); let f = file.read_be_f32();
assert f == 8.1250; fail_unless!(f == 8.1250);
} }
} }
@ -1560,8 +1560,8 @@ mod tests {
{ {
let file = io::file_reader(&path).get(); let file = io::file_reader(&path).get();
assert file.read_be_f32() == 8.1250; fail_unless!(file.read_be_f32() == 8.1250);
assert file.read_le_f32() == 8.1250; fail_unless!(file.read_le_f32() == 8.1250);
} }
} }
} }

View file

@ -28,7 +28,7 @@ mod inst {
let mut link = self.peek_n(); let mut link = self.peek_n();
while option::is_some(&link) { while option::is_some(&link) {
let nobe = option::get(link); let nobe = option::get(link);
assert nobe.linked; fail_unless!(nobe.linked);
{ {
let frozen_nobe = &*nobe; let frozen_nobe = &*nobe;

View file

@ -72,8 +72,8 @@ impl<T:Ord> Ord for @const T {
fn test() { fn test() {
let x = @3; let x = @3;
let y = @3; let y = @3;
assert (ptr_eq::<int>(x, x)); fail_unless!((ptr_eq::<int>(x, x)));
assert (ptr_eq::<int>(y, y)); fail_unless!((ptr_eq::<int>(y, y)));
assert (!ptr_eq::<int>(x, y)); fail_unless!((!ptr_eq::<int>(x, y)));
assert (!ptr_eq::<int>(y, x)); fail_unless!((!ptr_eq::<int>(y, x)));
} }

View file

@ -38,7 +38,7 @@ pub fn Mut<T>(t: T) -> Mut<T> {
pub fn unwrap<T>(m: Mut<T>) -> T { pub fn unwrap<T>(m: Mut<T>) -> T {
// Borrowck should prevent us from calling unwrap while the value // Borrowck should prevent us from calling unwrap while the value
// is in use, as that would be a move from a borrowed value. // is in use, as that would be a move from a borrowed value.
assert (m.mode as uint) == (ReadOnly as uint); fail_unless!((m.mode as uint) == (ReadOnly as uint));
let Data {value: value, mode: _} = m; let Data {value: value, mode: _} = m;
value value
} }
@ -105,9 +105,9 @@ pub fn test_const_in_mut() {
let m = @Mut(1); let m = @Mut(1);
do m.borrow_mut |p| { do m.borrow_mut |p| {
do m.borrow_const |q| { do m.borrow_const |q| {
assert *p == *q; fail_unless!(*p == *q);
*p += 1; *p += 1;
assert *p == *q; fail_unless!(*p == *q);
} }
} }
} }
@ -117,9 +117,9 @@ pub fn test_mut_in_const() {
let m = @Mut(1); let m = @Mut(1);
do m.borrow_const |p| { do m.borrow_const |p| {
do m.borrow_mut |q| { do m.borrow_mut |q| {
assert *p == *q; fail_unless!(*p == *q);
*q += 1; *q += 1;
assert *p == *q; fail_unless!(*p == *q);
} }
} }
} }
@ -129,7 +129,7 @@ pub fn test_imm_in_const() {
let m = @Mut(1); let m = @Mut(1);
do m.borrow_const |p| { do m.borrow_const |p| {
do m.borrow_imm |q| { do m.borrow_imm |q| {
assert *p == *q; fail_unless!(*p == *q);
} }
} }
} }
@ -139,7 +139,7 @@ pub fn test_const_in_imm() {
let m = @Mut(1); let m = @Mut(1);
do m.borrow_imm |p| { do m.borrow_imm |p| {
do m.borrow_const |q| { do m.borrow_const |q| {
assert *p == *q; fail_unless!(*p == *q);
} }
} }
} }

View file

@ -583,56 +583,56 @@ pub fn test_num() {
let ten: f32 = num::cast(10); let ten: f32 = num::cast(10);
let two: f32 = num::cast(2); let two: f32 = num::cast(2);
assert (ten.add(&two) == num::cast(12)); fail_unless!((ten.add(&two) == num::cast(12)));
assert (ten.sub(&two) == num::cast(8)); fail_unless!((ten.sub(&two) == num::cast(8)));
assert (ten.mul(&two) == num::cast(20)); fail_unless!((ten.mul(&two) == num::cast(20)));
assert (ten.div(&two) == num::cast(5)); fail_unless!((ten.div(&two) == num::cast(5)));
assert (ten.modulo(&two) == num::cast(0)); fail_unless!((ten.modulo(&two) == num::cast(0)));
} }
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20f32.to_uint()); fail_unless!((20u == 20f32.to_uint()));
assert (20u8 == 20f32.to_u8()); fail_unless!((20u8 == 20f32.to_u8()));
assert (20u16 == 20f32.to_u16()); fail_unless!((20u16 == 20f32.to_u16()));
assert (20u32 == 20f32.to_u32()); fail_unless!((20u32 == 20f32.to_u32()));
assert (20u64 == 20f32.to_u64()); fail_unless!((20u64 == 20f32.to_u64()));
assert (20i == 20f32.to_int()); fail_unless!((20i == 20f32.to_int()));
assert (20i8 == 20f32.to_i8()); fail_unless!((20i8 == 20f32.to_i8()));
assert (20i16 == 20f32.to_i16()); fail_unless!((20i16 == 20f32.to_i16()));
assert (20i32 == 20f32.to_i32()); fail_unless!((20i32 == 20f32.to_i32()));
assert (20i64 == 20f32.to_i64()); fail_unless!((20i64 == 20f32.to_i64()));
assert (20f == 20f32.to_float()); fail_unless!((20f == 20f32.to_float()));
assert (20f32 == 20f32.to_f32()); fail_unless!((20f32 == 20f32.to_f32()));
assert (20f64 == 20f32.to_f64()); fail_unless!((20f64 == 20f32.to_f64()));
assert (20f32 == NumCast::from(20u)); fail_unless!((20f32 == NumCast::from(20u)));
assert (20f32 == NumCast::from(20u8)); fail_unless!((20f32 == NumCast::from(20u8)));
assert (20f32 == NumCast::from(20u16)); fail_unless!((20f32 == NumCast::from(20u16)));
assert (20f32 == NumCast::from(20u32)); fail_unless!((20f32 == NumCast::from(20u32)));
assert (20f32 == NumCast::from(20u64)); fail_unless!((20f32 == NumCast::from(20u64)));
assert (20f32 == NumCast::from(20i)); fail_unless!((20f32 == NumCast::from(20i)));
assert (20f32 == NumCast::from(20i8)); fail_unless!((20f32 == NumCast::from(20i8)));
assert (20f32 == NumCast::from(20i16)); fail_unless!((20f32 == NumCast::from(20i16)));
assert (20f32 == NumCast::from(20i32)); fail_unless!((20f32 == NumCast::from(20i32)));
assert (20f32 == NumCast::from(20i64)); fail_unless!((20f32 == NumCast::from(20i64)));
assert (20f32 == NumCast::from(20f)); fail_unless!((20f32 == NumCast::from(20f)));
assert (20f32 == NumCast::from(20f32)); fail_unless!((20f32 == NumCast::from(20f32)));
assert (20f32 == NumCast::from(20f64)); fail_unless!((20f32 == NumCast::from(20f64)));
assert (20f32 == num::cast(20u)); fail_unless!((20f32 == num::cast(20u)));
assert (20f32 == num::cast(20u8)); fail_unless!((20f32 == num::cast(20u8)));
assert (20f32 == num::cast(20u16)); fail_unless!((20f32 == num::cast(20u16)));
assert (20f32 == num::cast(20u32)); fail_unless!((20f32 == num::cast(20u32)));
assert (20f32 == num::cast(20u64)); fail_unless!((20f32 == num::cast(20u64)));
assert (20f32 == num::cast(20i)); fail_unless!((20f32 == num::cast(20i)));
assert (20f32 == num::cast(20i8)); fail_unless!((20f32 == num::cast(20i8)));
assert (20f32 == num::cast(20i16)); fail_unless!((20f32 == num::cast(20i16)));
assert (20f32 == num::cast(20i32)); fail_unless!((20f32 == num::cast(20i32)));
assert (20f32 == num::cast(20i64)); fail_unless!((20f32 == num::cast(20i64)));
assert (20f32 == num::cast(20f)); fail_unless!((20f32 == num::cast(20f)));
assert (20f32 == num::cast(20f32)); fail_unless!((20f32 == num::cast(20f32)));
assert (20f32 == num::cast(20f64)); fail_unless!((20f32 == num::cast(20f64)));
} }
// //

View file

@ -607,56 +607,56 @@ pub fn test_num() {
let ten: f64 = num::cast(10); let ten: f64 = num::cast(10);
let two: f64 = num::cast(2); let two: f64 = num::cast(2);
assert (ten.add(&two) == num::cast(12)); fail_unless!((ten.add(&two) == num::cast(12)));
assert (ten.sub(&two) == num::cast(8)); fail_unless!((ten.sub(&two) == num::cast(8)));
assert (ten.mul(&two) == num::cast(20)); fail_unless!((ten.mul(&two) == num::cast(20)));
assert (ten.div(&two) == num::cast(5)); fail_unless!((ten.div(&two) == num::cast(5)));
assert (ten.modulo(&two) == num::cast(0)); fail_unless!((ten.modulo(&two) == num::cast(0)));
} }
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20f64.to_uint()); fail_unless!((20u == 20f64.to_uint()));
assert (20u8 == 20f64.to_u8()); fail_unless!((20u8 == 20f64.to_u8()));
assert (20u16 == 20f64.to_u16()); fail_unless!((20u16 == 20f64.to_u16()));
assert (20u32 == 20f64.to_u32()); fail_unless!((20u32 == 20f64.to_u32()));
assert (20u64 == 20f64.to_u64()); fail_unless!((20u64 == 20f64.to_u64()));
assert (20i == 20f64.to_int()); fail_unless!((20i == 20f64.to_int()));
assert (20i8 == 20f64.to_i8()); fail_unless!((20i8 == 20f64.to_i8()));
assert (20i16 == 20f64.to_i16()); fail_unless!((20i16 == 20f64.to_i16()));
assert (20i32 == 20f64.to_i32()); fail_unless!((20i32 == 20f64.to_i32()));
assert (20i64 == 20f64.to_i64()); fail_unless!((20i64 == 20f64.to_i64()));
assert (20f == 20f64.to_float()); fail_unless!((20f == 20f64.to_float()));
assert (20f32 == 20f64.to_f32()); fail_unless!((20f32 == 20f64.to_f32()));
assert (20f64 == 20f64.to_f64()); fail_unless!((20f64 == 20f64.to_f64()));
assert (20f64 == NumCast::from(20u)); fail_unless!((20f64 == NumCast::from(20u)));
assert (20f64 == NumCast::from(20u8)); fail_unless!((20f64 == NumCast::from(20u8)));
assert (20f64 == NumCast::from(20u16)); fail_unless!((20f64 == NumCast::from(20u16)));
assert (20f64 == NumCast::from(20u32)); fail_unless!((20f64 == NumCast::from(20u32)));
assert (20f64 == NumCast::from(20u64)); fail_unless!((20f64 == NumCast::from(20u64)));
assert (20f64 == NumCast::from(20i)); fail_unless!((20f64 == NumCast::from(20i)));
assert (20f64 == NumCast::from(20i8)); fail_unless!((20f64 == NumCast::from(20i8)));
assert (20f64 == NumCast::from(20i16)); fail_unless!((20f64 == NumCast::from(20i16)));
assert (20f64 == NumCast::from(20i32)); fail_unless!((20f64 == NumCast::from(20i32)));
assert (20f64 == NumCast::from(20i64)); fail_unless!((20f64 == NumCast::from(20i64)));
assert (20f64 == NumCast::from(20f)); fail_unless!((20f64 == NumCast::from(20f)));
assert (20f64 == NumCast::from(20f32)); fail_unless!((20f64 == NumCast::from(20f32)));
assert (20f64 == NumCast::from(20f64)); fail_unless!((20f64 == NumCast::from(20f64)));
assert (20f64 == num::cast(20u)); fail_unless!((20f64 == num::cast(20u)));
assert (20f64 == num::cast(20u8)); fail_unless!((20f64 == num::cast(20u8)));
assert (20f64 == num::cast(20u16)); fail_unless!((20f64 == num::cast(20u16)));
assert (20f64 == num::cast(20u32)); fail_unless!((20f64 == num::cast(20u32)));
assert (20f64 == num::cast(20u64)); fail_unless!((20f64 == num::cast(20u64)));
assert (20f64 == num::cast(20i)); fail_unless!((20f64 == num::cast(20i)));
assert (20f64 == num::cast(20i8)); fail_unless!((20f64 == num::cast(20i8)));
assert (20f64 == num::cast(20i16)); fail_unless!((20f64 == num::cast(20i16)));
assert (20f64 == num::cast(20i32)); fail_unless!((20f64 == num::cast(20i32)));
assert (20f64 == num::cast(20i64)); fail_unless!((20f64 == num::cast(20i64)));
assert (20f64 == num::cast(20f)); fail_unless!((20f64 == num::cast(20f)));
assert (20f64 == num::cast(20f32)); fail_unless!((20f64 == num::cast(20f32)));
assert (20f64 == num::cast(20f64)); fail_unless!((20f64 == num::cast(20f64)));
} }
// //

View file

@ -180,7 +180,7 @@ pub pure fn to_str_exact(num: float, digits: uint) -> ~str {
#[test] #[test]
pub fn test_to_str_exact_do_decimal() { pub fn test_to_str_exact_do_decimal() {
let s = to_str_exact(5.0, 4u); let s = to_str_exact(5.0, 4u);
assert s == ~"5.0000"; fail_unless!(s == ~"5.0000");
} }
/** /**
@ -500,191 +500,191 @@ impl ops::Neg<float> for float {
#[test] #[test]
pub fn test_from_str() { pub fn test_from_str() {
assert from_str(~"3") == Some(3.); fail_unless!(from_str(~"3") == Some(3.));
assert from_str(~"3.14") == Some(3.14); fail_unless!(from_str(~"3.14") == Some(3.14));
assert from_str(~"+3.14") == Some(3.14); fail_unless!(from_str(~"+3.14") == Some(3.14));
assert from_str(~"-3.14") == Some(-3.14); fail_unless!(from_str(~"-3.14") == Some(-3.14));
assert from_str(~"2.5E10") == Some(25000000000.); fail_unless!(from_str(~"2.5E10") == Some(25000000000.));
assert from_str(~"2.5e10") == Some(25000000000.); fail_unless!(from_str(~"2.5e10") == Some(25000000000.));
assert from_str(~"25000000000.E-10") == Some(2.5); fail_unless!(from_str(~"25000000000.E-10") == Some(2.5));
assert from_str(~".") == Some(0.); fail_unless!(from_str(~".") == Some(0.));
assert from_str(~".e1") == Some(0.); fail_unless!(from_str(~".e1") == Some(0.));
assert from_str(~".e-1") == Some(0.); fail_unless!(from_str(~".e-1") == Some(0.));
assert from_str(~"5.") == Some(5.); fail_unless!(from_str(~"5.") == Some(5.));
assert from_str(~".5") == Some(0.5); fail_unless!(from_str(~".5") == Some(0.5));
assert from_str(~"0.5") == Some(0.5); fail_unless!(from_str(~"0.5") == Some(0.5));
assert from_str(~"-.5") == Some(-0.5); fail_unless!(from_str(~"-.5") == Some(-0.5));
assert from_str(~"-5") == Some(-5.); fail_unless!(from_str(~"-5") == Some(-5.));
assert from_str(~"inf") == Some(infinity); fail_unless!(from_str(~"inf") == Some(infinity));
assert from_str(~"+inf") == Some(infinity); fail_unless!(from_str(~"+inf") == Some(infinity));
assert from_str(~"-inf") == Some(neg_infinity); fail_unless!(from_str(~"-inf") == Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test // note: NaN != NaN, hence this slightly complex test
match from_str(~"NaN") { match from_str(~"NaN") {
Some(f) => assert is_NaN(f), Some(f) => fail_unless!(is_NaN(f)),
None => fail!() None => fail!()
} }
// note: -0 == 0, hence these slightly more complex tests // note: -0 == 0, hence these slightly more complex tests
match from_str(~"-0") { match from_str(~"-0") {
Some(v) if is_zero(v) => assert is_negative(v), Some(v) if is_zero(v) => fail_unless!(is_negative(v)),
_ => fail!() _ => fail!()
} }
match from_str(~"0") { match from_str(~"0") {
Some(v) if is_zero(v) => assert is_positive(v), Some(v) if is_zero(v) => fail_unless!(is_positive(v)),
_ => fail!() _ => fail!()
} }
assert from_str(~"").is_none(); fail_unless!(from_str(~"").is_none());
assert from_str(~"x").is_none(); fail_unless!(from_str(~"x").is_none());
assert from_str(~" ").is_none(); fail_unless!(from_str(~" ").is_none());
assert from_str(~" ").is_none(); fail_unless!(from_str(~" ").is_none());
assert from_str(~"e").is_none(); fail_unless!(from_str(~"e").is_none());
assert from_str(~"E").is_none(); fail_unless!(from_str(~"E").is_none());
assert from_str(~"E1").is_none(); fail_unless!(from_str(~"E1").is_none());
assert from_str(~"1e1e1").is_none(); fail_unless!(from_str(~"1e1e1").is_none());
assert from_str(~"1e1.1").is_none(); fail_unless!(from_str(~"1e1.1").is_none());
assert from_str(~"1e1-1").is_none(); fail_unless!(from_str(~"1e1-1").is_none());
} }
#[test] #[test]
pub fn test_from_str_hex() { pub fn test_from_str_hex() {
assert from_str_hex(~"a4") == Some(164.); fail_unless!(from_str_hex(~"a4") == Some(164.));
assert from_str_hex(~"a4.fe") == Some(164.9921875); fail_unless!(from_str_hex(~"a4.fe") == Some(164.9921875));
assert from_str_hex(~"-a4.fe") == Some(-164.9921875); fail_unless!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
assert from_str_hex(~"+a4.fe") == Some(164.9921875); fail_unless!(from_str_hex(~"+a4.fe") == Some(164.9921875));
assert from_str_hex(~"ff0P4") == Some(0xff00 as float); fail_unless!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
assert from_str_hex(~"ff0p4") == Some(0xff00 as float); fail_unless!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
assert from_str_hex(~"ff0p-4") == Some(0xff as float); fail_unless!(from_str_hex(~"ff0p-4") == Some(0xff as float));
assert from_str_hex(~".") == Some(0.); fail_unless!(from_str_hex(~".") == Some(0.));
assert from_str_hex(~".p1") == Some(0.); fail_unless!(from_str_hex(~".p1") == Some(0.));
assert from_str_hex(~".p-1") == Some(0.); fail_unless!(from_str_hex(~".p-1") == Some(0.));
assert from_str_hex(~"f.") == Some(15.); fail_unless!(from_str_hex(~"f.") == Some(15.));
assert from_str_hex(~".f") == Some(0.9375); fail_unless!(from_str_hex(~".f") == Some(0.9375));
assert from_str_hex(~"0.f") == Some(0.9375); fail_unless!(from_str_hex(~"0.f") == Some(0.9375));
assert from_str_hex(~"-.f") == Some(-0.9375); fail_unless!(from_str_hex(~"-.f") == Some(-0.9375));
assert from_str_hex(~"-f") == Some(-15.); fail_unless!(from_str_hex(~"-f") == Some(-15.));
assert from_str_hex(~"inf") == Some(infinity); fail_unless!(from_str_hex(~"inf") == Some(infinity));
assert from_str_hex(~"+inf") == Some(infinity); fail_unless!(from_str_hex(~"+inf") == Some(infinity));
assert from_str_hex(~"-inf") == Some(neg_infinity); fail_unless!(from_str_hex(~"-inf") == Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test // note: NaN != NaN, hence this slightly complex test
match from_str_hex(~"NaN") { match from_str_hex(~"NaN") {
Some(f) => assert is_NaN(f), Some(f) => fail_unless!(is_NaN(f)),
None => fail!() None => fail!()
} }
// note: -0 == 0, hence these slightly more complex tests // note: -0 == 0, hence these slightly more complex tests
match from_str_hex(~"-0") { match from_str_hex(~"-0") {
Some(v) if is_zero(v) => assert is_negative(v), Some(v) if is_zero(v) => fail_unless!(is_negative(v)),
_ => fail!() _ => fail!()
} }
match from_str_hex(~"0") { match from_str_hex(~"0") {
Some(v) if is_zero(v) => assert is_positive(v), Some(v) if is_zero(v) => fail_unless!(is_positive(v)),
_ => fail!() _ => fail!()
} }
assert from_str_hex(~"e") == Some(14.); fail_unless!(from_str_hex(~"e") == Some(14.));
assert from_str_hex(~"E") == Some(14.); fail_unless!(from_str_hex(~"E") == Some(14.));
assert from_str_hex(~"E1") == Some(225.); fail_unless!(from_str_hex(~"E1") == Some(225.));
assert from_str_hex(~"1e1e1") == Some(123361.); fail_unless!(from_str_hex(~"1e1e1") == Some(123361.));
assert from_str_hex(~"1e1.1") == Some(481.0625); fail_unless!(from_str_hex(~"1e1.1") == Some(481.0625));
assert from_str_hex(~"").is_none(); fail_unless!(from_str_hex(~"").is_none());
assert from_str_hex(~"x").is_none(); fail_unless!(from_str_hex(~"x").is_none());
assert from_str_hex(~" ").is_none(); fail_unless!(from_str_hex(~" ").is_none());
assert from_str_hex(~" ").is_none(); fail_unless!(from_str_hex(~" ").is_none());
assert from_str_hex(~"p").is_none(); fail_unless!(from_str_hex(~"p").is_none());
assert from_str_hex(~"P").is_none(); fail_unless!(from_str_hex(~"P").is_none());
assert from_str_hex(~"P1").is_none(); fail_unless!(from_str_hex(~"P1").is_none());
assert from_str_hex(~"1p1p1").is_none(); fail_unless!(from_str_hex(~"1p1p1").is_none());
assert from_str_hex(~"1p1.1").is_none(); fail_unless!(from_str_hex(~"1p1.1").is_none());
assert from_str_hex(~"1p1-1").is_none(); fail_unless!(from_str_hex(~"1p1-1").is_none());
} }
#[test] #[test]
pub fn test_to_str_hex() { pub fn test_to_str_hex() {
assert to_str_hex(164.) == ~"a4"; fail_unless!(to_str_hex(164.) == ~"a4");
assert to_str_hex(164.9921875) == ~"a4.fe"; fail_unless!(to_str_hex(164.9921875) == ~"a4.fe");
assert to_str_hex(-164.9921875) == ~"-a4.fe"; fail_unless!(to_str_hex(-164.9921875) == ~"-a4.fe");
assert to_str_hex(0xff00 as float) == ~"ff00"; fail_unless!(to_str_hex(0xff00 as float) == ~"ff00");
assert to_str_hex(-(0xff00 as float)) == ~"-ff00"; fail_unless!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
assert to_str_hex(0.) == ~"0"; fail_unless!(to_str_hex(0.) == ~"0");
assert to_str_hex(15.) == ~"f"; fail_unless!(to_str_hex(15.) == ~"f");
assert to_str_hex(-15.) == ~"-f"; fail_unless!(to_str_hex(-15.) == ~"-f");
assert to_str_hex(0.9375) == ~"0.f"; fail_unless!(to_str_hex(0.9375) == ~"0.f");
assert to_str_hex(-0.9375) == ~"-0.f"; fail_unless!(to_str_hex(-0.9375) == ~"-0.f");
assert to_str_hex(infinity) == ~"inf"; fail_unless!(to_str_hex(infinity) == ~"inf");
assert to_str_hex(neg_infinity) == ~"-inf"; fail_unless!(to_str_hex(neg_infinity) == ~"-inf");
assert to_str_hex(NaN) == ~"NaN"; fail_unless!(to_str_hex(NaN) == ~"NaN");
assert to_str_hex(0.) == ~"0"; fail_unless!(to_str_hex(0.) == ~"0");
assert to_str_hex(-0.) == ~"-0"; fail_unless!(to_str_hex(-0.) == ~"-0");
} }
#[test] #[test]
pub fn test_to_str_radix() { pub fn test_to_str_radix() {
assert to_str_radix(36., 36u) == ~"10"; fail_unless!(to_str_radix(36., 36u) == ~"10");
assert to_str_radix(8.125, 2u) == ~"1000.001"; fail_unless!(to_str_radix(8.125, 2u) == ~"1000.001");
} }
#[test] #[test]
pub fn test_from_str_radix() { pub fn test_from_str_radix() {
assert from_str_radix(~"10", 36u) == Some(36.); fail_unless!(from_str_radix(~"10", 36u) == Some(36.));
assert from_str_radix(~"1000.001", 2u) == Some(8.125); fail_unless!(from_str_radix(~"1000.001", 2u) == Some(8.125));
} }
#[test] #[test]
pub fn test_positive() { pub fn test_positive() {
assert(is_positive(infinity)); fail_unless!((is_positive(infinity)));
assert(is_positive(1.)); fail_unless!((is_positive(1.)));
assert(is_positive(0.)); fail_unless!((is_positive(0.)));
assert(!is_positive(-1.)); fail_unless!((!is_positive(-1.)));
assert(!is_positive(neg_infinity)); fail_unless!((!is_positive(neg_infinity)));
assert(!is_positive(1./neg_infinity)); fail_unless!((!is_positive(1./neg_infinity)));
assert(!is_positive(NaN)); fail_unless!((!is_positive(NaN)));
} }
#[test] #[test]
pub fn test_negative() { pub fn test_negative() {
assert(!is_negative(infinity)); fail_unless!((!is_negative(infinity)));
assert(!is_negative(1.)); fail_unless!((!is_negative(1.)));
assert(!is_negative(0.)); fail_unless!((!is_negative(0.)));
assert(is_negative(-1.)); fail_unless!((is_negative(-1.)));
assert(is_negative(neg_infinity)); fail_unless!((is_negative(neg_infinity)));
assert(is_negative(1./neg_infinity)); fail_unless!((is_negative(1./neg_infinity)));
assert(!is_negative(NaN)); fail_unless!((!is_negative(NaN)));
} }
#[test] #[test]
pub fn test_nonpositive() { pub fn test_nonpositive() {
assert(!is_nonpositive(infinity)); fail_unless!((!is_nonpositive(infinity)));
assert(!is_nonpositive(1.)); fail_unless!((!is_nonpositive(1.)));
assert(!is_nonpositive(0.)); fail_unless!((!is_nonpositive(0.)));
assert(is_nonpositive(-1.)); fail_unless!((is_nonpositive(-1.)));
assert(is_nonpositive(neg_infinity)); fail_unless!((is_nonpositive(neg_infinity)));
assert(is_nonpositive(1./neg_infinity)); fail_unless!((is_nonpositive(1./neg_infinity)));
assert(!is_nonpositive(NaN)); fail_unless!((!is_nonpositive(NaN)));
} }
#[test] #[test]
pub fn test_nonnegative() { pub fn test_nonnegative() {
assert(is_nonnegative(infinity)); fail_unless!((is_nonnegative(infinity)));
assert(is_nonnegative(1.)); fail_unless!((is_nonnegative(1.)));
assert(is_nonnegative(0.)); fail_unless!((is_nonnegative(0.)));
assert(!is_nonnegative(-1.)); fail_unless!((!is_nonnegative(-1.)));
assert(!is_nonnegative(neg_infinity)); fail_unless!((!is_nonnegative(neg_infinity)));
assert(!is_nonnegative(1./neg_infinity)); fail_unless!((!is_nonnegative(1./neg_infinity)));
assert(!is_nonnegative(NaN)); fail_unless!((!is_nonnegative(NaN)));
} }
#[test] #[test]
pub fn test_to_str_inf() { pub fn test_to_str_inf() {
assert to_str_digits(infinity, 10u) == ~"inf"; fail_unless!(to_str_digits(infinity, 10u) == ~"inf");
assert to_str_digits(-infinity, 10u) == ~"-inf"; fail_unless!(to_str_digits(-infinity, 10u) == ~"-inf");
} }
#[test] #[test]
pub fn test_round() { pub fn test_round() {
assert round(5.8) == 6.0; fail_unless!(round(5.8) == 6.0);
assert round(5.2) == 5.0; fail_unless!(round(5.2) == 5.0);
assert round(3.0) == 3.0; fail_unless!(round(3.0) == 3.0);
assert round(2.5) == 3.0; fail_unless!(round(2.5) == 3.0);
assert round(-3.5) == -4.0; fail_unless!(round(-3.5) == -4.0);
} }
#[test] #[test]
@ -692,56 +692,56 @@ pub fn test_num() {
let ten: float = num::cast(10); let ten: float = num::cast(10);
let two: float = num::cast(2); let two: float = num::cast(2);
assert (ten.add(&two) == num::cast(12)); fail_unless!((ten.add(&two) == num::cast(12)));
assert (ten.sub(&two) == num::cast(8)); fail_unless!((ten.sub(&two) == num::cast(8)));
assert (ten.mul(&two) == num::cast(20)); fail_unless!((ten.mul(&two) == num::cast(20)));
assert (ten.div(&two) == num::cast(5)); fail_unless!((ten.div(&two) == num::cast(5)));
assert (ten.modulo(&two) == num::cast(0)); fail_unless!((ten.modulo(&two) == num::cast(0)));
} }
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20f.to_uint()); fail_unless!((20u == 20f.to_uint()));
assert (20u8 == 20f.to_u8()); fail_unless!((20u8 == 20f.to_u8()));
assert (20u16 == 20f.to_u16()); fail_unless!((20u16 == 20f.to_u16()));
assert (20u32 == 20f.to_u32()); fail_unless!((20u32 == 20f.to_u32()));
assert (20u64 == 20f.to_u64()); fail_unless!((20u64 == 20f.to_u64()));
assert (20i == 20f.to_int()); fail_unless!((20i == 20f.to_int()));
assert (20i8 == 20f.to_i8()); fail_unless!((20i8 == 20f.to_i8()));
assert (20i16 == 20f.to_i16()); fail_unless!((20i16 == 20f.to_i16()));
assert (20i32 == 20f.to_i32()); fail_unless!((20i32 == 20f.to_i32()));
assert (20i64 == 20f.to_i64()); fail_unless!((20i64 == 20f.to_i64()));
assert (20f == 20f.to_float()); fail_unless!((20f == 20f.to_float()));
assert (20f32 == 20f.to_f32()); fail_unless!((20f32 == 20f.to_f32()));
assert (20f64 == 20f.to_f64()); fail_unless!((20f64 == 20f.to_f64()));
assert (20f == NumCast::from(20u)); fail_unless!((20f == NumCast::from(20u)));
assert (20f == NumCast::from(20u8)); fail_unless!((20f == NumCast::from(20u8)));
assert (20f == NumCast::from(20u16)); fail_unless!((20f == NumCast::from(20u16)));
assert (20f == NumCast::from(20u32)); fail_unless!((20f == NumCast::from(20u32)));
assert (20f == NumCast::from(20u64)); fail_unless!((20f == NumCast::from(20u64)));
assert (20f == NumCast::from(20i)); fail_unless!((20f == NumCast::from(20i)));
assert (20f == NumCast::from(20i8)); fail_unless!((20f == NumCast::from(20i8)));
assert (20f == NumCast::from(20i16)); fail_unless!((20f == NumCast::from(20i16)));
assert (20f == NumCast::from(20i32)); fail_unless!((20f == NumCast::from(20i32)));
assert (20f == NumCast::from(20i64)); fail_unless!((20f == NumCast::from(20i64)));
assert (20f == NumCast::from(20f)); fail_unless!((20f == NumCast::from(20f)));
assert (20f == NumCast::from(20f32)); fail_unless!((20f == NumCast::from(20f32)));
assert (20f == NumCast::from(20f64)); fail_unless!((20f == NumCast::from(20f64)));
assert (20f == num::cast(20u)); fail_unless!((20f == num::cast(20u)));
assert (20f == num::cast(20u8)); fail_unless!((20f == num::cast(20u8)));
assert (20f == num::cast(20u16)); fail_unless!((20f == num::cast(20u16)));
assert (20f == num::cast(20u32)); fail_unless!((20f == num::cast(20u32)));
assert (20f == num::cast(20u64)); fail_unless!((20f == num::cast(20u64)));
assert (20f == num::cast(20i)); fail_unless!((20f == num::cast(20i)));
assert (20f == num::cast(20i8)); fail_unless!((20f == num::cast(20i8)));
assert (20f == num::cast(20i16)); fail_unless!((20f == num::cast(20i16)));
assert (20f == num::cast(20i32)); fail_unless!((20f == num::cast(20i32)));
assert (20f == num::cast(20i64)); fail_unless!((20f == num::cast(20i64)));
assert (20f == num::cast(20f)); fail_unless!((20f == num::cast(20f)));
assert (20f == num::cast(20f32)); fail_unless!((20f == num::cast(20f32)));
assert (20f == num::cast(20f64)); fail_unless!((20f == num::cast(20f64)));
} }

View file

@ -41,18 +41,18 @@ pub pure fn div(x: T, y: T) -> T { x / y }
* *
* # Examples * # Examples
* ~~~ * ~~~
* assert int::rem(5 / 2) == 1; * fail_unless!(int::rem(5 / 2) == 1);
* ~~~ * ~~~
* *
* When faced with negative numbers, the result copies the sign of the * When faced with negative numbers, the result copies the sign of the
* dividend. * dividend.
* *
* ~~~ * ~~~
* assert int::rem(2 / -3) == 2; * fail_unless!(int::rem(2 / -3) == 2);
* ~~~ * ~~~
* *
* ~~~ * ~~~
* assert int::rem(-2 / 3) == -2; * fail_unless!(int::rem(-2 / 3) == -2);
* ~~~ * ~~~
* *
*/ */
@ -95,7 +95,7 @@ pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
* for int::range(1, 5) |i| { * for int::range(1, 5) |i| {
* sum += i; * sum += i;
* } * }
* assert sum == 10; * fail_unless!(sum == 10);
* ~~~ * ~~~
*/ */
#[inline(always)] #[inline(always)]
@ -275,117 +275,117 @@ impl ToStrRadix for T {
#[test] #[test]
fn test_from_str() { fn test_from_str() {
assert from_str(~"0") == Some(0 as T); fail_unless!(from_str(~"0") == Some(0 as T));
assert from_str(~"3") == Some(3 as T); fail_unless!(from_str(~"3") == Some(3 as T));
assert from_str(~"10") == Some(10 as T); fail_unless!(from_str(~"10") == Some(10 as T));
assert i32::from_str(~"123456789") == Some(123456789 as i32); fail_unless!(i32::from_str(~"123456789") == Some(123456789 as i32));
assert from_str(~"00100") == Some(100 as T); fail_unless!(from_str(~"00100") == Some(100 as T));
assert from_str(~"-1") == Some(-1 as T); fail_unless!(from_str(~"-1") == Some(-1 as T));
assert from_str(~"-3") == Some(-3 as T); fail_unless!(from_str(~"-3") == Some(-3 as T));
assert from_str(~"-10") == Some(-10 as T); fail_unless!(from_str(~"-10") == Some(-10 as T));
assert i32::from_str(~"-123456789") == Some(-123456789 as i32); fail_unless!(i32::from_str(~"-123456789") == Some(-123456789 as i32));
assert from_str(~"-00100") == Some(-100 as T); fail_unless!(from_str(~"-00100") == Some(-100 as T));
assert from_str(~" ").is_none(); fail_unless!(from_str(~" ").is_none());
assert from_str(~"x").is_none(); fail_unless!(from_str(~"x").is_none());
} }
#[test] #[test]
fn test_parse_bytes() { fn test_parse_bytes() {
use str::to_bytes; use str::to_bytes;
assert parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T); fail_unless!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
assert parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T); fail_unless!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
assert parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T); fail_unless!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
assert i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32); fail_unless!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
assert i32::parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535 as i32); fail_unless!(i32::parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535 as i32));
assert i32::parse_bytes(to_bytes(~"FFFF"), 16u) == Some(65535 as i32); fail_unless!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) == Some(65535 as i32));
assert parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T); fail_unless!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
assert parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T); fail_unless!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
assert parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T); fail_unless!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
assert parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T); fail_unless!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
assert parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T); fail_unless!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
assert i32::parse_bytes(to_bytes(~"-123"), 16u) == Some(-291 as i32); fail_unless!(i32::parse_bytes(to_bytes(~"-123"), 16u) == Some(-291 as i32));
assert i32::parse_bytes(to_bytes(~"-ffff"), 16u) == Some(-65535 as i32); fail_unless!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) == Some(-65535 as i32));
assert i32::parse_bytes(to_bytes(~"-FFFF"), 16u) == Some(-65535 as i32); fail_unless!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) == Some(-65535 as i32));
assert parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T); fail_unless!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
assert parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T); fail_unless!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
assert parse_bytes(to_bytes(~"Z"), 35u).is_none(); fail_unless!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
assert parse_bytes(to_bytes(~"-9"), 2u).is_none(); fail_unless!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
} }
#[test] #[test]
fn test_to_str() { fn test_to_str() {
assert (to_str_radix(0 as T, 10u) == ~"0"); fail_unless!((to_str_radix(0 as T, 10u) == ~"0"));
assert (to_str_radix(1 as T, 10u) == ~"1"); fail_unless!((to_str_radix(1 as T, 10u) == ~"1"));
assert (to_str_radix(-1 as T, 10u) == ~"-1"); fail_unless!((to_str_radix(-1 as T, 10u) == ~"-1"));
assert (to_str_radix(127 as T, 16u) == ~"7f"); fail_unless!((to_str_radix(127 as T, 16u) == ~"7f"));
assert (to_str_radix(100 as T, 10u) == ~"100"); fail_unless!((to_str_radix(100 as T, 10u) == ~"100"));
} }
#[test] #[test]
fn test_int_to_str_overflow() { fn test_int_to_str_overflow() {
let mut i8_val: i8 = 127_i8; let mut i8_val: i8 = 127_i8;
assert (i8::to_str(i8_val) == ~"127"); fail_unless!((i8::to_str(i8_val) == ~"127"));
i8_val += 1 as i8; i8_val += 1 as i8;
assert (i8::to_str(i8_val) == ~"-128"); fail_unless!((i8::to_str(i8_val) == ~"-128"));
let mut i16_val: i16 = 32_767_i16; let mut i16_val: i16 = 32_767_i16;
assert (i16::to_str(i16_val) == ~"32767"); fail_unless!((i16::to_str(i16_val) == ~"32767"));
i16_val += 1 as i16; i16_val += 1 as i16;
assert (i16::to_str(i16_val) == ~"-32768"); fail_unless!((i16::to_str(i16_val) == ~"-32768"));
let mut i32_val: i32 = 2_147_483_647_i32; let mut i32_val: i32 = 2_147_483_647_i32;
assert (i32::to_str(i32_val) == ~"2147483647"); fail_unless!((i32::to_str(i32_val) == ~"2147483647"));
i32_val += 1 as i32; i32_val += 1 as i32;
assert (i32::to_str(i32_val) == ~"-2147483648"); fail_unless!((i32::to_str(i32_val) == ~"-2147483648"));
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert (i64::to_str(i64_val) == ~"9223372036854775807"); fail_unless!((i64::to_str(i64_val) == ~"9223372036854775807"));
i64_val += 1 as i64; i64_val += 1 as i64;
assert (i64::to_str(i64_val) == ~"-9223372036854775808"); fail_unless!((i64::to_str(i64_val) == ~"-9223372036854775808"));
} }
#[test] #[test]
fn test_int_from_str_overflow() { fn test_int_from_str_overflow() {
let mut i8_val: i8 = 127_i8; let mut i8_val: i8 = 127_i8;
assert (i8::from_str(~"127") == Some(i8_val)); fail_unless!((i8::from_str(~"127") == Some(i8_val)));
assert (i8::from_str(~"128").is_none()); fail_unless!((i8::from_str(~"128").is_none()));
i8_val += 1 as i8; i8_val += 1 as i8;
assert (i8::from_str(~"-128") == Some(i8_val)); fail_unless!((i8::from_str(~"-128") == Some(i8_val)));
assert (i8::from_str(~"-129").is_none()); fail_unless!((i8::from_str(~"-129").is_none()));
let mut i16_val: i16 = 32_767_i16; let mut i16_val: i16 = 32_767_i16;
assert (i16::from_str(~"32767") == Some(i16_val)); fail_unless!((i16::from_str(~"32767") == Some(i16_val)));
assert (i16::from_str(~"32768").is_none()); fail_unless!((i16::from_str(~"32768").is_none()));
i16_val += 1 as i16; i16_val += 1 as i16;
assert (i16::from_str(~"-32768") == Some(i16_val)); fail_unless!((i16::from_str(~"-32768") == Some(i16_val)));
assert (i16::from_str(~"-32769").is_none()); fail_unless!((i16::from_str(~"-32769").is_none()));
let mut i32_val: i32 = 2_147_483_647_i32; let mut i32_val: i32 = 2_147_483_647_i32;
assert (i32::from_str(~"2147483647") == Some(i32_val)); fail_unless!((i32::from_str(~"2147483647") == Some(i32_val)));
assert (i32::from_str(~"2147483648").is_none()); fail_unless!((i32::from_str(~"2147483648").is_none()));
i32_val += 1 as i32; i32_val += 1 as i32;
assert (i32::from_str(~"-2147483648") == Some(i32_val)); fail_unless!((i32::from_str(~"-2147483648") == Some(i32_val)));
assert (i32::from_str(~"-2147483649").is_none()); fail_unless!((i32::from_str(~"-2147483649").is_none()));
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert (i64::from_str(~"9223372036854775807") == Some(i64_val)); fail_unless!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
assert (i64::from_str(~"9223372036854775808").is_none()); fail_unless!((i64::from_str(~"9223372036854775808").is_none()));
i64_val += 1 as i64; i64_val += 1 as i64;
assert (i64::from_str(~"-9223372036854775808") == Some(i64_val)); fail_unless!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
assert (i64::from_str(~"-9223372036854775809").is_none()); fail_unless!((i64::from_str(~"-9223372036854775809").is_none()));
} }
#[test] #[test]
@ -393,11 +393,11 @@ pub fn test_num() {
let ten: T = num::cast(10); let ten: T = num::cast(10);
let two: T = num::cast(2); let two: T = num::cast(2);
assert (ten.add(&two) == num::cast(12)); fail_unless!((ten.add(&two) == num::cast(12)));
assert (ten.sub(&two) == num::cast(8)); fail_unless!((ten.sub(&two) == num::cast(8)));
assert (ten.mul(&two) == num::cast(20)); fail_unless!((ten.mul(&two) == num::cast(20)));
assert (ten.div(&two) == num::cast(5)); fail_unless!((ten.div(&two) == num::cast(5)));
assert (ten.modulo(&two) == num::cast(0)); fail_unless!((ten.modulo(&two) == num::cast(0)));
} }
#[test] #[test]
@ -416,10 +416,10 @@ pub fn test_ranges() {
for range_step(36,30,-2) |i| { for range_step(36,30,-2) |i| {
l.push(i); l.push(i);
} }
assert l == ~[0,1,2, fail_unless!(l == ~[0,1,2,
13,12,11, 13,12,11,
20,22,24, 20,22,24,
36,34,32]; 36,34,32]);
// None of the `fail`s should execute. // None of the `fail`s should execute.
for range(10,0) |_i| { for range(10,0) |_i| {

View file

@ -43,45 +43,45 @@ impl NumCast for i16 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20i16.to_uint()); fail_unless!((20u == 20i16.to_uint()));
assert (20u8 == 20i16.to_u8()); fail_unless!((20u8 == 20i16.to_u8()));
assert (20u16 == 20i16.to_u16()); fail_unless!((20u16 == 20i16.to_u16()));
assert (20u32 == 20i16.to_u32()); fail_unless!((20u32 == 20i16.to_u32()));
assert (20u64 == 20i16.to_u64()); fail_unless!((20u64 == 20i16.to_u64()));
assert (20i == 20i16.to_int()); fail_unless!((20i == 20i16.to_int()));
assert (20i8 == 20i16.to_i8()); fail_unless!((20i8 == 20i16.to_i8()));
assert (20i16 == 20i16.to_i16()); fail_unless!((20i16 == 20i16.to_i16()));
assert (20i32 == 20i16.to_i32()); fail_unless!((20i32 == 20i16.to_i32()));
assert (20i64 == 20i16.to_i64()); fail_unless!((20i64 == 20i16.to_i64()));
assert (20f == 20i16.to_float()); fail_unless!((20f == 20i16.to_float()));
assert (20f32 == 20i16.to_f32()); fail_unless!((20f32 == 20i16.to_f32()));
assert (20f64 == 20i16.to_f64()); fail_unless!((20f64 == 20i16.to_f64()));
assert (20i16 == NumCast::from(20u)); fail_unless!((20i16 == NumCast::from(20u)));
assert (20i16 == NumCast::from(20u8)); fail_unless!((20i16 == NumCast::from(20u8)));
assert (20i16 == NumCast::from(20u16)); fail_unless!((20i16 == NumCast::from(20u16)));
assert (20i16 == NumCast::from(20u32)); fail_unless!((20i16 == NumCast::from(20u32)));
assert (20i16 == NumCast::from(20u64)); fail_unless!((20i16 == NumCast::from(20u64)));
assert (20i16 == NumCast::from(20i)); fail_unless!((20i16 == NumCast::from(20i)));
assert (20i16 == NumCast::from(20i8)); fail_unless!((20i16 == NumCast::from(20i8)));
assert (20i16 == NumCast::from(20i16)); fail_unless!((20i16 == NumCast::from(20i16)));
assert (20i16 == NumCast::from(20i32)); fail_unless!((20i16 == NumCast::from(20i32)));
assert (20i16 == NumCast::from(20i64)); fail_unless!((20i16 == NumCast::from(20i64)));
assert (20i16 == NumCast::from(20f)); fail_unless!((20i16 == NumCast::from(20f)));
assert (20i16 == NumCast::from(20f32)); fail_unless!((20i16 == NumCast::from(20f32)));
assert (20i16 == NumCast::from(20f64)); fail_unless!((20i16 == NumCast::from(20f64)));
assert (20i16 == num::cast(20u)); fail_unless!((20i16 == num::cast(20u)));
assert (20i16 == num::cast(20u8)); fail_unless!((20i16 == num::cast(20u8)));
assert (20i16 == num::cast(20u16)); fail_unless!((20i16 == num::cast(20u16)));
assert (20i16 == num::cast(20u32)); fail_unless!((20i16 == num::cast(20u32)));
assert (20i16 == num::cast(20u64)); fail_unless!((20i16 == num::cast(20u64)));
assert (20i16 == num::cast(20i)); fail_unless!((20i16 == num::cast(20i)));
assert (20i16 == num::cast(20i8)); fail_unless!((20i16 == num::cast(20i8)));
assert (20i16 == num::cast(20i16)); fail_unless!((20i16 == num::cast(20i16)));
assert (20i16 == num::cast(20i32)); fail_unless!((20i16 == num::cast(20i32)));
assert (20i16 == num::cast(20i64)); fail_unless!((20i16 == num::cast(20i64)));
assert (20i16 == num::cast(20f)); fail_unless!((20i16 == num::cast(20f)));
assert (20i16 == num::cast(20f32)); fail_unless!((20i16 == num::cast(20f32)));
assert (20i16 == num::cast(20f64)); fail_unless!((20i16 == num::cast(20f64)));
} }

View file

@ -43,45 +43,45 @@ impl NumCast for i32 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20i32.to_uint()); fail_unless!((20u == 20i32.to_uint()));
assert (20u8 == 20i32.to_u8()); fail_unless!((20u8 == 20i32.to_u8()));
assert (20u16 == 20i32.to_u16()); fail_unless!((20u16 == 20i32.to_u16()));
assert (20u32 == 20i32.to_u32()); fail_unless!((20u32 == 20i32.to_u32()));
assert (20u64 == 20i32.to_u64()); fail_unless!((20u64 == 20i32.to_u64()));
assert (20i == 20i32.to_int()); fail_unless!((20i == 20i32.to_int()));
assert (20i8 == 20i32.to_i8()); fail_unless!((20i8 == 20i32.to_i8()));
assert (20i16 == 20i32.to_i16()); fail_unless!((20i16 == 20i32.to_i16()));
assert (20i32 == 20i32.to_i32()); fail_unless!((20i32 == 20i32.to_i32()));
assert (20i64 == 20i32.to_i64()); fail_unless!((20i64 == 20i32.to_i64()));
assert (20f == 20i32.to_float()); fail_unless!((20f == 20i32.to_float()));
assert (20f32 == 20i32.to_f32()); fail_unless!((20f32 == 20i32.to_f32()));
assert (20f64 == 20i32.to_f64()); fail_unless!((20f64 == 20i32.to_f64()));
assert (20i32 == NumCast::from(20u)); fail_unless!((20i32 == NumCast::from(20u)));
assert (20i32 == NumCast::from(20u8)); fail_unless!((20i32 == NumCast::from(20u8)));
assert (20i32 == NumCast::from(20u16)); fail_unless!((20i32 == NumCast::from(20u16)));
assert (20i32 == NumCast::from(20u32)); fail_unless!((20i32 == NumCast::from(20u32)));
assert (20i32 == NumCast::from(20u64)); fail_unless!((20i32 == NumCast::from(20u64)));
assert (20i32 == NumCast::from(20i)); fail_unless!((20i32 == NumCast::from(20i)));
assert (20i32 == NumCast::from(20i8)); fail_unless!((20i32 == NumCast::from(20i8)));
assert (20i32 == NumCast::from(20i16)); fail_unless!((20i32 == NumCast::from(20i16)));
assert (20i32 == NumCast::from(20i32)); fail_unless!((20i32 == NumCast::from(20i32)));
assert (20i32 == NumCast::from(20i64)); fail_unless!((20i32 == NumCast::from(20i64)));
assert (20i32 == NumCast::from(20f)); fail_unless!((20i32 == NumCast::from(20f)));
assert (20i32 == NumCast::from(20f32)); fail_unless!((20i32 == NumCast::from(20f32)));
assert (20i32 == NumCast::from(20f64)); fail_unless!((20i32 == NumCast::from(20f64)));
assert (20i32 == num::cast(20u)); fail_unless!((20i32 == num::cast(20u)));
assert (20i32 == num::cast(20u8)); fail_unless!((20i32 == num::cast(20u8)));
assert (20i32 == num::cast(20u16)); fail_unless!((20i32 == num::cast(20u16)));
assert (20i32 == num::cast(20u32)); fail_unless!((20i32 == num::cast(20u32)));
assert (20i32 == num::cast(20u64)); fail_unless!((20i32 == num::cast(20u64)));
assert (20i32 == num::cast(20i)); fail_unless!((20i32 == num::cast(20i)));
assert (20i32 == num::cast(20i8)); fail_unless!((20i32 == num::cast(20i8)));
assert (20i32 == num::cast(20i16)); fail_unless!((20i32 == num::cast(20i16)));
assert (20i32 == num::cast(20i32)); fail_unless!((20i32 == num::cast(20i32)));
assert (20i32 == num::cast(20i64)); fail_unless!((20i32 == num::cast(20i64)));
assert (20i32 == num::cast(20f)); fail_unless!((20i32 == num::cast(20f)));
assert (20i32 == num::cast(20f32)); fail_unless!((20i32 == num::cast(20f32)));
assert (20i32 == num::cast(20f64)); fail_unless!((20i32 == num::cast(20f64)));
} }

View file

@ -43,45 +43,45 @@ impl NumCast for i64 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20i64.to_uint()); fail_unless!((20u == 20i64.to_uint()));
assert (20u8 == 20i64.to_u8()); fail_unless!((20u8 == 20i64.to_u8()));
assert (20u16 == 20i64.to_u16()); fail_unless!((20u16 == 20i64.to_u16()));
assert (20u32 == 20i64.to_u32()); fail_unless!((20u32 == 20i64.to_u32()));
assert (20u64 == 20i64.to_u64()); fail_unless!((20u64 == 20i64.to_u64()));
assert (20i == 20i64.to_int()); fail_unless!((20i == 20i64.to_int()));
assert (20i8 == 20i64.to_i8()); fail_unless!((20i8 == 20i64.to_i8()));
assert (20i16 == 20i64.to_i16()); fail_unless!((20i16 == 20i64.to_i16()));
assert (20i32 == 20i64.to_i32()); fail_unless!((20i32 == 20i64.to_i32()));
assert (20i64 == 20i64.to_i64()); fail_unless!((20i64 == 20i64.to_i64()));
assert (20f == 20i64.to_float()); fail_unless!((20f == 20i64.to_float()));
assert (20f32 == 20i64.to_f32()); fail_unless!((20f32 == 20i64.to_f32()));
assert (20f64 == 20i64.to_f64()); fail_unless!((20f64 == 20i64.to_f64()));
assert (20i64 == NumCast::from(20u)); fail_unless!((20i64 == NumCast::from(20u)));
assert (20i64 == NumCast::from(20u8)); fail_unless!((20i64 == NumCast::from(20u8)));
assert (20i64 == NumCast::from(20u16)); fail_unless!((20i64 == NumCast::from(20u16)));
assert (20i64 == NumCast::from(20u32)); fail_unless!((20i64 == NumCast::from(20u32)));
assert (20i64 == NumCast::from(20u64)); fail_unless!((20i64 == NumCast::from(20u64)));
assert (20i64 == NumCast::from(20i)); fail_unless!((20i64 == NumCast::from(20i)));
assert (20i64 == NumCast::from(20i8)); fail_unless!((20i64 == NumCast::from(20i8)));
assert (20i64 == NumCast::from(20i16)); fail_unless!((20i64 == NumCast::from(20i16)));
assert (20i64 == NumCast::from(20i32)); fail_unless!((20i64 == NumCast::from(20i32)));
assert (20i64 == NumCast::from(20i64)); fail_unless!((20i64 == NumCast::from(20i64)));
assert (20i64 == NumCast::from(20f)); fail_unless!((20i64 == NumCast::from(20f)));
assert (20i64 == NumCast::from(20f32)); fail_unless!((20i64 == NumCast::from(20f32)));
assert (20i64 == NumCast::from(20f64)); fail_unless!((20i64 == NumCast::from(20f64)));
assert (20i64 == num::cast(20u)); fail_unless!((20i64 == num::cast(20u)));
assert (20i64 == num::cast(20u8)); fail_unless!((20i64 == num::cast(20u8)));
assert (20i64 == num::cast(20u16)); fail_unless!((20i64 == num::cast(20u16)));
assert (20i64 == num::cast(20u32)); fail_unless!((20i64 == num::cast(20u32)));
assert (20i64 == num::cast(20u64)); fail_unless!((20i64 == num::cast(20u64)));
assert (20i64 == num::cast(20i)); fail_unless!((20i64 == num::cast(20i)));
assert (20i64 == num::cast(20i8)); fail_unless!((20i64 == num::cast(20i8)));
assert (20i64 == num::cast(20i16)); fail_unless!((20i64 == num::cast(20i16)));
assert (20i64 == num::cast(20i32)); fail_unless!((20i64 == num::cast(20i32)));
assert (20i64 == num::cast(20i64)); fail_unless!((20i64 == num::cast(20i64)));
assert (20i64 == num::cast(20f)); fail_unless!((20i64 == num::cast(20f)));
assert (20i64 == num::cast(20f32)); fail_unless!((20i64 == num::cast(20f32)));
assert (20i64 == num::cast(20f64)); fail_unless!((20i64 == num::cast(20f64)));
} }

View file

@ -43,45 +43,45 @@ impl NumCast for i8 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20i8.to_uint()); fail_unless!((20u == 20i8.to_uint()));
assert (20u8 == 20i8.to_u8()); fail_unless!((20u8 == 20i8.to_u8()));
assert (20u16 == 20i8.to_u16()); fail_unless!((20u16 == 20i8.to_u16()));
assert (20u32 == 20i8.to_u32()); fail_unless!((20u32 == 20i8.to_u32()));
assert (20u64 == 20i8.to_u64()); fail_unless!((20u64 == 20i8.to_u64()));
assert (20i == 20i8.to_int()); fail_unless!((20i == 20i8.to_int()));
assert (20i8 == 20i8.to_i8()); fail_unless!((20i8 == 20i8.to_i8()));
assert (20i16 == 20i8.to_i16()); fail_unless!((20i16 == 20i8.to_i16()));
assert (20i32 == 20i8.to_i32()); fail_unless!((20i32 == 20i8.to_i32()));
assert (20i64 == 20i8.to_i64()); fail_unless!((20i64 == 20i8.to_i64()));
assert (20f == 20i8.to_float()); fail_unless!((20f == 20i8.to_float()));
assert (20f32 == 20i8.to_f32()); fail_unless!((20f32 == 20i8.to_f32()));
assert (20f64 == 20i8.to_f64()); fail_unless!((20f64 == 20i8.to_f64()));
assert (20i8 == NumCast::from(20u)); fail_unless!((20i8 == NumCast::from(20u)));
assert (20i8 == NumCast::from(20u8)); fail_unless!((20i8 == NumCast::from(20u8)));
assert (20i8 == NumCast::from(20u16)); fail_unless!((20i8 == NumCast::from(20u16)));
assert (20i8 == NumCast::from(20u32)); fail_unless!((20i8 == NumCast::from(20u32)));
assert (20i8 == NumCast::from(20u64)); fail_unless!((20i8 == NumCast::from(20u64)));
assert (20i8 == NumCast::from(20i)); fail_unless!((20i8 == NumCast::from(20i)));
assert (20i8 == NumCast::from(20i8)); fail_unless!((20i8 == NumCast::from(20i8)));
assert (20i8 == NumCast::from(20i16)); fail_unless!((20i8 == NumCast::from(20i16)));
assert (20i8 == NumCast::from(20i32)); fail_unless!((20i8 == NumCast::from(20i32)));
assert (20i8 == NumCast::from(20i64)); fail_unless!((20i8 == NumCast::from(20i64)));
assert (20i8 == NumCast::from(20f)); fail_unless!((20i8 == NumCast::from(20f)));
assert (20i8 == NumCast::from(20f32)); fail_unless!((20i8 == NumCast::from(20f32)));
assert (20i8 == NumCast::from(20f64)); fail_unless!((20i8 == NumCast::from(20f64)));
assert (20i8 == num::cast(20u)); fail_unless!((20i8 == num::cast(20u)));
assert (20i8 == num::cast(20u8)); fail_unless!((20i8 == num::cast(20u8)));
assert (20i8 == num::cast(20u16)); fail_unless!((20i8 == num::cast(20u16)));
assert (20i8 == num::cast(20u32)); fail_unless!((20i8 == num::cast(20u32)));
assert (20i8 == num::cast(20u64)); fail_unless!((20i8 == num::cast(20u64)));
assert (20i8 == num::cast(20i)); fail_unless!((20i8 == num::cast(20i)));
assert (20i8 == num::cast(20i8)); fail_unless!((20i8 == num::cast(20i8)));
assert (20i8 == num::cast(20i16)); fail_unless!((20i8 == num::cast(20i16)));
assert (20i8 == num::cast(20i32)); fail_unless!((20i8 == num::cast(20i32)));
assert (20i8 == num::cast(20i64)); fail_unless!((20i8 == num::cast(20i64)));
assert (20i8 == num::cast(20f)); fail_unless!((20i8 == num::cast(20f)));
assert (20i8 == num::cast(20f32)); fail_unless!((20i8 == num::cast(20f32)));
assert (20i8 == num::cast(20f64)); fail_unless!((20i8 == num::cast(20f64)));
} }

View file

@ -40,21 +40,21 @@ mod inst {
#[test] #[test]
fn test_pow() { fn test_pow() {
assert (pow(0, 0u) == 1); fail_unless!((pow(0, 0u) == 1));
assert (pow(0, 1u) == 0); fail_unless!((pow(0, 1u) == 0));
assert (pow(0, 2u) == 0); fail_unless!((pow(0, 2u) == 0));
assert (pow(-1, 0u) == 1); fail_unless!((pow(-1, 0u) == 1));
assert (pow(1, 0u) == 1); fail_unless!((pow(1, 0u) == 1));
assert (pow(-3, 2u) == 9); fail_unless!((pow(-3, 2u) == 9));
assert (pow(-3, 3u) == -27); fail_unless!((pow(-3, 3u) == -27));
assert (pow(4, 9u) == 262144); fail_unless!((pow(4, 9u) == 262144));
} }
#[test] #[test]
fn test_overflows() { fn test_overflows() {
assert (::int::max_value > 0); fail_unless!((::int::max_value > 0));
assert (::int::min_value <= 0); fail_unless!((::int::min_value <= 0));
assert (::int::min_value + ::int::max_value + 1 == 0); fail_unless!((::int::min_value + ::int::max_value + 1 == 0));
} }
} }
@ -84,45 +84,45 @@ impl NumCast for int {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20i.to_uint()); fail_unless!((20u == 20i.to_uint()));
assert (20u8 == 20i.to_u8()); fail_unless!((20u8 == 20i.to_u8()));
assert (20u16 == 20i.to_u16()); fail_unless!((20u16 == 20i.to_u16()));
assert (20u32 == 20i.to_u32()); fail_unless!((20u32 == 20i.to_u32()));
assert (20u64 == 20i.to_u64()); fail_unless!((20u64 == 20i.to_u64()));
assert (20i == 20i.to_int()); fail_unless!((20i == 20i.to_int()));
assert (20i8 == 20i.to_i8()); fail_unless!((20i8 == 20i.to_i8()));
assert (20i16 == 20i.to_i16()); fail_unless!((20i16 == 20i.to_i16()));
assert (20i32 == 20i.to_i32()); fail_unless!((20i32 == 20i.to_i32()));
assert (20i64 == 20i.to_i64()); fail_unless!((20i64 == 20i.to_i64()));
assert (20f == 20i.to_float()); fail_unless!((20f == 20i.to_float()));
assert (20f32 == 20i.to_f32()); fail_unless!((20f32 == 20i.to_f32()));
assert (20f64 == 20i.to_f64()); fail_unless!((20f64 == 20i.to_f64()));
assert (20i == NumCast::from(20u)); fail_unless!((20i == NumCast::from(20u)));
assert (20i == NumCast::from(20u8)); fail_unless!((20i == NumCast::from(20u8)));
assert (20i == NumCast::from(20u16)); fail_unless!((20i == NumCast::from(20u16)));
assert (20i == NumCast::from(20u32)); fail_unless!((20i == NumCast::from(20u32)));
assert (20i == NumCast::from(20u64)); fail_unless!((20i == NumCast::from(20u64)));
assert (20i == NumCast::from(20i)); fail_unless!((20i == NumCast::from(20i)));
assert (20i == NumCast::from(20i8)); fail_unless!((20i == NumCast::from(20i8)));
assert (20i == NumCast::from(20i16)); fail_unless!((20i == NumCast::from(20i16)));
assert (20i == NumCast::from(20i32)); fail_unless!((20i == NumCast::from(20i32)));
assert (20i == NumCast::from(20i64)); fail_unless!((20i == NumCast::from(20i64)));
assert (20i == NumCast::from(20f)); fail_unless!((20i == NumCast::from(20f)));
assert (20i == NumCast::from(20f32)); fail_unless!((20i == NumCast::from(20f32)));
assert (20i == NumCast::from(20f64)); fail_unless!((20i == NumCast::from(20f64)));
assert (20i == num::cast(20u)); fail_unless!((20i == num::cast(20u)));
assert (20i == num::cast(20u8)); fail_unless!((20i == num::cast(20u8)));
assert (20i == num::cast(20u16)); fail_unless!((20i == num::cast(20u16)));
assert (20i == num::cast(20u32)); fail_unless!((20i == num::cast(20u32)));
assert (20i == num::cast(20u64)); fail_unless!((20i == num::cast(20u64)));
assert (20i == num::cast(20i)); fail_unless!((20i == num::cast(20i)));
assert (20i == num::cast(20i8)); fail_unless!((20i == num::cast(20i8)));
assert (20i == num::cast(20i16)); fail_unless!((20i == num::cast(20i16)));
assert (20i == num::cast(20i32)); fail_unless!((20i == num::cast(20i32)));
assert (20i == num::cast(20i64)); fail_unless!((20i == num::cast(20i64)));
assert (20i == num::cast(20f)); fail_unless!((20i == num::cast(20f)));
assert (20i == num::cast(20f32)); fail_unless!((20i == num::cast(20f32)));
assert (20i == num::cast(20f64)); fail_unless!((20i == num::cast(20f64)));
} }

View file

@ -55,7 +55,7 @@ pub enum RoundMode {
* *
* ~~~ * ~~~
* let twenty: f32 = num::cast(0x14); * let twenty: f32 = num::cast(0x14);
* assert twenty == 20f32; * fail_unless!(twenty == 20f32);
* ~~~ * ~~~
*/ */
#[inline(always)] #[inline(always)]

View file

@ -238,102 +238,102 @@ impl ToStrRadix for T {
#[test] #[test]
pub fn test_to_str() { pub fn test_to_str() {
assert to_str_radix(0 as T, 10u) == ~"0"; fail_unless!(to_str_radix(0 as T, 10u) == ~"0");
assert to_str_radix(1 as T, 10u) == ~"1"; fail_unless!(to_str_radix(1 as T, 10u) == ~"1");
assert to_str_radix(2 as T, 10u) == ~"2"; fail_unless!(to_str_radix(2 as T, 10u) == ~"2");
assert to_str_radix(11 as T, 10u) == ~"11"; fail_unless!(to_str_radix(11 as T, 10u) == ~"11");
assert to_str_radix(11 as T, 16u) == ~"b"; fail_unless!(to_str_radix(11 as T, 16u) == ~"b");
assert to_str_radix(255 as T, 16u) == ~"ff"; fail_unless!(to_str_radix(255 as T, 16u) == ~"ff");
assert to_str_radix(0xff as T, 10u) == ~"255"; fail_unless!(to_str_radix(0xff as T, 10u) == ~"255");
} }
#[test] #[test]
pub fn test_from_str() { pub fn test_from_str() {
assert from_str(~"0") == Some(0u as T); fail_unless!(from_str(~"0") == Some(0u as T));
assert from_str(~"3") == Some(3u as T); fail_unless!(from_str(~"3") == Some(3u as T));
assert from_str(~"10") == Some(10u as T); fail_unless!(from_str(~"10") == Some(10u as T));
assert u32::from_str(~"123456789") == Some(123456789 as u32); fail_unless!(u32::from_str(~"123456789") == Some(123456789 as u32));
assert from_str(~"00100") == Some(100u as T); fail_unless!(from_str(~"00100") == Some(100u as T));
assert from_str(~"").is_none(); fail_unless!(from_str(~"").is_none());
assert from_str(~" ").is_none(); fail_unless!(from_str(~" ").is_none());
assert from_str(~"x").is_none(); fail_unless!(from_str(~"x").is_none());
} }
#[test] #[test]
pub fn test_parse_bytes() { pub fn test_parse_bytes() {
use str::to_bytes; use str::to_bytes;
assert parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T); fail_unless!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
assert parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T); fail_unless!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
assert parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T); fail_unless!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
assert u16::parse_bytes(to_bytes(~"123"), 16u) == Some(291u as u16); fail_unless!(u16::parse_bytes(to_bytes(~"123"), 16u) == Some(291u as u16));
assert u16::parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535u as u16); fail_unless!(u16::parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535u as u16));
assert parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T); fail_unless!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
assert parse_bytes(to_bytes(~"Z"), 10u).is_none(); fail_unless!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
assert parse_bytes(to_bytes(~"_"), 2u).is_none(); fail_unless!(parse_bytes(to_bytes(~"_"), 2u).is_none());
} }
#[test] #[test]
fn test_uint_to_str_overflow() { fn test_uint_to_str_overflow() {
let mut u8_val: u8 = 255_u8; let mut u8_val: u8 = 255_u8;
assert (u8::to_str(u8_val) == ~"255"); fail_unless!((u8::to_str(u8_val) == ~"255"));
u8_val += 1 as u8; u8_val += 1 as u8;
assert (u8::to_str(u8_val) == ~"0"); fail_unless!((u8::to_str(u8_val) == ~"0"));
let mut u16_val: u16 = 65_535_u16; let mut u16_val: u16 = 65_535_u16;
assert (u16::to_str(u16_val) == ~"65535"); fail_unless!((u16::to_str(u16_val) == ~"65535"));
u16_val += 1 as u16; u16_val += 1 as u16;
assert (u16::to_str(u16_val) == ~"0"); fail_unless!((u16::to_str(u16_val) == ~"0"));
let mut u32_val: u32 = 4_294_967_295_u32; let mut u32_val: u32 = 4_294_967_295_u32;
assert (u32::to_str(u32_val) == ~"4294967295"); fail_unless!((u32::to_str(u32_val) == ~"4294967295"));
u32_val += 1 as u32; u32_val += 1 as u32;
assert (u32::to_str(u32_val) == ~"0"); fail_unless!((u32::to_str(u32_val) == ~"0"));
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert (u64::to_str(u64_val) == ~"18446744073709551615"); fail_unless!((u64::to_str(u64_val) == ~"18446744073709551615"));
u64_val += 1 as u64; u64_val += 1 as u64;
assert (u64::to_str(u64_val) == ~"0"); fail_unless!((u64::to_str(u64_val) == ~"0"));
} }
#[test] #[test]
fn test_uint_from_str_overflow() { fn test_uint_from_str_overflow() {
let mut u8_val: u8 = 255_u8; let mut u8_val: u8 = 255_u8;
assert (u8::from_str(~"255") == Some(u8_val)); fail_unless!((u8::from_str(~"255") == Some(u8_val)));
assert (u8::from_str(~"256").is_none()); fail_unless!((u8::from_str(~"256").is_none()));
u8_val += 1 as u8; u8_val += 1 as u8;
assert (u8::from_str(~"0") == Some(u8_val)); fail_unless!((u8::from_str(~"0") == Some(u8_val)));
assert (u8::from_str(~"-1").is_none()); fail_unless!((u8::from_str(~"-1").is_none()));
let mut u16_val: u16 = 65_535_u16; let mut u16_val: u16 = 65_535_u16;
assert (u16::from_str(~"65535") == Some(u16_val)); fail_unless!((u16::from_str(~"65535") == Some(u16_val)));
assert (u16::from_str(~"65536").is_none()); fail_unless!((u16::from_str(~"65536").is_none()));
u16_val += 1 as u16; u16_val += 1 as u16;
assert (u16::from_str(~"0") == Some(u16_val)); fail_unless!((u16::from_str(~"0") == Some(u16_val)));
assert (u16::from_str(~"-1").is_none()); fail_unless!((u16::from_str(~"-1").is_none()));
let mut u32_val: u32 = 4_294_967_295_u32; let mut u32_val: u32 = 4_294_967_295_u32;
assert (u32::from_str(~"4294967295") == Some(u32_val)); fail_unless!((u32::from_str(~"4294967295") == Some(u32_val)));
assert (u32::from_str(~"4294967296").is_none()); fail_unless!((u32::from_str(~"4294967296").is_none()));
u32_val += 1 as u32; u32_val += 1 as u32;
assert (u32::from_str(~"0") == Some(u32_val)); fail_unless!((u32::from_str(~"0") == Some(u32_val)));
assert (u32::from_str(~"-1").is_none()); fail_unless!((u32::from_str(~"-1").is_none()));
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert (u64::from_str(~"18446744073709551615") == Some(u64_val)); fail_unless!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
assert (u64::from_str(~"18446744073709551616").is_none()); fail_unless!((u64::from_str(~"18446744073709551616").is_none()));
u64_val += 1 as u64; u64_val += 1 as u64;
assert (u64::from_str(~"0") == Some(u64_val)); fail_unless!((u64::from_str(~"0") == Some(u64_val)));
assert (u64::from_str(~"-1").is_none()); fail_unless!((u64::from_str(~"-1").is_none()));
} }
#[test] #[test]
@ -367,10 +367,10 @@ pub fn test_ranges() {
l.push(i); l.push(i);
} }
assert l == ~[0,1,2, fail_unless!(l == ~[0,1,2,
13,12,11, 13,12,11,
20,22,24, 20,22,24,
36,34,32]; 36,34,32]);
// None of the `fail`s should execute. // None of the `fail`s should execute.
for range(0,0) |_i| { for range(0,0) |_i| {
@ -392,11 +392,11 @@ pub fn test_num() {
let ten: T = num::cast(10); let ten: T = num::cast(10);
let two: T = num::cast(2); let two: T = num::cast(2);
assert (ten.add(&two) == num::cast(12)); fail_unless!((ten.add(&two) == num::cast(12)));
assert (ten.sub(&two) == num::cast(8)); fail_unless!((ten.sub(&two) == num::cast(8)));
assert (ten.mul(&two) == num::cast(20)); fail_unless!((ten.mul(&two) == num::cast(20)));
assert (ten.div(&two) == num::cast(5)); fail_unless!((ten.div(&two) == num::cast(5)));
assert (ten.modulo(&two) == num::cast(0)); fail_unless!((ten.modulo(&two) == num::cast(0)));
} }
#[test] #[test]

View file

@ -45,45 +45,45 @@ impl NumCast for u16 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20u16.to_uint()); fail_unless!((20u == 20u16.to_uint()));
assert (20u8 == 20u16.to_u8()); fail_unless!((20u8 == 20u16.to_u8()));
assert (20u16 == 20u16.to_u16()); fail_unless!((20u16 == 20u16.to_u16()));
assert (20u32 == 20u16.to_u32()); fail_unless!((20u32 == 20u16.to_u32()));
assert (20u64 == 20u16.to_u64()); fail_unless!((20u64 == 20u16.to_u64()));
assert (20i == 20u16.to_int()); fail_unless!((20i == 20u16.to_int()));
assert (20i8 == 20u16.to_i8()); fail_unless!((20i8 == 20u16.to_i8()));
assert (20i16 == 20u16.to_i16()); fail_unless!((20i16 == 20u16.to_i16()));
assert (20i32 == 20u16.to_i32()); fail_unless!((20i32 == 20u16.to_i32()));
assert (20i64 == 20u16.to_i64()); fail_unless!((20i64 == 20u16.to_i64()));
assert (20f == 20u16.to_float()); fail_unless!((20f == 20u16.to_float()));
assert (20f32 == 20u16.to_f32()); fail_unless!((20f32 == 20u16.to_f32()));
assert (20f64 == 20u16.to_f64()); fail_unless!((20f64 == 20u16.to_f64()));
assert (20u16 == NumCast::from(20u)); fail_unless!((20u16 == NumCast::from(20u)));
assert (20u16 == NumCast::from(20u8)); fail_unless!((20u16 == NumCast::from(20u8)));
assert (20u16 == NumCast::from(20u16)); fail_unless!((20u16 == NumCast::from(20u16)));
assert (20u16 == NumCast::from(20u32)); fail_unless!((20u16 == NumCast::from(20u32)));
assert (20u16 == NumCast::from(20u64)); fail_unless!((20u16 == NumCast::from(20u64)));
assert (20u16 == NumCast::from(20i)); fail_unless!((20u16 == NumCast::from(20i)));
assert (20u16 == NumCast::from(20i8)); fail_unless!((20u16 == NumCast::from(20i8)));
assert (20u16 == NumCast::from(20i16)); fail_unless!((20u16 == NumCast::from(20i16)));
assert (20u16 == NumCast::from(20i32)); fail_unless!((20u16 == NumCast::from(20i32)));
assert (20u16 == NumCast::from(20i64)); fail_unless!((20u16 == NumCast::from(20i64)));
assert (20u16 == NumCast::from(20f)); fail_unless!((20u16 == NumCast::from(20f)));
assert (20u16 == NumCast::from(20f32)); fail_unless!((20u16 == NumCast::from(20f32)));
assert (20u16 == NumCast::from(20f64)); fail_unless!((20u16 == NumCast::from(20f64)));
assert (20u16 == num::cast(20u)); fail_unless!((20u16 == num::cast(20u)));
assert (20u16 == num::cast(20u8)); fail_unless!((20u16 == num::cast(20u8)));
assert (20u16 == num::cast(20u16)); fail_unless!((20u16 == num::cast(20u16)));
assert (20u16 == num::cast(20u32)); fail_unless!((20u16 == num::cast(20u32)));
assert (20u16 == num::cast(20u64)); fail_unless!((20u16 == num::cast(20u64)));
assert (20u16 == num::cast(20i)); fail_unless!((20u16 == num::cast(20i)));
assert (20u16 == num::cast(20i8)); fail_unless!((20u16 == num::cast(20i8)));
assert (20u16 == num::cast(20i16)); fail_unless!((20u16 == num::cast(20i16)));
assert (20u16 == num::cast(20i32)); fail_unless!((20u16 == num::cast(20i32)));
assert (20u16 == num::cast(20i64)); fail_unless!((20u16 == num::cast(20i64)));
assert (20u16 == num::cast(20f)); fail_unless!((20u16 == num::cast(20f)));
assert (20u16 == num::cast(20f32)); fail_unless!((20u16 == num::cast(20f32)));
assert (20u16 == num::cast(20f64)); fail_unless!((20u16 == num::cast(20f64)));
} }

View file

@ -45,45 +45,45 @@ impl NumCast for u32 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20u64.to_uint()); fail_unless!((20u == 20u64.to_uint()));
assert (20u8 == 20u64.to_u8()); fail_unless!((20u8 == 20u64.to_u8()));
assert (20u16 == 20u64.to_u16()); fail_unless!((20u16 == 20u64.to_u16()));
assert (20u32 == 20u64.to_u32()); fail_unless!((20u32 == 20u64.to_u32()));
assert (20u64 == 20u64.to_u64()); fail_unless!((20u64 == 20u64.to_u64()));
assert (20i == 20u64.to_int()); fail_unless!((20i == 20u64.to_int()));
assert (20i8 == 20u64.to_i8()); fail_unless!((20i8 == 20u64.to_i8()));
assert (20i16 == 20u64.to_i16()); fail_unless!((20i16 == 20u64.to_i16()));
assert (20i32 == 20u64.to_i32()); fail_unless!((20i32 == 20u64.to_i32()));
assert (20i64 == 20u64.to_i64()); fail_unless!((20i64 == 20u64.to_i64()));
assert (20f == 20u64.to_float()); fail_unless!((20f == 20u64.to_float()));
assert (20f32 == 20u64.to_f32()); fail_unless!((20f32 == 20u64.to_f32()));
assert (20f64 == 20u64.to_f64()); fail_unless!((20f64 == 20u64.to_f64()));
assert (20u64 == NumCast::from(20u)); fail_unless!((20u64 == NumCast::from(20u)));
assert (20u64 == NumCast::from(20u8)); fail_unless!((20u64 == NumCast::from(20u8)));
assert (20u64 == NumCast::from(20u16)); fail_unless!((20u64 == NumCast::from(20u16)));
assert (20u64 == NumCast::from(20u32)); fail_unless!((20u64 == NumCast::from(20u32)));
assert (20u64 == NumCast::from(20u64)); fail_unless!((20u64 == NumCast::from(20u64)));
assert (20u64 == NumCast::from(20i)); fail_unless!((20u64 == NumCast::from(20i)));
assert (20u64 == NumCast::from(20i8)); fail_unless!((20u64 == NumCast::from(20i8)));
assert (20u64 == NumCast::from(20i16)); fail_unless!((20u64 == NumCast::from(20i16)));
assert (20u64 == NumCast::from(20i32)); fail_unless!((20u64 == NumCast::from(20i32)));
assert (20u64 == NumCast::from(20i64)); fail_unless!((20u64 == NumCast::from(20i64)));
assert (20u64 == NumCast::from(20f)); fail_unless!((20u64 == NumCast::from(20f)));
assert (20u64 == NumCast::from(20f32)); fail_unless!((20u64 == NumCast::from(20f32)));
assert (20u64 == NumCast::from(20f64)); fail_unless!((20u64 == NumCast::from(20f64)));
assert (20u64 == num::cast(20u)); fail_unless!((20u64 == num::cast(20u)));
assert (20u64 == num::cast(20u8)); fail_unless!((20u64 == num::cast(20u8)));
assert (20u64 == num::cast(20u16)); fail_unless!((20u64 == num::cast(20u16)));
assert (20u64 == num::cast(20u32)); fail_unless!((20u64 == num::cast(20u32)));
assert (20u64 == num::cast(20u64)); fail_unless!((20u64 == num::cast(20u64)));
assert (20u64 == num::cast(20i)); fail_unless!((20u64 == num::cast(20i)));
assert (20u64 == num::cast(20i8)); fail_unless!((20u64 == num::cast(20i8)));
assert (20u64 == num::cast(20i16)); fail_unless!((20u64 == num::cast(20i16)));
assert (20u64 == num::cast(20i32)); fail_unless!((20u64 == num::cast(20i32)));
assert (20u64 == num::cast(20i64)); fail_unless!((20u64 == num::cast(20i64)));
assert (20u64 == num::cast(20f)); fail_unless!((20u64 == num::cast(20f)));
assert (20u64 == num::cast(20f32)); fail_unless!((20u64 == num::cast(20f32)));
assert (20u64 == num::cast(20f64)); fail_unless!((20u64 == num::cast(20f64)));
} }

View file

@ -45,45 +45,45 @@ impl NumCast for u64 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20u64.to_uint()); fail_unless!((20u == 20u64.to_uint()));
assert (20u8 == 20u64.to_u8()); fail_unless!((20u8 == 20u64.to_u8()));
assert (20u16 == 20u64.to_u16()); fail_unless!((20u16 == 20u64.to_u16()));
assert (20u32 == 20u64.to_u32()); fail_unless!((20u32 == 20u64.to_u32()));
assert (20u64 == 20u64.to_u64()); fail_unless!((20u64 == 20u64.to_u64()));
assert (20i == 20u64.to_int()); fail_unless!((20i == 20u64.to_int()));
assert (20i8 == 20u64.to_i8()); fail_unless!((20i8 == 20u64.to_i8()));
assert (20i16 == 20u64.to_i16()); fail_unless!((20i16 == 20u64.to_i16()));
assert (20i32 == 20u64.to_i32()); fail_unless!((20i32 == 20u64.to_i32()));
assert (20i64 == 20u64.to_i64()); fail_unless!((20i64 == 20u64.to_i64()));
assert (20f == 20u64.to_float()); fail_unless!((20f == 20u64.to_float()));
assert (20f32 == 20u64.to_f32()); fail_unless!((20f32 == 20u64.to_f32()));
assert (20f64 == 20u64.to_f64()); fail_unless!((20f64 == 20u64.to_f64()));
assert (20u64 == NumCast::from(20u)); fail_unless!((20u64 == NumCast::from(20u)));
assert (20u64 == NumCast::from(20u8)); fail_unless!((20u64 == NumCast::from(20u8)));
assert (20u64 == NumCast::from(20u16)); fail_unless!((20u64 == NumCast::from(20u16)));
assert (20u64 == NumCast::from(20u32)); fail_unless!((20u64 == NumCast::from(20u32)));
assert (20u64 == NumCast::from(20u64)); fail_unless!((20u64 == NumCast::from(20u64)));
assert (20u64 == NumCast::from(20i)); fail_unless!((20u64 == NumCast::from(20i)));
assert (20u64 == NumCast::from(20i8)); fail_unless!((20u64 == NumCast::from(20i8)));
assert (20u64 == NumCast::from(20i16)); fail_unless!((20u64 == NumCast::from(20i16)));
assert (20u64 == NumCast::from(20i32)); fail_unless!((20u64 == NumCast::from(20i32)));
assert (20u64 == NumCast::from(20i64)); fail_unless!((20u64 == NumCast::from(20i64)));
assert (20u64 == NumCast::from(20f)); fail_unless!((20u64 == NumCast::from(20f)));
assert (20u64 == NumCast::from(20f32)); fail_unless!((20u64 == NumCast::from(20f32)));
assert (20u64 == NumCast::from(20f64)); fail_unless!((20u64 == NumCast::from(20f64)));
assert (20u64 == num::cast(20u)); fail_unless!((20u64 == num::cast(20u)));
assert (20u64 == num::cast(20u8)); fail_unless!((20u64 == num::cast(20u8)));
assert (20u64 == num::cast(20u16)); fail_unless!((20u64 == num::cast(20u16)));
assert (20u64 == num::cast(20u32)); fail_unless!((20u64 == num::cast(20u32)));
assert (20u64 == num::cast(20u64)); fail_unless!((20u64 == num::cast(20u64)));
assert (20u64 == num::cast(20i)); fail_unless!((20u64 == num::cast(20i)));
assert (20u64 == num::cast(20i8)); fail_unless!((20u64 == num::cast(20i8)));
assert (20u64 == num::cast(20i16)); fail_unless!((20u64 == num::cast(20i16)));
assert (20u64 == num::cast(20i32)); fail_unless!((20u64 == num::cast(20i32)));
assert (20u64 == num::cast(20i64)); fail_unless!((20u64 == num::cast(20i64)));
assert (20u64 == num::cast(20f)); fail_unless!((20u64 == num::cast(20f)));
assert (20u64 == num::cast(20f32)); fail_unless!((20u64 == num::cast(20f32)));
assert (20u64 == num::cast(20f64)); fail_unless!((20u64 == num::cast(20f64)));
} }

View file

@ -52,45 +52,45 @@ impl NumCast for u8 {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20u8.to_uint()); fail_unless!((20u == 20u8.to_uint()));
assert (20u8 == 20u8.to_u8()); fail_unless!((20u8 == 20u8.to_u8()));
assert (20u16 == 20u8.to_u16()); fail_unless!((20u16 == 20u8.to_u16()));
assert (20u32 == 20u8.to_u32()); fail_unless!((20u32 == 20u8.to_u32()));
assert (20u64 == 20u8.to_u64()); fail_unless!((20u64 == 20u8.to_u64()));
assert (20i == 20u8.to_int()); fail_unless!((20i == 20u8.to_int()));
assert (20i8 == 20u8.to_i8()); fail_unless!((20i8 == 20u8.to_i8()));
assert (20i16 == 20u8.to_i16()); fail_unless!((20i16 == 20u8.to_i16()));
assert (20i32 == 20u8.to_i32()); fail_unless!((20i32 == 20u8.to_i32()));
assert (20i64 == 20u8.to_i64()); fail_unless!((20i64 == 20u8.to_i64()));
assert (20f == 20u8.to_float()); fail_unless!((20f == 20u8.to_float()));
assert (20f32 == 20u8.to_f32()); fail_unless!((20f32 == 20u8.to_f32()));
assert (20f64 == 20u8.to_f64()); fail_unless!((20f64 == 20u8.to_f64()));
assert (20u8 == NumCast::from(20u)); fail_unless!((20u8 == NumCast::from(20u)));
assert (20u8 == NumCast::from(20u8)); fail_unless!((20u8 == NumCast::from(20u8)));
assert (20u8 == NumCast::from(20u16)); fail_unless!((20u8 == NumCast::from(20u16)));
assert (20u8 == NumCast::from(20u32)); fail_unless!((20u8 == NumCast::from(20u32)));
assert (20u8 == NumCast::from(20u64)); fail_unless!((20u8 == NumCast::from(20u64)));
assert (20u8 == NumCast::from(20i)); fail_unless!((20u8 == NumCast::from(20i)));
assert (20u8 == NumCast::from(20i8)); fail_unless!((20u8 == NumCast::from(20i8)));
assert (20u8 == NumCast::from(20i16)); fail_unless!((20u8 == NumCast::from(20i16)));
assert (20u8 == NumCast::from(20i32)); fail_unless!((20u8 == NumCast::from(20i32)));
assert (20u8 == NumCast::from(20i64)); fail_unless!((20u8 == NumCast::from(20i64)));
assert (20u8 == NumCast::from(20f)); fail_unless!((20u8 == NumCast::from(20f)));
assert (20u8 == NumCast::from(20f32)); fail_unless!((20u8 == NumCast::from(20f32)));
assert (20u8 == NumCast::from(20f64)); fail_unless!((20u8 == NumCast::from(20f64)));
assert (20u8 == num::cast(20u)); fail_unless!((20u8 == num::cast(20u)));
assert (20u8 == num::cast(20u8)); fail_unless!((20u8 == num::cast(20u8)));
assert (20u8 == num::cast(20u16)); fail_unless!((20u8 == num::cast(20u16)));
assert (20u8 == num::cast(20u32)); fail_unless!((20u8 == num::cast(20u32)));
assert (20u8 == num::cast(20u64)); fail_unless!((20u8 == num::cast(20u64)));
assert (20u8 == num::cast(20i)); fail_unless!((20u8 == num::cast(20i)));
assert (20u8 == num::cast(20i8)); fail_unless!((20u8 == num::cast(20i8)));
assert (20u8 == num::cast(20i16)); fail_unless!((20u8 == num::cast(20i16)));
assert (20u8 == num::cast(20i32)); fail_unless!((20u8 == num::cast(20i32)));
assert (20u8 == num::cast(20i64)); fail_unless!((20u8 == num::cast(20i64)));
assert (20u8 == num::cast(20f)); fail_unless!((20u8 == num::cast(20f)));
assert (20u8 == num::cast(20f32)); fail_unless!((20u8 == num::cast(20f32)));
assert (20u8 == num::cast(20f64)); fail_unless!((20u8 == num::cast(20f64)));
} }

View file

@ -143,61 +143,61 @@ pub mod inst {
#[test] #[test]
fn test_next_power_of_two() { fn test_next_power_of_two() {
assert (next_power_of_two(0u) == 0u); fail_unless!((next_power_of_two(0u) == 0u));
assert (next_power_of_two(1u) == 1u); fail_unless!((next_power_of_two(1u) == 1u));
assert (next_power_of_two(2u) == 2u); fail_unless!((next_power_of_two(2u) == 2u));
assert (next_power_of_two(3u) == 4u); fail_unless!((next_power_of_two(3u) == 4u));
assert (next_power_of_two(4u) == 4u); fail_unless!((next_power_of_two(4u) == 4u));
assert (next_power_of_two(5u) == 8u); fail_unless!((next_power_of_two(5u) == 8u));
assert (next_power_of_two(6u) == 8u); fail_unless!((next_power_of_two(6u) == 8u));
assert (next_power_of_two(7u) == 8u); fail_unless!((next_power_of_two(7u) == 8u));
assert (next_power_of_two(8u) == 8u); fail_unless!((next_power_of_two(8u) == 8u));
assert (next_power_of_two(9u) == 16u); fail_unless!((next_power_of_two(9u) == 16u));
assert (next_power_of_two(10u) == 16u); fail_unless!((next_power_of_two(10u) == 16u));
assert (next_power_of_two(11u) == 16u); fail_unless!((next_power_of_two(11u) == 16u));
assert (next_power_of_two(12u) == 16u); fail_unless!((next_power_of_two(12u) == 16u));
assert (next_power_of_two(13u) == 16u); fail_unless!((next_power_of_two(13u) == 16u));
assert (next_power_of_two(14u) == 16u); fail_unless!((next_power_of_two(14u) == 16u));
assert (next_power_of_two(15u) == 16u); fail_unless!((next_power_of_two(15u) == 16u));
assert (next_power_of_two(16u) == 16u); fail_unless!((next_power_of_two(16u) == 16u));
assert (next_power_of_two(17u) == 32u); fail_unless!((next_power_of_two(17u) == 32u));
assert (next_power_of_two(18u) == 32u); fail_unless!((next_power_of_two(18u) == 32u));
assert (next_power_of_two(19u) == 32u); fail_unless!((next_power_of_two(19u) == 32u));
assert (next_power_of_two(20u) == 32u); fail_unless!((next_power_of_two(20u) == 32u));
assert (next_power_of_two(21u) == 32u); fail_unless!((next_power_of_two(21u) == 32u));
assert (next_power_of_two(22u) == 32u); fail_unless!((next_power_of_two(22u) == 32u));
assert (next_power_of_two(23u) == 32u); fail_unless!((next_power_of_two(23u) == 32u));
assert (next_power_of_two(24u) == 32u); fail_unless!((next_power_of_two(24u) == 32u));
assert (next_power_of_two(25u) == 32u); fail_unless!((next_power_of_two(25u) == 32u));
assert (next_power_of_two(26u) == 32u); fail_unless!((next_power_of_two(26u) == 32u));
assert (next_power_of_two(27u) == 32u); fail_unless!((next_power_of_two(27u) == 32u));
assert (next_power_of_two(28u) == 32u); fail_unless!((next_power_of_two(28u) == 32u));
assert (next_power_of_two(29u) == 32u); fail_unless!((next_power_of_two(29u) == 32u));
assert (next_power_of_two(30u) == 32u); fail_unless!((next_power_of_two(30u) == 32u));
assert (next_power_of_two(31u) == 32u); fail_unless!((next_power_of_two(31u) == 32u));
assert (next_power_of_two(32u) == 32u); fail_unless!((next_power_of_two(32u) == 32u));
assert (next_power_of_two(33u) == 64u); fail_unless!((next_power_of_two(33u) == 64u));
assert (next_power_of_two(34u) == 64u); fail_unless!((next_power_of_two(34u) == 64u));
assert (next_power_of_two(35u) == 64u); fail_unless!((next_power_of_two(35u) == 64u));
assert (next_power_of_two(36u) == 64u); fail_unless!((next_power_of_two(36u) == 64u));
assert (next_power_of_two(37u) == 64u); fail_unless!((next_power_of_two(37u) == 64u));
assert (next_power_of_two(38u) == 64u); fail_unless!((next_power_of_two(38u) == 64u));
assert (next_power_of_two(39u) == 64u); fail_unless!((next_power_of_two(39u) == 64u));
} }
#[test] #[test]
fn test_overflows() { fn test_overflows() {
use uint; use uint;
assert (uint::max_value > 0u); fail_unless!((uint::max_value > 0u));
assert (uint::min_value <= 0u); fail_unless!((uint::min_value <= 0u));
assert (uint::min_value + uint::max_value + 1u == 0u); fail_unless!((uint::min_value + uint::max_value + 1u == 0u));
} }
#[test] #[test]
fn test_div() { fn test_div() {
assert(div_floor(3u, 4u) == 0u); fail_unless!((div_floor(3u, 4u) == 0u));
assert(div_ceil(3u, 4u) == 1u); fail_unless!((div_ceil(3u, 4u) == 1u));
assert(div_round(3u, 4u) == 1u); fail_unless!((div_round(3u, 4u) == 1u));
} }
#[test] #[test]
@ -206,7 +206,7 @@ pub mod inst {
let ten = 10 as uint; let ten = 10 as uint;
let mut accum = 0; let mut accum = 0;
for ten.times { accum += 1; } for ten.times { accum += 1; }
assert (accum == 10); fail_unless!((accum == 10));
} }
} }
@ -236,45 +236,45 @@ impl NumCast for uint {
#[test] #[test]
fn test_numcast() { fn test_numcast() {
assert (20u == 20u.to_uint()); fail_unless!((20u == 20u.to_uint()));
assert (20u8 == 20u.to_u8()); fail_unless!((20u8 == 20u.to_u8()));
assert (20u16 == 20u.to_u16()); fail_unless!((20u16 == 20u.to_u16()));
assert (20u32 == 20u.to_u32()); fail_unless!((20u32 == 20u.to_u32()));
assert (20u64 == 20u.to_u64()); fail_unless!((20u64 == 20u.to_u64()));
assert (20i == 20u.to_int()); fail_unless!((20i == 20u.to_int()));
assert (20i8 == 20u.to_i8()); fail_unless!((20i8 == 20u.to_i8()));
assert (20i16 == 20u.to_i16()); fail_unless!((20i16 == 20u.to_i16()));
assert (20i32 == 20u.to_i32()); fail_unless!((20i32 == 20u.to_i32()));
assert (20i64 == 20u.to_i64()); fail_unless!((20i64 == 20u.to_i64()));
assert (20f == 20u.to_float()); fail_unless!((20f == 20u.to_float()));
assert (20f32 == 20u.to_f32()); fail_unless!((20f32 == 20u.to_f32()));
assert (20f64 == 20u.to_f64()); fail_unless!((20f64 == 20u.to_f64()));
assert (20u == NumCast::from(20u)); fail_unless!((20u == NumCast::from(20u)));
assert (20u == NumCast::from(20u8)); fail_unless!((20u == NumCast::from(20u8)));
assert (20u == NumCast::from(20u16)); fail_unless!((20u == NumCast::from(20u16)));
assert (20u == NumCast::from(20u32)); fail_unless!((20u == NumCast::from(20u32)));
assert (20u == NumCast::from(20u64)); fail_unless!((20u == NumCast::from(20u64)));
assert (20u == NumCast::from(20i)); fail_unless!((20u == NumCast::from(20i)));
assert (20u == NumCast::from(20i8)); fail_unless!((20u == NumCast::from(20i8)));
assert (20u == NumCast::from(20i16)); fail_unless!((20u == NumCast::from(20i16)));
assert (20u == NumCast::from(20i32)); fail_unless!((20u == NumCast::from(20i32)));
assert (20u == NumCast::from(20i64)); fail_unless!((20u == NumCast::from(20i64)));
assert (20u == NumCast::from(20f)); fail_unless!((20u == NumCast::from(20f)));
assert (20u == NumCast::from(20f32)); fail_unless!((20u == NumCast::from(20f32)));
assert (20u == NumCast::from(20f64)); fail_unless!((20u == NumCast::from(20f64)));
assert (20u == num::cast(20u)); fail_unless!((20u == num::cast(20u)));
assert (20u == num::cast(20u8)); fail_unless!((20u == num::cast(20u8)));
assert (20u == num::cast(20u16)); fail_unless!((20u == num::cast(20u16)));
assert (20u == num::cast(20u32)); fail_unless!((20u == num::cast(20u32)));
assert (20u == num::cast(20u64)); fail_unless!((20u == num::cast(20u64)));
assert (20u == num::cast(20i)); fail_unless!((20u == num::cast(20i)));
assert (20u == num::cast(20i8)); fail_unless!((20u == num::cast(20i8)));
assert (20u == num::cast(20i16)); fail_unless!((20u == num::cast(20i16)));
assert (20u == num::cast(20i32)); fail_unless!((20u == num::cast(20i32)));
assert (20u == num::cast(20i64)); fail_unless!((20u == num::cast(20i64)));
assert (20u == num::cast(20f)); fail_unless!((20u == num::cast(20f)));
assert (20u == num::cast(20f32)); fail_unless!((20u == num::cast(20f32)));
assert (20u == num::cast(20f64)); fail_unless!((20u == num::cast(20f64)));
} }

View file

@ -437,7 +437,7 @@ fn test_unwrap_ptr() {
let opt = Some(x); let opt = Some(x);
let y = unwrap(opt); let y = unwrap(opt);
let addr_y = ptr::addr_of(&(*y)); let addr_y = ptr::addr_of(&(*y));
assert addr_x == addr_y; fail_unless!(addr_x == addr_y);
} }
#[test] #[test]
@ -447,7 +447,7 @@ fn test_unwrap_str() {
let opt = Some(x); let opt = Some(x);
let y = unwrap(opt); let y = unwrap(opt);
let addr_y = str::as_buf(y, |buf, _len| buf); let addr_y = str::as_buf(y, |buf, _len| buf);
assert addr_x == addr_y; fail_unless!(addr_x == addr_y);
} }
#[test] #[test]
@ -472,7 +472,7 @@ fn test_unwrap_resource() {
let opt = Some(x); let opt = Some(x);
let _y = unwrap(opt); let _y = unwrap(opt);
} }
assert *i == 1; fail_unless!(*i == 1);
} }
#[test] #[test]
@ -483,8 +483,8 @@ fn test_option_dance() {
for x.each |_x| { for x.each |_x| {
y2 = swap_unwrap(&mut y); y2 = swap_unwrap(&mut y);
} }
assert y2 == 5; fail_unless!(y2 == 5);
assert y.is_none(); fail_unless!(y.is_none());
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() { fn test_option_too_much_dance() {
@ -504,15 +504,15 @@ fn test_option_while_some() {
None None
} }
} }
assert i == 11; fail_unless!(i == 11);
} }
#[test] #[test]
fn test_get_or_zero() { fn test_get_or_zero() {
let some_stuff = Some(42); let some_stuff = Some(42);
assert some_stuff.get_or_zero() == 42; fail_unless!(some_stuff.get_or_zero() == 42);
let no_stuff: Option<int> = None; let no_stuff: Option<int> = None;
assert no_stuff.get_or_zero() == 0; fail_unless!(no_stuff.get_or_zero() == 0);
} }
// Local Variables: // Local Variables:

View file

@ -173,7 +173,7 @@ pub fn env() -> ~[(~str,~str)] {
let mut pairs = ~[]; let mut pairs = ~[];
for vec::each(rust_env_pairs()) |p| { for vec::each(rust_env_pairs()) |p| {
let vs = str::splitn_char(*p, '=', 1u); let vs = str::splitn_char(*p, '=', 1u);
assert vec::len(vs) == 2u; fail_unless!(vec::len(vs) == 2u);
pairs.push((copy vs[0], copy vs[1])); pairs.push((copy vs[0], copy vs[1]));
} }
pairs pairs
@ -313,7 +313,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
use libc::funcs::posix01::wait::*; use libc::funcs::posix01::wait::*;
let mut status = 0 as c_int; let mut status = 0 as c_int;
assert (waitpid(pid, &mut status, 0 as c_int) != (-1 as c_int)); fail_unless!((waitpid(pid, &mut status, 0 as c_int) != (-1 as c_int)));
return status; return status;
} }
} }
@ -326,7 +326,7 @@ pub fn pipe() -> Pipe {
unsafe { unsafe {
let mut fds = Pipe {in: 0 as c_int, let mut fds = Pipe {in: 0 as c_int,
out: 0 as c_int }; out: 0 as c_int };
assert (libc::pipe(&mut fds.in) == (0 as c_int)); fail_unless!((libc::pipe(&mut fds.in) == (0 as c_int)));
return Pipe {in: fds.in, out: fds.out}; return Pipe {in: fds.in, out: fds.out};
} }
} }
@ -345,9 +345,9 @@ pub fn pipe() -> Pipe {
out: 0 as c_int }; out: 0 as c_int };
let res = libc::pipe(&mut fds.in, 1024 as c_uint, let res = libc::pipe(&mut fds.in, 1024 as c_uint,
(libc::O_BINARY | libc::O_NOINHERIT) as c_int); (libc::O_BINARY | libc::O_NOINHERIT) as c_int);
assert (res == 0 as c_int); fail_unless!((res == 0 as c_int));
assert (fds.in != -1 as c_int && fds.in != 0 as c_int); fail_unless!((fds.in != -1 as c_int && fds.in != 0 as c_int));
assert (fds.out != -1 as c_int && fds.in != 0 as c_int); fail_unless!((fds.out != -1 as c_int && fds.in != 0 as c_int));
return Pipe {in: fds.in, out: fds.out}; return Pipe {in: fds.in, out: fds.out};
} }
} }
@ -1142,13 +1142,13 @@ mod tests {
#[test] #[test]
pub fn test_args() { pub fn test_args() {
let a = real_args(); let a = real_args();
assert a.len() >= 1; fail_unless!(a.len() >= 1);
} }
fn make_rand_name() -> ~str { fn make_rand_name() -> ~str {
let rng: rand::Rng = rand::Rng(); let rng: rand::Rng = rand::Rng();
let n = ~"TEST" + rng.gen_str(10u); let n = ~"TEST" + rng.gen_str(10u);
assert getenv(n).is_none(); fail_unless!(getenv(n).is_none());
n n
} }
@ -1156,7 +1156,7 @@ mod tests {
fn test_setenv() { fn test_setenv() {
let n = make_rand_name(); let n = make_rand_name();
setenv(n, ~"VALUE"); setenv(n, ~"VALUE");
assert getenv(n) == option::Some(~"VALUE"); fail_unless!(getenv(n) == option::Some(~"VALUE"));
} }
#[test] #[test]
@ -1166,9 +1166,9 @@ mod tests {
let n = make_rand_name(); let n = make_rand_name();
setenv(n, ~"1"); setenv(n, ~"1");
setenv(n, ~"2"); setenv(n, ~"2");
assert getenv(n) == option::Some(~"2"); fail_unless!(getenv(n) == option::Some(~"2"));
setenv(n, ~""); setenv(n, ~"");
assert getenv(n) == option::Some(~""); fail_unless!(getenv(n) == option::Some(~""));
} }
// Windows GetEnvironmentVariable requires some extra work to make sure // Windows GetEnvironmentVariable requires some extra work to make sure
@ -1183,25 +1183,25 @@ mod tests {
let n = make_rand_name(); let n = make_rand_name();
setenv(n, s); setenv(n, s);
log(debug, copy s); log(debug, copy s);
assert getenv(n) == option::Some(s); fail_unless!(getenv(n) == option::Some(s));
} }
#[test] #[test]
fn test_self_exe_path() { fn test_self_exe_path() {
let path = os::self_exe_path(); let path = os::self_exe_path();
assert path.is_some(); fail_unless!(path.is_some());
let path = path.get(); let path = path.get();
log(debug, copy path); log(debug, copy path);
// Hard to test this function // Hard to test this function
assert path.is_absolute; fail_unless!(path.is_absolute);
} }
#[test] #[test]
#[ignore] #[ignore]
fn test_env_getenv() { fn test_env_getenv() {
let e = env(); let e = env();
assert vec::len(e) > 0u; fail_unless!(vec::len(e) > 0u);
for vec::each(e) |p| { for vec::each(e) |p| {
let (n, v) = copy *p; let (n, v) = copy *p;
log(debug, copy n); log(debug, copy n);
@ -1209,7 +1209,7 @@ mod tests {
// MingW seems to set some funky environment variables like // MingW seems to set some funky environment variables like
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned // "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
// from env() but not visible from getenv(). // from env() but not visible from getenv().
assert v2.is_none() || v2 == option::Some(v); fail_unless!(v2.is_none() || v2 == option::Some(v));
} }
} }
@ -1219,15 +1219,15 @@ mod tests {
let mut e = env(); let mut e = env();
setenv(n, ~"VALUE"); setenv(n, ~"VALUE");
assert !vec::contains(e, &(copy n, ~"VALUE")); fail_unless!(!vec::contains(e, &(copy n, ~"VALUE")));
e = env(); e = env();
assert vec::contains(e, &(n, ~"VALUE")); fail_unless!(vec::contains(e, &(n, ~"VALUE")));
} }
#[test] #[test]
fn test() { fn test() {
assert (!Path("test-path").is_absolute); fail_unless!((!Path("test-path").is_absolute));
log(debug, ~"Current working directory: " + getcwd().to_str()); log(debug, ~"Current working directory: " + getcwd().to_str());
@ -1241,10 +1241,10 @@ mod tests {
let oldhome = getenv(~"HOME"); let oldhome = getenv(~"HOME");
setenv(~"HOME", ~"/home/MountainView"); setenv(~"HOME", ~"/home/MountainView");
assert os::homedir() == Some(Path("/home/MountainView")); fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
setenv(~"HOME", ~""); setenv(~"HOME", ~"");
assert os::homedir().is_none(); fail_unless!(os::homedir().is_none());
for oldhome.each |s| { setenv(~"HOME", *s) } for oldhome.each |s| { setenv(~"HOME", *s) }
} }
@ -1259,19 +1259,19 @@ mod tests {
setenv(~"HOME", ~""); setenv(~"HOME", ~"");
setenv(~"USERPROFILE", ~""); setenv(~"USERPROFILE", ~"");
assert os::homedir().is_none(); fail_unless!(os::homedir().is_none());
setenv(~"HOME", ~"/home/MountainView"); setenv(~"HOME", ~"/home/MountainView");
assert os::homedir() == Some(Path("/home/MountainView")); fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
setenv(~"HOME", ~""); setenv(~"HOME", ~"");
setenv(~"USERPROFILE", ~"/home/MountainView"); setenv(~"USERPROFILE", ~"/home/MountainView");
assert os::homedir() == Some(Path("/home/MountainView")); fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
setenv(~"HOME", ~"/home/MountainView"); setenv(~"HOME", ~"/home/MountainView");
setenv(~"USERPROFILE", ~"/home/PaloAlto"); setenv(~"USERPROFILE", ~"/home/PaloAlto");
assert os::homedir() == Some(Path("/home/MountainView")); fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
option::iter(&oldhome, |s| setenv(~"HOME", *s)); option::iter(&oldhome, |s| setenv(~"HOME", *s));
option::iter(&olduserprofile, option::iter(&olduserprofile,
@ -1280,7 +1280,7 @@ mod tests {
#[test] #[test]
fn tmpdir() { fn tmpdir() {
assert !str::is_empty(os::tmpdir().to_str()); fail_unless!(!str::is_empty(os::tmpdir().to_str()));
} }
// Issue #712 // Issue #712
@ -1293,7 +1293,7 @@ mod tests {
fn list_dir() { fn list_dir() {
let dirs = os::list_dir(&Path(".")); let dirs = os::list_dir(&Path("."));
// Just assuming that we've got some contents in the current directory // Just assuming that we've got some contents in the current directory
assert (vec::len(dirs) > 0u); fail_unless!((vec::len(dirs) > 0u));
for vec::each(dirs) |dir| { for vec::each(dirs) |dir| {
log(debug, copy *dir); log(debug, copy *dir);
@ -1302,21 +1302,21 @@ mod tests {
#[test] #[test]
fn path_is_dir() { fn path_is_dir() {
assert (os::path_is_dir(&Path("."))); fail_unless!((os::path_is_dir(&Path("."))));
assert (!os::path_is_dir(&Path("test/stdtest/fs.rs"))); fail_unless!((!os::path_is_dir(&Path("test/stdtest/fs.rs"))));
} }
#[test] #[test]
fn path_exists() { fn path_exists() {
assert (os::path_exists(&Path("."))); fail_unless!((os::path_exists(&Path("."))));
assert (!os::path_exists(&Path("test/nonexistent-bogus-path"))); fail_unless!((!os::path_exists(&Path("test/nonexistent-bogus-path"))));
} }
#[test] #[test]
fn copy_file_does_not_exist() { fn copy_file_does_not_exist() {
assert !os::copy_file(&Path("test/nonexistent-bogus-path"), fail_unless!(!os::copy_file(&Path("test/nonexistent-bogus-path"),
&Path("test/other-bogus-path")); &Path("test/other-bogus-path")));
assert !os::path_exists(&Path("test/other-bogus-path")); fail_unless!(!os::path_exists(&Path("test/other-bogus-path")));
} }
#[test] #[test]
@ -1324,7 +1324,7 @@ mod tests {
unsafe { unsafe {
let tempdir = getcwd(); // would like to use $TMPDIR, let tempdir = getcwd(); // would like to use $TMPDIR,
// doesn't seem to work on Linux // doesn't seem to work on Linux
assert (str::len(tempdir.to_str()) > 0u); fail_unless!((str::len(tempdir.to_str()) > 0u));
let in = tempdir.push("in.txt"); let in = tempdir.push("in.txt");
let out = tempdir.push("out.txt"); let out = tempdir.push("out.txt");
@ -1334,23 +1334,24 @@ mod tests {
libc::fopen(fromp, modebuf) libc::fopen(fromp, modebuf)
} }
}; };
assert (ostream as uint != 0u); fail_unless!((ostream as uint != 0u));
let s = ~"hello"; let s = ~"hello";
let mut buf = str::to_bytes(s) + ~[0 as u8]; let mut buf = str::to_bytes(s) + ~[0 as u8];
do vec::as_mut_buf(buf) |b, _len| { do vec::as_mut_buf(buf) |b, _len| {
assert (libc::fwrite(b as *c_void, 1u as size_t, fail_unless!((libc::fwrite(b as *c_void, 1u as size_t,
(str::len(s) + 1u) as size_t, ostream) (str::len(s) + 1u) as size_t, ostream)
== buf.len() as size_t)}; == buf.len() as size_t))
assert (libc::fclose(ostream) == (0u as c_int)); }
fail_unless!((libc::fclose(ostream) == (0u as c_int)));
let rs = os::copy_file(&in, &out); let rs = os::copy_file(&in, &out);
if (!os::path_exists(&in)) { if (!os::path_exists(&in)) {
fail!(fmt!("%s doesn't exist", in.to_str())); fail!(fmt!("%s doesn't exist", in.to_str()));
} }
assert(rs); fail_unless!((rs));
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]); let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
assert (rslt == 0); fail_unless!((rslt == 0));
assert (remove_file(&in)); fail_unless!((remove_file(&in)));
assert (remove_file(&out)); fail_unless!((remove_file(&out)));
} }
} }
} }

View file

@ -439,7 +439,7 @@ impl GenericPath for PosixPath {
pure fn with_filename(&self, f: &str) -> PosixPath { pure fn with_filename(&self, f: &str) -> PosixPath {
unsafe { unsafe {
assert ! str::any(f, |c| windows::is_sep(c as u8)); fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
self.dir_path().push(f) self.dir_path().push(f)
} }
} }
@ -484,7 +484,7 @@ impl GenericPath for PosixPath {
} }
pure fn push_rel(&self, other: &PosixPath) -> PosixPath { pure fn push_rel(&self, other: &PosixPath) -> PosixPath {
assert !other.is_absolute; fail_unless!(!other.is_absolute);
self.push_many(other.components) self.push_many(other.components)
} }
@ -650,7 +650,7 @@ impl GenericPath for WindowsPath {
} }
pure fn with_filename(&self, f: &str) -> WindowsPath { pure fn with_filename(&self, f: &str) -> WindowsPath {
assert ! str::any(f, |c| windows::is_sep(c as u8)); fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
self.dir_path().push(f) self.dir_path().push(f)
} }
@ -697,7 +697,7 @@ impl GenericPath for WindowsPath {
} }
pure fn push_rel(&self, other: &WindowsPath) -> WindowsPath { pure fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
assert !other.is_absolute; fail_unless!(!other.is_absolute);
self.push_many(other.components) self.push_many(other.components)
} }
@ -880,30 +880,30 @@ mod tests {
let path = PosixPath("tmp/"); let path = PosixPath("tmp/");
let path = path.push("/hmm"); let path = path.push("/hmm");
let path = path.normalize(); let path = path.normalize();
assert ~"tmp/hmm" == path.to_str(); fail_unless!(~"tmp/hmm" == path.to_str());
let path = WindowsPath("tmp/"); let path = WindowsPath("tmp/");
let path = path.push("/hmm"); let path = path.push("/hmm");
let path = path.normalize(); let path = path.normalize();
assert ~"tmp\\hmm" == path.to_str(); fail_unless!(~"tmp\\hmm" == path.to_str());
} }
#[test] #[test]
fn test_filetype_foo_bar() { fn test_filetype_foo_bar() {
let wp = PosixPath("foo.bar"); let wp = PosixPath("foo.bar");
assert wp.filetype() == Some(~".bar"); fail_unless!(wp.filetype() == Some(~".bar"));
let wp = WindowsPath("foo.bar"); let wp = WindowsPath("foo.bar");
assert wp.filetype() == Some(~".bar"); fail_unless!(wp.filetype() == Some(~".bar"));
} }
#[test] #[test]
fn test_filetype_foo() { fn test_filetype_foo() {
let wp = PosixPath("foo"); let wp = PosixPath("foo");
assert wp.filetype() == None; fail_unless!(wp.filetype() == None);
let wp = WindowsPath("foo"); let wp = WindowsPath("foo");
assert wp.filetype() == None; fail_unless!(wp.filetype() == None);
} }
#[test] #[test]
@ -914,7 +914,7 @@ mod tests {
if (ss != sss) { if (ss != sss) {
debug!("got %s", ss); debug!("got %s", ss);
debug!("expected %s", sss); debug!("expected %s", sss);
assert ss == sss; fail_unless!(ss == sss);
} }
} }
@ -972,7 +972,7 @@ mod tests {
if (ss != sss) { if (ss != sss) {
debug!("got %s", ss); debug!("got %s", ss);
debug!("expected %s", sss); debug!("expected %s", sss);
assert ss == sss; fail_unless!(ss == sss);
} }
} }
@ -988,37 +988,43 @@ mod tests {
#[test] #[test]
fn test_extract_unc_prefixes() { fn test_extract_unc_prefixes() {
assert windows::extract_unc_prefix("\\\\").is_none(); fail_unless!(windows::extract_unc_prefix("\\\\").is_none());
assert windows::extract_unc_prefix("//").is_none(); fail_unless!(windows::extract_unc_prefix("//").is_none());
assert windows::extract_unc_prefix("\\\\hi").is_none(); fail_unless!(windows::extract_unc_prefix("\\\\hi").is_none());
assert windows::extract_unc_prefix("//hi").is_none(); fail_unless!(windows::extract_unc_prefix("//hi").is_none());
assert windows::extract_unc_prefix("\\\\hi\\") == fail_unless!(windows::extract_unc_prefix("\\\\hi\\") ==
Some((~"hi", ~"\\")); Some((~"hi", ~"\\")));
assert windows::extract_unc_prefix("//hi\\") == fail_unless!(windows::extract_unc_prefix("//hi\\") ==
Some((~"hi", ~"\\")); Some((~"hi", ~"\\")));
assert windows::extract_unc_prefix("\\\\hi\\there") == fail_unless!(windows::extract_unc_prefix("\\\\hi\\there") ==
Some((~"hi", ~"\\there")); Some((~"hi", ~"\\there")));
assert windows::extract_unc_prefix("//hi/there") == fail_unless!(windows::extract_unc_prefix("//hi/there") ==
Some((~"hi", ~"/there")); Some((~"hi", ~"/there")));
assert windows::extract_unc_prefix("\\\\hi\\there\\friends.txt") == fail_unless!(windows::extract_unc_prefix(
Some((~"hi", ~"\\there\\friends.txt")); "\\\\hi\\there\\friends.txt") ==
assert windows::extract_unc_prefix("//hi\\there\\friends.txt") == Some((~"hi", ~"\\there\\friends.txt")));
Some((~"hi", ~"\\there\\friends.txt")); fail_unless!(windows::extract_unc_prefix(
"//hi\\there\\friends.txt") ==
Some((~"hi", ~"\\there\\friends.txt")));
} }
#[test] #[test]
fn test_extract_drive_prefixes() { fn test_extract_drive_prefixes() {
assert windows::extract_drive_prefix("c").is_none(); fail_unless!(windows::extract_drive_prefix("c").is_none());
assert windows::extract_drive_prefix("c:") == Some((~"c", ~"")); fail_unless!(windows::extract_drive_prefix("c:") ==
assert windows::extract_drive_prefix("d:") == Some((~"d", ~"")); Some((~"c", ~"")));
assert windows::extract_drive_prefix("z:") == Some((~"z", ~"")); fail_unless!(windows::extract_drive_prefix("d:") ==
assert windows::extract_drive_prefix("c:\\hi") == Some((~"d", ~"")));
Some((~"c", ~"\\hi")); fail_unless!(windows::extract_drive_prefix("z:") ==
assert windows::extract_drive_prefix("d:hi") == Some((~"d", ~"hi")); Some((~"z", ~"")));
assert windows::extract_drive_prefix("c:hi\\there.txt") == fail_unless!(windows::extract_drive_prefix("c:\\hi") ==
Some((~"c", ~"hi\\there.txt")); Some((~"c", ~"\\hi")));
assert windows::extract_drive_prefix("c:\\hi\\there.txt") == fail_unless!(windows::extract_drive_prefix("d:hi") ==
Some((~"c", ~"\\hi\\there.txt")); Some((~"d", ~"hi")));
fail_unless!(windows::extract_drive_prefix("c:hi\\there.txt") ==
Some((~"c", ~"hi\\there.txt")));
fail_unless!(windows::extract_drive_prefix("c:\\hi\\there.txt") ==
Some((~"c", ~"\\hi\\there.txt")));
} }
#[test] #[test]
@ -1029,7 +1035,7 @@ mod tests {
if (ss != sss) { if (ss != sss) {
debug!("got %s", ss); debug!("got %s", ss);
debug!("expected %s", sss); debug!("expected %s", sss);
assert ss == sss; fail_unless!(ss == sss);
} }
} }
@ -1114,9 +1120,9 @@ mod tests {
#[test] #[test]
fn test_windows_path_restrictions() { fn test_windows_path_restrictions() {
assert WindowsPath("hi").is_restricted() == false; fail_unless!(WindowsPath("hi").is_restricted() == false);
assert WindowsPath("C:\\NUL").is_restricted() == true; fail_unless!(WindowsPath("C:\\NUL").is_restricted() == true);
assert WindowsPath("C:\\COM1.TXT").is_restricted() == true; fail_unless!(WindowsPath("C:\\COM1.TXT").is_restricted() == true);
assert WindowsPath("c:\\prn.exe").is_restricted() == true; fail_unless!(WindowsPath("c:\\prn.exe").is_restricted() == true);
} }
} }

View file

@ -161,7 +161,7 @@ pub impl PacketHeader {
unsafe fn mark_blocked(&self, this: *rust_task) -> State { unsafe fn mark_blocked(&self, this: *rust_task) -> State {
rustrt::rust_task_ref(this); rustrt::rust_task_ref(this);
let old_task = swap_task(&mut self.blocked_task, this); let old_task = swap_task(&mut self.blocked_task, this);
assert old_task.is_null(); fail_unless!(old_task.is_null());
swap_state_acq(&mut self.state, Blocked) swap_state_acq(&mut self.state, Blocked)
} }
@ -183,7 +183,7 @@ pub impl PacketHeader {
// continuum. It ends making multiple unique pointers to the same // continuum. It ends making multiple unique pointers to the same
// thing. You'll proobably want to forget them when you're done. // thing. You'll proobably want to forget them when you're done.
unsafe fn buf_header(&self) -> ~BufferHeader { unsafe fn buf_header(&self) -> ~BufferHeader {
assert self.buffer.is_not_null(); fail_unless!(self.buffer.is_not_null());
reinterpret_cast(&self.buffer) reinterpret_cast(&self.buffer)
} }
@ -386,8 +386,8 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
let header = p.header(); let header = p.header();
let p_ = p.unwrap(); let p_ = p.unwrap();
let p = unsafe { &*p_ }; let p = unsafe { &*p_ };
assert ptr::addr_of(&(p.header)) == header; fail_unless!(ptr::addr_of(&(p.header)) == header);
assert p.payload.is_none(); fail_unless!(p.payload.is_none());
p.payload = Some(payload); p.payload = Some(payload);
let old_state = swap_state_rel(&mut p.header.state, Full); let old_state = swap_state_rel(&mut p.header.state, Full);
match old_state { match old_state {
@ -488,7 +488,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
debug!("blocked = %x this = %x old_task = %x", debug!("blocked = %x this = %x old_task = %x",
p.header.blocked_task as uint, p.header.blocked_task as uint,
this as uint, old_task as uint); this as uint, old_task as uint);
assert old_task.is_null(); fail_unless!(old_task.is_null());
let mut first = true; let mut first = true;
let mut count = SPIN_COUNT; let mut count = SPIN_COUNT;
loop { loop {
@ -533,7 +533,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
Terminated => { Terminated => {
// This assert detects when we've accidentally unsafely // This assert detects when we've accidentally unsafely
// casted too big of a number to a state. // casted too big of a number to a state.
assert old_state == Terminated; fail_unless!(old_state == Terminated);
let old_task = swap_task(&mut p.header.blocked_task, ptr::null()); let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
if !old_task.is_null() { if !old_task.is_null() {
@ -582,7 +582,7 @@ fn sender_terminate<T:Owned>(p: *Packet<T>) {
fail!(~"you dun goofed") fail!(~"you dun goofed")
} }
Terminated => { Terminated => {
assert p.header.blocked_task.is_null(); fail_unless!(p.header.blocked_task.is_null());
// I have to clean up, use drop_glue // I have to clean up, use drop_glue
} }
} }
@ -593,7 +593,7 @@ fn receiver_terminate<T:Owned>(p: *Packet<T>) {
let p = unsafe { &*p }; let p = unsafe { &*p };
match swap_state_rel(&mut p.header.state, Terminated) { match swap_state_rel(&mut p.header.state, Terminated) {
Empty => { Empty => {
assert p.header.blocked_task.is_null(); fail_unless!(p.header.blocked_task.is_null());
// the sender will clean up // the sender will clean up
} }
Blocked => { Blocked => {
@ -601,12 +601,12 @@ fn receiver_terminate<T:Owned>(p: *Packet<T>) {
if !old_task.is_null() { if !old_task.is_null() {
unsafe { unsafe {
rustrt::rust_task_deref(old_task); rustrt::rust_task_deref(old_task);
assert old_task == rustrt::rust_get_task(); fail_unless!(old_task == rustrt::rust_get_task());
} }
} }
} }
Terminated | Full => { Terminated | Full => {
assert p.header.blocked_task.is_null(); fail_unless!(p.header.blocked_task.is_null());
// I have to clean up, use drop_glue // I have to clean up, use drop_glue
} }
} }
@ -669,8 +669,8 @@ pub fn wait_many<T: Selectable>(pkts: &[T]) -> uint {
debug!("%?, %?", ready_packet, pkts[ready_packet]); debug!("%?, %?", ready_packet, pkts[ready_packet]);
unsafe { unsafe {
assert (*pkts[ready_packet].header()).state == Full fail_unless!((*pkts[ready_packet].header()).state == Full
|| (*pkts[ready_packet].header()).state == Terminated; || (*pkts[ready_packet].header()).state == Terminated);
} }
ready_packet ready_packet
@ -999,6 +999,6 @@ pub mod test {
let _chan = chan; let _chan = chan;
} }
assert !port.peek(); fail_unless!(!port.peek());
} }
} }

View file

@ -310,28 +310,28 @@ pub fn test() {
let mut p = Pair {fst: 10, snd: 20}; let mut p = Pair {fst: 10, snd: 20};
let pptr: *mut Pair = &mut p; let pptr: *mut Pair = &mut p;
let iptr: *mut int = cast::reinterpret_cast(&pptr); let iptr: *mut int = cast::reinterpret_cast(&pptr);
assert (*iptr == 10);; fail_unless!((*iptr == 10));;
*iptr = 30; *iptr = 30;
assert (*iptr == 30); fail_unless!((*iptr == 30));
assert (p.fst == 30);; fail_unless!((p.fst == 30));;
*pptr = Pair {fst: 50, snd: 60}; *pptr = Pair {fst: 50, snd: 60};
assert (*iptr == 50); fail_unless!((*iptr == 50));
assert (p.fst == 50); fail_unless!((p.fst == 50));
assert (p.snd == 60); fail_unless!((p.snd == 60));
let mut v0 = ~[32000u16, 32001u16, 32002u16]; let mut v0 = ~[32000u16, 32001u16, 32002u16];
let mut v1 = ~[0u16, 0u16, 0u16]; let mut v1 = ~[0u16, 0u16, 0u16];
copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u), copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u),
offset(vec::raw::to_ptr(v0), 1u), 1u); offset(vec::raw::to_ptr(v0), 1u), 1u);
assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16); fail_unless!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
copy_memory(vec::raw::to_mut_ptr(v1), copy_memory(vec::raw::to_mut_ptr(v1),
offset(vec::raw::to_ptr(v0), 2u), 1u); offset(vec::raw::to_ptr(v0), 2u), 1u);
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16); fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16));
copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u), copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u),
vec::raw::to_ptr(v0), 1u); vec::raw::to_ptr(v0), 1u);
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16); fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16));
} }
} }
@ -342,9 +342,9 @@ pub fn test_position() {
let s = ~"hello"; let s = ~"hello";
unsafe { unsafe {
assert 2u == as_c_str(s, |p| position(p, |c| *c == 'l' as c_char)); fail_unless!(2u == as_c_str(s, |p| position(p, |c| *c == 'l' as c_char)));
assert 4u == as_c_str(s, |p| position(p, |c| *c == 'o' as c_char)); fail_unless!(4u == as_c_str(s, |p| position(p, |c| *c == 'o' as c_char)));
assert 5u == as_c_str(s, |p| position(p, |c| *c == 0 as c_char)); fail_unless!(5u == as_c_str(s, |p| position(p, |c| *c == 0 as c_char)));
} }
} }
@ -358,8 +358,8 @@ pub fn test_buf_len() {
do str::as_c_str(s2) |p2| { do str::as_c_str(s2) |p2| {
let v = ~[p0, p1, p2, null()]; let v = ~[p0, p1, p2, null()];
do vec::as_imm_buf(v) |vp, len| { do vec::as_imm_buf(v) |vp, len| {
assert unsafe { buf_len(vp) } == 3u; fail_unless!(unsafe { buf_len(vp) } == 3u);
assert len == 4u; fail_unless!(len == 4u);
} }
} }
} }
@ -369,18 +369,18 @@ pub fn test_buf_len() {
#[test] #[test]
pub fn test_is_null() { pub fn test_is_null() {
let p: *int = null(); let p: *int = null();
assert p.is_null(); fail_unless!(p.is_null());
assert !p.is_not_null(); fail_unless!(!p.is_not_null());
let q = offset(p, 1u); let q = offset(p, 1u);
assert !q.is_null(); fail_unless!(!q.is_null());
assert q.is_not_null(); fail_unless!(q.is_not_null());
let mp: *mut int = mut_null(); let mp: *mut int = mut_null();
assert mp.is_null(); fail_unless!(mp.is_null());
assert !mp.is_not_null(); fail_unless!(!mp.is_not_null());
let mq = mp.offset(1u); let mq = mp.offset(1u);
assert !mq.is_null(); fail_unless!(!mq.is_null());
assert mq.is_not_null(); fail_unless!(mq.is_not_null());
} }

View file

@ -162,7 +162,7 @@ pub impl Rng {
* failing if start >= end * failing if start >= end
*/ */
fn gen_int_range(&self, start: int, end: int) -> int { fn gen_int_range(&self, start: int, end: int) -> int {
assert start < end; fail_unless!(start < end);
start + int::abs(self.gen_int() % (end - start)) start + int::abs(self.gen_int() % (end - start))
} }
@ -196,7 +196,7 @@ pub impl Rng {
* failing if start >= end * failing if start >= end
*/ */
fn gen_uint_range(&self, start: uint, end: uint) -> uint { fn gen_uint_range(&self, start: uint, end: uint) -> uint {
assert start < end; fail_unless!(start < end);
start + (self.gen_uint() % (end - start)) start + (self.gen_uint() % (end - start))
} }
@ -248,7 +248,7 @@ pub impl Rng {
* Return a char randomly chosen from chars, failing if chars is empty * Return a char randomly chosen from chars, failing if chars is empty
*/ */
fn gen_char_from(&self, chars: &str) -> char { fn gen_char_from(&self, chars: &str) -> char {
assert !chars.is_empty(); fail_unless!(!chars.is_empty());
self.choose(str::chars(chars)) self.choose(str::chars(chars))
} }
@ -503,7 +503,7 @@ pub mod tests {
let seed = rand::seed(); let seed = rand::seed();
let ra = rand::seeded_rng(seed); let ra = rand::seeded_rng(seed);
let rb = rand::seeded_rng(seed); let rb = rand::seeded_rng(seed);
assert ra.gen_str(100u) == rb.gen_str(100u); fail_unless!(ra.gen_str(100u) == rb.gen_str(100u));
} }
#[test] #[test]
@ -512,7 +512,7 @@ pub mod tests {
let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
let ra = rand::seeded_rng(seed); let ra = rand::seeded_rng(seed);
let rb = rand::seeded_rng(seed); let rb = rand::seeded_rng(seed);
assert ra.gen_str(100u) == rb.gen_str(100u); fail_unless!(ra.gen_str(100u) == rb.gen_str(100u));
} }
#[test] #[test]
@ -522,17 +522,17 @@ pub mod tests {
// Regression test that isaac is actually using the above vector // Regression test that isaac is actually using the above vector
let r = ra.next(); let r = ra.next();
error!("%?", r); error!("%?", r);
assert r == 890007737u32 // on x86_64 fail_unless!(r == 890007737u32 // on x86_64
|| r == 2935188040u32; // on x86 || r == 2935188040u32); // on x86
} }
#[test] #[test]
pub fn gen_int_range() { pub fn gen_int_range() {
let r = rand::Rng(); let r = rand::Rng();
let a = r.gen_int_range(-3, 42); let a = r.gen_int_range(-3, 42);
assert a >= -3 && a < 42; fail_unless!(a >= -3 && a < 42);
assert r.gen_int_range(0, 1) == 0; fail_unless!(r.gen_int_range(0, 1) == 0);
assert r.gen_int_range(-12, -11) == -12; fail_unless!(r.gen_int_range(-12, -11) == -12);
} }
#[test] #[test]
@ -546,9 +546,9 @@ pub mod tests {
pub fn gen_uint_range() { pub fn gen_uint_range() {
let r = rand::Rng(); let r = rand::Rng();
let a = r.gen_uint_range(3u, 42u); let a = r.gen_uint_range(3u, 42u);
assert a >= 3u && a < 42u; fail_unless!(a >= 3u && a < 42u);
assert r.gen_uint_range(0u, 1u) == 0u; fail_unless!(r.gen_uint_range(0u, 1u) == 0u);
assert r.gen_uint_range(12u, 13u) == 12u; fail_unless!(r.gen_uint_range(12u, 13u) == 12u);
} }
#[test] #[test]
@ -569,8 +569,8 @@ pub mod tests {
#[test] #[test]
pub fn gen_weighted_bool() { pub fn gen_weighted_bool() {
let r = rand::Rng(); let r = rand::Rng();
assert r.gen_weighted_bool(0u) == true; fail_unless!(r.gen_weighted_bool(0u) == true);
assert r.gen_weighted_bool(1u) == true; fail_unless!(r.gen_weighted_bool(1u) == true);
} }
#[test] #[test]
@ -579,85 +579,85 @@ pub mod tests {
log(debug, r.gen_str(10u)); log(debug, r.gen_str(10u));
log(debug, r.gen_str(10u)); log(debug, r.gen_str(10u));
log(debug, r.gen_str(10u)); log(debug, r.gen_str(10u));
assert r.gen_str(0u).len() == 0u; fail_unless!(r.gen_str(0u).len() == 0u);
assert r.gen_str(10u).len() == 10u; fail_unless!(r.gen_str(10u).len() == 10u);
assert r.gen_str(16u).len() == 16u; fail_unless!(r.gen_str(16u).len() == 16u);
} }
#[test] #[test]
pub fn gen_bytes() { pub fn gen_bytes() {
let r = rand::Rng(); let r = rand::Rng();
assert r.gen_bytes(0u).len() == 0u; fail_unless!(r.gen_bytes(0u).len() == 0u);
assert r.gen_bytes(10u).len() == 10u; fail_unless!(r.gen_bytes(10u).len() == 10u);
assert r.gen_bytes(16u).len() == 16u; fail_unless!(r.gen_bytes(16u).len() == 16u);
} }
#[test] #[test]
pub fn choose() { pub fn choose() {
let r = rand::Rng(); let r = rand::Rng();
assert r.choose([1, 1, 1]) == 1; fail_unless!(r.choose([1, 1, 1]) == 1);
} }
#[test] #[test]
pub fn choose_option() { pub fn choose_option() {
let r = rand::Rng(); let r = rand::Rng();
let x: Option<int> = r.choose_option([]); let x: Option<int> = r.choose_option([]);
assert x.is_none(); fail_unless!(x.is_none());
assert r.choose_option([1, 1, 1]) == Some(1); fail_unless!(r.choose_option([1, 1, 1]) == Some(1));
} }
#[test] #[test]
pub fn choose_weighted() { pub fn choose_weighted() {
let r = rand::Rng(); let r = rand::Rng();
assert r.choose_weighted(~[ fail_unless!(r.choose_weighted(~[
rand::Weighted { weight: 1u, item: 42 }, rand::Weighted { weight: 1u, item: 42 },
]) == 42; ]) == 42);
assert r.choose_weighted(~[ fail_unless!(r.choose_weighted(~[
rand::Weighted { weight: 0u, item: 42 }, rand::Weighted { weight: 0u, item: 42 },
rand::Weighted { weight: 1u, item: 43 }, rand::Weighted { weight: 1u, item: 43 },
]) == 43; ]) == 43);
} }
#[test] #[test]
pub fn choose_weighted_option() { pub fn choose_weighted_option() {
let r = rand::Rng(); let r = rand::Rng();
assert r.choose_weighted_option(~[ fail_unless!(r.choose_weighted_option(~[
rand::Weighted { weight: 1u, item: 42 }, rand::Weighted { weight: 1u, item: 42 },
]) == Some(42); ]) == Some(42));
assert r.choose_weighted_option(~[ fail_unless!(r.choose_weighted_option(~[
rand::Weighted { weight: 0u, item: 42 }, rand::Weighted { weight: 0u, item: 42 },
rand::Weighted { weight: 1u, item: 43 }, rand::Weighted { weight: 1u, item: 43 },
]) == Some(43); ]) == Some(43));
let v: Option<int> = r.choose_weighted_option([]); let v: Option<int> = r.choose_weighted_option([]);
assert v.is_none(); fail_unless!(v.is_none());
} }
#[test] #[test]
pub fn weighted_vec() { pub fn weighted_vec() {
let r = rand::Rng(); let r = rand::Rng();
let empty: ~[int] = ~[]; let empty: ~[int] = ~[];
assert r.weighted_vec(~[]) == empty; fail_unless!(r.weighted_vec(~[]) == empty);
assert r.weighted_vec(~[ fail_unless!(r.weighted_vec(~[
rand::Weighted { weight: 0u, item: 3u }, rand::Weighted { weight: 0u, item: 3u },
rand::Weighted { weight: 1u, item: 2u }, rand::Weighted { weight: 1u, item: 2u },
rand::Weighted { weight: 2u, item: 1u }, rand::Weighted { weight: 2u, item: 1u },
]) == ~[2u, 1u, 1u]; ]) == ~[2u, 1u, 1u]);
} }
#[test] #[test]
pub fn shuffle() { pub fn shuffle() {
let r = rand::Rng(); let r = rand::Rng();
let empty: ~[int] = ~[]; let empty: ~[int] = ~[];
assert r.shuffle(~[]) == empty; fail_unless!(r.shuffle(~[]) == empty);
assert r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]; fail_unless!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
} }
#[test] #[test]
pub fn task_rng() { pub fn task_rng() {
let r = rand::task_rng(); let r = rand::task_rng();
r.gen_int(); r.gen_int();
assert r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]; fail_unless!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
assert r.gen_uint_range(0u, 1u) == 0u; fail_unless!(r.gen_uint_range(0u, 1u) == 0u);
} }
#[test] #[test]

View file

@ -231,7 +231,7 @@ pub impl ReprVisitor {
} else if mtbl == 1 { } else if mtbl == 1 {
// skip, this is ast::m_imm // skip, this is ast::m_imm
} else { } else {
assert mtbl == 2; fail_unless!(mtbl == 2);
self.writer.write_str("const "); self.writer.write_str("const ");
} }
} }
@ -590,7 +590,7 @@ fn test_repr() {
error!("expected '%s', got '%s'", error!("expected '%s', got '%s'",
e, s); e, s);
} }
assert s == e; fail_unless!(s == e);
} }

View file

@ -294,7 +294,7 @@ pub impl<T, E: Copy> Result<T, E> {
* else { return ok(x+1u); } * else { return ok(x+1u); }
* } * }
* map(~[1u, 2u, 3u], inc_conditionally).chain {|incd| * map(~[1u, 2u, 3u], inc_conditionally).chain {|incd|
* assert incd == ~[2u, 3u, 4u]; * fail_unless!(incd == ~[2u, 3u, 4u]);
* } * }
*/ */
#[inline(always)] #[inline(always)]
@ -337,7 +337,7 @@ pub fn map_opt<T,U:Copy,V:Copy>(
pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T], pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
op: fn(&S,&T) -> Result<V,U>) -> Result<~[V],U> { op: fn(&S,&T) -> Result<V,U>) -> Result<~[V],U> {
assert vec::same_length(ss, ts); fail_unless!(vec::same_length(ss, ts));
let n = vec::len(ts); let n = vec::len(ts);
let mut vs = vec::with_capacity(n); let mut vs = vec::with_capacity(n);
let mut i = 0u; let mut i = 0u;
@ -360,7 +360,7 @@ pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T], pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
op: fn(&S,&T) -> Result<(),U>) -> Result<(),U> { op: fn(&S,&T) -> Result<(),U>) -> Result<(),U> {
assert vec::same_length(ss, ts); fail_unless!(vec::same_length(ss, ts));
let n = vec::len(ts); let n = vec::len(ts);
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
@ -407,50 +407,50 @@ mod tests {
#[test] #[test]
pub fn chain_success() { pub fn chain_success() {
assert get(&chain(op1(), op2)) == 667u; fail_unless!(get(&chain(op1(), op2)) == 667u);
} }
#[test] #[test]
pub fn chain_failure() { pub fn chain_failure() {
assert get_err(&chain(op3(), op2)) == ~"sadface"; fail_unless!(get_err(&chain(op3(), op2)) == ~"sadface");
} }
#[test] #[test]
pub fn test_impl_iter() { pub fn test_impl_iter() {
let mut valid = false; let mut valid = false;
Ok::<~str, ~str>(~"a").iter(|_x| valid = true); Ok::<~str, ~str>(~"a").iter(|_x| valid = true);
assert valid; fail_unless!(valid);
Err::<~str, ~str>(~"b").iter(|_x| valid = false); Err::<~str, ~str>(~"b").iter(|_x| valid = false);
assert valid; fail_unless!(valid);
} }
#[test] #[test]
pub fn test_impl_iter_err() { pub fn test_impl_iter_err() {
let mut valid = true; let mut valid = true;
Ok::<~str, ~str>(~"a").iter_err(|_x| valid = false); Ok::<~str, ~str>(~"a").iter_err(|_x| valid = false);
assert valid; fail_unless!(valid);
valid = false; valid = false;
Err::<~str, ~str>(~"b").iter_err(|_x| valid = true); Err::<~str, ~str>(~"b").iter_err(|_x| valid = true);
assert valid; fail_unless!(valid);
} }
#[test] #[test]
pub fn test_impl_map() { pub fn test_impl_map() {
assert Ok::<~str, ~str>(~"a").map(|_x| ~"b") == Ok(~"b"); fail_unless!(Ok::<~str, ~str>(~"a").map(|_x| ~"b") == Ok(~"b"));
assert Err::<~str, ~str>(~"a").map(|_x| ~"b") == Err(~"a"); fail_unless!(Err::<~str, ~str>(~"a").map(|_x| ~"b") == Err(~"a"));
} }
#[test] #[test]
pub fn test_impl_map_err() { pub fn test_impl_map_err() {
assert Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a"); fail_unless!(Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a"));
assert Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b"); fail_unless!(Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b"));
} }
#[test] #[test]
pub fn test_get_ref_method() { pub fn test_get_ref_method() {
let foo: Result<int, ()> = Ok(100); let foo: Result<int, ()> = Ok(100);
assert *foo.get_ref() == 100; fail_unless!(*foo.get_ref() == 100);
} }
} }

View file

@ -496,7 +496,7 @@ mod tests {
log(debug, copy expected); log(debug, copy expected);
log(debug, copy actual); log(debug, copy actual);
assert (expected == actual); fail_unless!((expected == actual));
} }
#[test] #[test]
@ -505,7 +505,7 @@ mod tests {
&None, &None, &None, &None,
0i32, 0i32, 0i32); 0i32, 0i32, 0i32);
let status = run::waitpid(pid); let status = run::waitpid(pid);
assert status == 1; fail_unless!(status == 1);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -156,6 +156,13 @@ pub pure fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
} }
} }
pub pure fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
unsafe {
let (msg, file) = (msg.to_owned(), file.to_owned());
begin_unwind(~"assertion failed: " + msg, file, line)
}
}
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use cast; use cast;
@ -163,10 +170,10 @@ pub mod tests {
#[test] #[test]
pub fn size_of_basic() { pub fn size_of_basic() {
assert size_of::<u8>() == 1u; fail_unless!(size_of::<u8>() == 1u);
assert size_of::<u16>() == 2u; fail_unless!(size_of::<u16>() == 2u);
assert size_of::<u32>() == 4u; fail_unless!(size_of::<u32>() == 4u);
assert size_of::<u64>() == 8u; fail_unless!(size_of::<u64>() == 8u);
} }
#[test] #[test]
@ -174,30 +181,30 @@ pub mod tests {
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")] #[cfg(target_arch = "mips")]
pub fn size_of_32() { pub fn size_of_32() {
assert size_of::<uint>() == 4u; fail_unless!(size_of::<uint>() == 4u);
assert size_of::<*uint>() == 4u; fail_unless!(size_of::<*uint>() == 4u);
} }
#[test] #[test]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub fn size_of_64() { pub fn size_of_64() {
assert size_of::<uint>() == 8u; fail_unless!(size_of::<uint>() == 8u);
assert size_of::<*uint>() == 8u; fail_unless!(size_of::<*uint>() == 8u);
} }
#[test] #[test]
pub fn nonzero_size_of_basic() { pub fn nonzero_size_of_basic() {
type Z = [i8 * 0]; type Z = [i8 * 0];
assert size_of::<Z>() == 0u; fail_unless!(size_of::<Z>() == 0u);
assert nonzero_size_of::<Z>() == 1u; fail_unless!(nonzero_size_of::<Z>() == 1u);
assert nonzero_size_of::<uint>() == size_of::<uint>(); fail_unless!(nonzero_size_of::<uint>() == size_of::<uint>());
} }
#[test] #[test]
pub fn align_of_basic() { pub fn align_of_basic() {
assert pref_align_of::<u8>() == 1u; fail_unless!(pref_align_of::<u8>() == 1u);
assert pref_align_of::<u16>() == 2u; fail_unless!(pref_align_of::<u16>() == 2u);
assert pref_align_of::<u32>() == 4u; fail_unless!(pref_align_of::<u32>() == 4u);
} }
#[test] #[test]
@ -205,15 +212,15 @@ pub mod tests {
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")] #[cfg(target_arch = "mips")]
pub fn align_of_32() { pub fn align_of_32() {
assert pref_align_of::<uint>() == 4u; fail_unless!(pref_align_of::<uint>() == 4u);
assert pref_align_of::<*uint>() == 4u; fail_unless!(pref_align_of::<*uint>() == 4u);
} }
#[test] #[test]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub fn align_of_64() { pub fn align_of_64() {
assert pref_align_of::<uint>() == 8u; fail_unless!(pref_align_of::<uint>() == 8u);
assert pref_align_of::<*uint>() == 8u; fail_unless!(pref_align_of::<*uint>() == 8u);
} }
#[test] #[test]
@ -222,7 +229,7 @@ pub mod tests {
let x = 10; let x = 10;
let f: fn(int) -> int = |y| x + y; let f: fn(int) -> int = |y| x + y;
assert f(20) == 30; fail_unless!(f(20) == 30);
let original_closure: Closure = cast::transmute(f); let original_closure: Closure = cast::transmute(f);
@ -235,7 +242,7 @@ pub mod tests {
}; };
let new_f: fn(int) -> int = cast::transmute(new_closure); let new_f: fn(int) -> int = cast::transmute(new_closure);
assert new_f(20) == 30; fail_unless!(new_f(20) == 30);
} }
} }
} }

View file

@ -92,16 +92,16 @@ fn test_tls_multitask() {
do task::spawn { do task::spawn {
unsafe { unsafe {
// TLS shouldn't carry over. // TLS shouldn't carry over.
assert local_data_get(my_key).is_none(); fail_unless!(local_data_get(my_key).is_none());
local_data_set(my_key, @~"child data"); local_data_set(my_key, @~"child data");
assert *(local_data_get(my_key).get()) == ~"child data"; fail_unless!(*(local_data_get(my_key).get()) == ~"child data");
// should be cleaned up for us // should be cleaned up for us
} }
} }
// Must work multiple times // Must work multiple times
assert *(local_data_get(my_key).get()) == ~"parent data"; fail_unless!(*(local_data_get(my_key).get()) == ~"parent data");
assert *(local_data_get(my_key).get()) == ~"parent data"; fail_unless!(*(local_data_get(my_key).get()) == ~"parent data");
assert *(local_data_get(my_key).get()) == ~"parent data"; fail_unless!(*(local_data_get(my_key).get()) == ~"parent data");
} }
} }
@ -111,7 +111,7 @@ fn test_tls_overwrite() {
fn my_key(_x: @~str) { } fn my_key(_x: @~str) { }
local_data_set(my_key, @~"first data"); local_data_set(my_key, @~"first data");
local_data_set(my_key, @~"next data"); // Shouldn't leak. local_data_set(my_key, @~"next data"); // Shouldn't leak.
assert *(local_data_get(my_key).get()) == ~"next data"; fail_unless!(*(local_data_get(my_key).get()) == ~"next data");
} }
} }
@ -120,9 +120,9 @@ fn test_tls_pop() {
unsafe { unsafe {
fn my_key(_x: @~str) { } fn my_key(_x: @~str) { }
local_data_set(my_key, @~"weasel"); local_data_set(my_key, @~"weasel");
assert *(local_data_pop(my_key).get()) == ~"weasel"; fail_unless!(*(local_data_pop(my_key).get()) == ~"weasel");
// Pop must remove the data from the map. // Pop must remove the data from the map.
assert local_data_pop(my_key).is_none(); fail_unless!(local_data_pop(my_key).is_none());
} }
} }
@ -143,7 +143,7 @@ fn test_tls_modify() {
None => fail!(~"missing value") None => fail!(~"missing value")
} }
}); });
assert *(local_data_pop(my_key).get()) == ~"next data"; fail_unless!(*(local_data_pop(my_key).get()) == ~"next data");
} }
} }

View file

@ -43,7 +43,7 @@ type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) { extern fn cleanup_task_local_map(map_ptr: *libc::c_void) {
unsafe { unsafe {
assert !map_ptr.is_null(); fail_unless!(!map_ptr.is_null());
// Get and keep the single reference that was created at the // Get and keep the single reference that was created at the
// beginning. // beginning.
let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr); let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr);

View file

@ -848,14 +848,14 @@ fn test_add_wrapper() {
fn test_future_result() { fn test_future_result() {
let mut result = None; let mut result = None;
do task().future_result(|+r| { result = Some(r); }).spawn { } do task().future_result(|+r| { result = Some(r); }).spawn { }
assert option::unwrap(result).recv() == Success; fail_unless!(option::unwrap(result).recv() == Success);
result = None; result = None;
do task().future_result(|+r| do task().future_result(|+r|
{ result = Some(r); }).unlinked().spawn { { result = Some(r); }).unlinked().spawn {
fail!(); fail!();
} }
assert option::unwrap(result).recv() == Failure; fail_unless!(option::unwrap(result).recv() == Failure);
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
@ -901,7 +901,7 @@ fn test_spawn_sched() {
do spawn_sched(SingleThreaded) { do spawn_sched(SingleThreaded) {
let child_sched_id = unsafe { rt::rust_get_sched_id() }; let child_sched_id = unsafe { rt::rust_get_sched_id() };
assert parent_sched_id != child_sched_id; fail_unless!(parent_sched_id != child_sched_id);
if (i == 0) { if (i == 0) {
ch.send(()); ch.send(());
@ -929,8 +929,8 @@ fn test_spawn_sched_childs_on_default_sched() {
do spawn { do spawn {
let ch = ch.f.swap_unwrap(); let ch = ch.f.swap_unwrap();
let child_sched_id = unsafe { rt::rust_get_sched_id() }; let child_sched_id = unsafe { rt::rust_get_sched_id() };
assert parent_sched_id != child_sched_id; fail_unless!(parent_sched_id != child_sched_id);
assert child_sched_id == default_id; fail_unless!(child_sched_id == default_id);
ch.send(()); ch.send(());
}; };
}; };
@ -1022,7 +1022,7 @@ fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) {
} }
let x_in_child = p.recv(); let x_in_child = p.recv();
assert x_in_parent == x_in_child; fail_unless!(x_in_parent == x_in_child);
} }
#[test] #[test]
@ -1177,7 +1177,7 @@ fn test_sched_thread_per_core() {
unsafe { unsafe {
let cores = rt::rust_num_threads(); let cores = rt::rust_num_threads();
let reported_threads = rt::rust_sched_threads(); let reported_threads = rt::rust_sched_threads();
assert(cores as uint == reported_threads as uint); fail_unless!((cores as uint == reported_threads as uint));
chan.send(()); chan.send(());
} }
} }
@ -1192,9 +1192,9 @@ fn test_spawn_thread_on_demand() {
do spawn_sched(ManualThreads(2)) || { do spawn_sched(ManualThreads(2)) || {
unsafe { unsafe {
let max_threads = rt::rust_sched_threads(); let max_threads = rt::rust_sched_threads();
assert(max_threads as int == 2); fail_unless!((max_threads as int == 2));
let running_threads = rt::rust_sched_current_nonlazy_threads(); let running_threads = rt::rust_sched_current_nonlazy_threads();
assert(running_threads as int == 1); fail_unless!((running_threads as int == 1));
let (port2, chan2) = comm::stream(); let (port2, chan2) = comm::stream();
@ -1203,7 +1203,7 @@ fn test_spawn_thread_on_demand() {
} }
let running_threads2 = rt::rust_sched_current_nonlazy_threads(); let running_threads2 = rt::rust_sched_current_nonlazy_threads();
assert(running_threads2 as int == 2); fail_unless!((running_threads2 as int == 2));
port2.recv(); port2.recv();
chan.send(()); chan.send(());

View file

@ -102,11 +102,11 @@ fn new_taskset() -> TaskSet {
} }
fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
let didnt_overwrite = tasks.insert(task); let didnt_overwrite = tasks.insert(task);
assert didnt_overwrite; fail_unless!(didnt_overwrite);
} }
fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
let was_present = tasks.remove(&task); let was_present = tasks.remove(&task);
assert was_present; fail_unless!(was_present);
} }
pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) {
tasks.each(|k| blk(*k)) tasks.each(|k| blk(*k))
@ -230,7 +230,7 @@ fn each_ancestor(list: &mut AncestorList,
// NB: Takes a lock! (this ancestor node) // NB: Takes a lock! (this ancestor node)
do access_ancestors(ancestor_arc) |nobe| { do access_ancestors(ancestor_arc) |nobe| {
// Check monotonicity // Check monotonicity
assert last_generation > nobe.generation; fail_unless!(last_generation > nobe.generation);
/*##########################################################* /*##########################################################*
* Step 1: Look at this ancestor group (call iterator block). * Step 1: Look at this ancestor group (call iterator block).
*##########################################################*/ *##########################################################*/
@ -422,7 +422,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
} }
} }
for taskset_each(&group.descendants) |child| { for taskset_each(&group.descendants) |child| {
assert child != me; fail_unless!(child != me);
rt::rust_task_kill_other(child); rt::rust_task_kill_other(child);
} }
// Only one task should ever do this. // Only one task should ever do this.
@ -497,7 +497,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
} }
None => 0 // the actual value doesn't really matter. None => 0 // the actual value doesn't really matter.
}; };
assert new_generation < uint::max_value; fail_unless!(new_generation < uint::max_value);
// Build a new node in the ancestor list. // Build a new node in the ancestor list.
AncestorList(Some(unstable::exclusive(AncestorNode { AncestorList(Some(unstable::exclusive(AncestorNode {
generation: new_generation, generation: new_generation,
@ -544,7 +544,7 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
DefaultScheduler => rt::new_task(), DefaultScheduler => rt::new_task(),
_ => new_task_in_sched(opts.sched) _ => new_task_in_sched(opts.sched)
}; };
assert !new_task.is_null(); fail_unless!(!new_task.is_null());
// Getting killed after here would leak the task. // Getting killed after here would leak the task.
let mut notify_chan = if opts.notify_chan.is_none() { let mut notify_chan = if opts.notify_chan.is_none() {
None None
@ -716,7 +716,7 @@ fn test_spawn_raw_notify_success() {
}; };
do spawn_raw(opts) { do spawn_raw(opts) {
} }
assert notify_po.recv() == Success; fail_unless!(notify_po.recv() == Success);
} }
#[test] #[test]
@ -733,5 +733,5 @@ fn test_spawn_raw_notify_failure() {
do spawn_raw(opts) { do spawn_raw(opts) {
fail!(); fail!();
} }
assert notify_po.recv() == Failure; fail_unless!(notify_po.recv() == Failure);
} }

View file

@ -140,31 +140,31 @@ impl<A:ToStr> ToStr for @[A] {
mod tests { mod tests {
#[test] #[test]
fn test_simple_types() { fn test_simple_types() {
assert 1i.to_str() == ~"1"; fail_unless!(1i.to_str() == ~"1");
assert (-1i).to_str() == ~"-1"; fail_unless!((-1i).to_str() == ~"-1");
assert 200u.to_str() == ~"200"; fail_unless!(200u.to_str() == ~"200");
assert 2u8.to_str() == ~"2"; fail_unless!(2u8.to_str() == ~"2");
assert true.to_str() == ~"true"; fail_unless!(true.to_str() == ~"true");
assert false.to_str() == ~"false"; fail_unless!(false.to_str() == ~"false");
assert ().to_str() == ~"()"; fail_unless!(().to_str() == ~"()");
assert (~"hi").to_str() == ~"hi"; fail_unless!((~"hi").to_str() == ~"hi");
assert (@"hi").to_str() == ~"hi"; fail_unless!((@"hi").to_str() == ~"hi");
} }
#[test] #[test]
fn test_tuple_types() { fn test_tuple_types() {
assert (1, 2).to_str() == ~"(1, 2)"; fail_unless!((1, 2).to_str() == ~"(1, 2)");
assert (~"a", ~"b", false).to_str() == ~"(a, b, false)"; fail_unless!((~"a", ~"b", false).to_str() == ~"(a, b, false)");
assert ((), ((), 100)).to_str() == ~"((), ((), 100))"; fail_unless!(((), ((), 100)).to_str() == ~"((), ((), 100))");
} }
#[test] #[test]
fn test_vectors() { fn test_vectors() {
let x: ~[int] = ~[]; let x: ~[int] = ~[];
assert x.to_str() == ~"[]"; fail_unless!(x.to_str() == ~"[]");
assert (~[1]).to_str() == ~"[1]"; fail_unless!((~[1]).to_str() == ~"[1]");
assert (~[1, 2, 3]).to_str() == ~"[1, 2, 3]"; fail_unless!((~[1, 2, 3]).to_str() == ~"[1, 2, 3]");
assert (~[~[], ~[1], ~[1, 1]]).to_str() == fail_unless!((~[~[], ~[1], ~[1, 1]]).to_str() ==
~"[[], [1], [1, 1]]"; ~"[[], [1], [1, 1]]");
} }
} }

View file

@ -327,7 +327,7 @@ fn remove<T>(count: &mut uint, child: &mut Child<T>, key: uint,
#[cfg(test)] #[cfg(test)]
pub fn check_integrity<T>(trie: &TrieNode<T>) { pub fn check_integrity<T>(trie: &TrieNode<T>) {
assert trie.count != 0; fail_unless!(trie.count != 0);
let mut sum = 0; let mut sum = 0;
@ -342,7 +342,7 @@ pub fn check_integrity<T>(trie: &TrieNode<T>) {
} }
} }
assert sum == trie.count; fail_unless!(sum == trie.count);
} }
#[cfg(test)] #[cfg(test)]
@ -356,32 +356,32 @@ mod tests {
let n = 300; let n = 300;
for uint::range_step(1, n, 2) |x| { for uint::range_step(1, n, 2) |x| {
assert trie.insert(x, x + 1); fail_unless!(trie.insert(x, x + 1));
assert trie.contains_key(&x); fail_unless!(trie.contains_key(&x));
check_integrity(&trie.root); check_integrity(&trie.root);
} }
for uint::range_step(0, n, 2) |x| { for uint::range_step(0, n, 2) |x| {
assert !trie.contains_key(&x); fail_unless!(!trie.contains_key(&x));
assert trie.insert(x, x + 1); fail_unless!(trie.insert(x, x + 1));
check_integrity(&trie.root); check_integrity(&trie.root);
} }
for uint::range(0, n) |x| { for uint::range(0, n) |x| {
assert trie.contains_key(&x); fail_unless!(trie.contains_key(&x));
assert !trie.insert(x, x + 1); fail_unless!(!trie.insert(x, x + 1));
check_integrity(&trie.root); check_integrity(&trie.root);
} }
for uint::range_step(1, n, 2) |x| { for uint::range_step(1, n, 2) |x| {
assert trie.remove(&x); fail_unless!(trie.remove(&x));
assert !trie.contains_key(&x); fail_unless!(!trie.contains_key(&x));
check_integrity(&trie.root); check_integrity(&trie.root);
} }
for uint::range_step(0, n, 2) |x| { for uint::range_step(0, n, 2) |x| {
assert trie.contains_key(&x); fail_unless!(trie.contains_key(&x));
assert !trie.insert(x, x + 1); fail_unless!(!trie.insert(x, x + 1));
check_integrity(&trie.root); check_integrity(&trie.root);
} }
} }
@ -390,16 +390,16 @@ mod tests {
fn test_each() { fn test_each() {
let mut m = TrieMap::new(); let mut m = TrieMap::new();
assert m.insert(3, 6); fail_unless!(m.insert(3, 6));
assert m.insert(0, 0); fail_unless!(m.insert(0, 0));
assert m.insert(4, 8); fail_unless!(m.insert(4, 8));
assert m.insert(2, 4); fail_unless!(m.insert(2, 4));
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
let mut n = 0; let mut n = 0;
for m.each |&(k, v)| { for m.each |&(k, v)| {
assert k == n; fail_unless!(k == n);
assert *v == n * 2; fail_unless!(*v == n * 2);
n += 1; n += 1;
} }
} }
@ -415,10 +415,10 @@ mod tests {
let mut n = uint::max_value - 9999; let mut n = uint::max_value - 9999;
for m.each |&(k, v)| { for m.each |&(k, v)| {
if n == uint::max_value - 5000 { break } if n == uint::max_value - 5000 { break }
assert n < uint::max_value - 5000; fail_unless!(n < uint::max_value - 5000);
assert k == n; fail_unless!(k == n);
assert *v == n / 2; fail_unless!(*v == n / 2);
n += 1; n += 1;
} }
} }
@ -427,16 +427,16 @@ mod tests {
fn test_each_reverse() { fn test_each_reverse() {
let mut m = TrieMap::new(); let mut m = TrieMap::new();
assert m.insert(3, 6); fail_unless!(m.insert(3, 6));
assert m.insert(0, 0); fail_unless!(m.insert(0, 0));
assert m.insert(4, 8); fail_unless!(m.insert(4, 8));
assert m.insert(2, 4); fail_unless!(m.insert(2, 4));
assert m.insert(1, 2); fail_unless!(m.insert(1, 2));
let mut n = 4; let mut n = 4;
for m.each_reverse |&(k, v)| { for m.each_reverse |&(k, v)| {
assert k == n; fail_unless!(k == n);
assert *v == n * 2; fail_unless!(*v == n * 2);
n -= 1; n -= 1;
} }
} }
@ -452,10 +452,10 @@ mod tests {
let mut n = uint::max_value; let mut n = uint::max_value;
for m.each_reverse |&(k, v)| { for m.each_reverse |&(k, v)| {
if n == uint::max_value - 5000 { break } if n == uint::max_value - 5000 { break }
assert n > uint::max_value - 5000; fail_unless!(n > uint::max_value - 5000);
assert k == n; fail_unless!(k == n);
assert *v == n / 2; fail_unless!(*v == n / 2);
n -= 1; n -= 1;
} }
} }

View file

@ -202,15 +202,15 @@ impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
#[test] #[test]
fn test_tuple_ref() { fn test_tuple_ref() {
let x = (~"foo", ~"bar"); let x = (~"foo", ~"bar");
assert x.first_ref() == &~"foo"; fail_unless!(x.first_ref() == &~"foo");
assert x.second_ref() == &~"bar"; fail_unless!(x.second_ref() == &~"bar");
} }
#[test] #[test]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
fn test_tuple() { fn test_tuple() {
assert (948, 4039.48).first() == 948; fail_unless!((948, 4039.48).first() == 948);
assert (34.5, ~"foo").second() == ~"foo"; fail_unless!((34.5, ~"foo").second() == ~"foo");
assert ('a', 2).swap() == (2, 'a'); fail_unless!(('a', 2).swap() == (2, 'a'));
} }

View file

@ -83,7 +83,7 @@ fn test_run_in_bare_thread() {
unsafe { unsafe {
let i = 100; let i = 100;
do run_in_bare_thread { do run_in_bare_thread {
assert i == 100; fail_unless!(i == 100);
} }
} }
} }
@ -94,7 +94,7 @@ fn test_run_in_bare_thread_exchange() {
// Does the exchange heap work without the runtime? // Does the exchange heap work without the runtime?
let i = ~100; let i = ~100;
do run_in_bare_thread { do run_in_bare_thread {
assert i == ~100; fail_unless!(i == ~100);
} }
} }
} }
@ -127,7 +127,7 @@ impl<T> Drop for ArcDestruct<T>{
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data); let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
let new_count = let new_count =
intrinsics::atomic_xsub(&mut data.count, 1) - 1; intrinsics::atomic_xsub(&mut data.count, 1) - 1;
assert new_count >= 0; fail_unless!(new_count >= 0);
if new_count == 0 { if new_count == 0 {
// drop glue takes over. // drop glue takes over.
} else { } else {
@ -167,7 +167,7 @@ pub unsafe fn get_shared_mutable_state<T:Owned>(
{ {
unsafe { unsafe {
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data); let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
assert ptr.count > 0; fail_unless!(ptr.count > 0);
let r = cast::transmute(option::get_ref(&ptr.data)); let r = cast::transmute(option::get_ref(&ptr.data));
cast::forget(ptr); cast::forget(ptr);
return r; return r;
@ -178,7 +178,7 @@ pub unsafe fn get_shared_immutable_state<T:Owned>(
rc: &a/SharedMutableState<T>) -> &a/T { rc: &a/SharedMutableState<T>) -> &a/T {
unsafe { unsafe {
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data); let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
assert ptr.count > 0; fail_unless!(ptr.count > 0);
// Cast us back into the correct region // Cast us back into the correct region
let r = cast::transmute_region(option::get_ref(&ptr.data)); let r = cast::transmute_region(option::get_ref(&ptr.data));
cast::forget(ptr); cast::forget(ptr);
@ -191,7 +191,7 @@ pub unsafe fn clone_shared_mutable_state<T:Owned>(rc: &SharedMutableState<T>)
unsafe { unsafe {
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data); let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1; let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1;
assert new_count >= 2; fail_unless!(new_count >= 2);
cast::forget(ptr); cast::forget(ptr);
} }
ArcDestruct((*rc).data) ArcDestruct((*rc).data)
@ -342,7 +342,7 @@ pub mod tests {
for futures.each |f| { f.recv() } for futures.each |f| { f.recv() }
do total.with |total| { do total.with |total| {
assert **total == num_tasks * count fail_unless!(**total == num_tasks * count)
}; };
} }
@ -354,11 +354,11 @@ pub mod tests {
let x2 = x.clone(); let x2 = x.clone();
do task::try || { do task::try || {
do x2.with |one| { do x2.with |one| {
assert *one == 2; fail_unless!(*one == 2);
} }
}; };
do x.with |one| { do x.with |one| {
assert *one == 1; fail_unless!(*one == 1);
} }
} }
} }

View file

@ -79,7 +79,7 @@ fn test_at_exit() {
let i = 10; let i = 10;
do at_exit { do at_exit {
debug!("at_exit1"); debug!("at_exit1");
assert i == 10; fail_unless!(i == 10);
} }
} }
@ -89,8 +89,8 @@ fn test_at_exit_many() {
for uint::range(20, 100) |j| { for uint::range(20, 100) |j| {
do at_exit { do at_exit {
debug!("at_exit2"); debug!("at_exit2");
assert i == 10; fail_unless!(i == 10);
assert j > i; fail_unless!(j > i);
} }
} }
} }

View file

@ -20,11 +20,11 @@ use intrinsic::TyDesc;
pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void { pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
unsafe { unsafe {
assert td.is_not_null(); fail_unless!(td.is_not_null());
let total_size = get_box_size(size, (*td).align); let total_size = get_box_size(size, (*td).align);
let p = c_malloc(total_size as size_t); let p = c_malloc(total_size as size_t);
assert p.is_not_null(); fail_unless!(p.is_not_null());
// FIXME #3475: Converting between our two different tydesc types // FIXME #3475: Converting between our two different tydesc types
let td: *TyDesc = transmute(td); let td: *TyDesc = transmute(td);
@ -46,7 +46,7 @@ pub unsafe fn free(ptr: *c_void) {
let exchange_count = &mut *rust_get_exchange_count_ptr(); let exchange_count = &mut *rust_get_exchange_count_ptr();
atomic_xsub(exchange_count, 1); atomic_xsub(exchange_count, 1);
assert ptr.is_not_null(); fail_unless!(ptr.is_not_null());
c_free(ptr); c_free(ptr);
} }
@ -60,7 +60,7 @@ fn get_box_size(body_size: uint, body_align: uint) -> uint {
// Rounds |size| to the nearest |alignment|. Invariant: |alignment| is a power // Rounds |size| to the nearest |alignment|. Invariant: |alignment| is a power
// of two. // of two.
fn align_to(size: uint, align: uint) -> uint { fn align_to(size: uint, align: uint) -> uint {
assert align != 0; fail_unless!(align != 0);
(size + align - 1) & !(align - 1) (size + align - 1) & !(align - 1)
} }

View file

@ -340,11 +340,11 @@ pub mod ct {
parse_count(s, 0, s.len()) == Parsed::new(count, next) parse_count(s, 0, s.len()) == Parsed::new(count, next)
} }
assert test("", CountImplied, 0); fail_unless!(test("", CountImplied, 0));
assert test("*", CountIsNextParam, 1); fail_unless!(test("*", CountIsNextParam, 1));
assert test("*1", CountIsNextParam, 1); fail_unless!(test("*1", CountIsNextParam, 1));
assert test("*1$", CountIsParam(1), 3); fail_unless!(test("*1$", CountIsParam(1), 3));
assert test("123", CountIs(123), 3); fail_unless!(test("123", CountIs(123), 3));
} }
#[test] #[test]
@ -355,8 +355,8 @@ pub mod ct {
fn test(s: &str, flags: &[Flag], next: uint) { fn test(s: &str, flags: &[Flag], next: uint) {
let f = parse_flags(s, 0, s.len()); let f = parse_flags(s, 0, s.len());
assert pack(f.val) == pack(flags); fail_unless!(pack(f.val) == pack(flags));
assert f.next == next; fail_unless!(f.next == next);
} }
test("", [], 0); test("", [], 0);
@ -367,7 +367,7 @@ pub mod ct {
#[test] #[test]
fn test_parse_fmt_string() { fn test_parse_fmt_string() {
assert parse_fmt_string("foo %s bar", die) == ~[ fail_unless!(parse_fmt_string("foo %s bar", die) == ~[
PieceString(~"foo "), PieceString(~"foo "),
PieceConv(Conv { PieceConv(Conv {
param: None, param: None,
@ -376,19 +376,19 @@ pub mod ct {
precision: CountImplied, precision: CountImplied,
ty: TyStr, ty: TyStr,
}), }),
PieceString(~" bar")]; PieceString(~" bar")]);
assert parse_fmt_string("%s", die) == ~[ fail_unless!(parse_fmt_string("%s", die) == ~[
PieceConv(Conv { PieceConv(Conv {
param: None, param: None,
flags: ~[], flags: ~[],
width: CountImplied, width: CountImplied,
precision: CountImplied, precision: CountImplied,
ty: TyStr, ty: TyStr,
})]; })]);
assert parse_fmt_string("%%%%", die) == ~[ fail_unless!(parse_fmt_string("%%%%", die) == ~[
PieceString(~"%"), PieceString(~"%")]; PieceString(~"%"), PieceString(~"%")]);
} }
#[test] #[test]
@ -397,10 +397,10 @@ pub mod ct {
parse_parameter(s, 0, s.len()) == Parsed::new(param, next) parse_parameter(s, 0, s.len()) == Parsed::new(param, next)
} }
assert test("", None, 0); fail_unless!(test("", None, 0));
assert test("foo", None, 0); fail_unless!(test("foo", None, 0));
assert test("123", None, 0); fail_unless!(test("123", None, 0));
assert test("123$", Some(123), 4); fail_unless!(test("123$", Some(123), 4));
} }
#[test] #[test]
@ -409,12 +409,12 @@ pub mod ct {
parse_precision(s, 0, s.len()) == Parsed::new(count, next) parse_precision(s, 0, s.len()) == Parsed::new(count, next)
} }
assert test("", CountImplied, 0); fail_unless!(test("", CountImplied, 0));
assert test(".", CountIs(0), 1); fail_unless!(test(".", CountIs(0), 1));
assert test(".*", CountIsNextParam, 2); fail_unless!(test(".*", CountIsNextParam, 2));
assert test(".*1", CountIsNextParam, 2); fail_unless!(test(".*1", CountIsNextParam, 2));
assert test(".*1$", CountIsParam(1), 4); fail_unless!(test(".*1$", CountIsParam(1), 4));
assert test(".123", CountIs(123), 4); fail_unless!(test(".123", CountIs(123), 4));
} }
#[test] #[test]
@ -423,17 +423,17 @@ pub mod ct {
parse_type(s, 0, s.len(), die) == Parsed::new(ty, 1) parse_type(s, 0, s.len(), die) == Parsed::new(ty, 1)
} }
assert test("b", TyBool); fail_unless!(test("b", TyBool));
assert test("c", TyChar); fail_unless!(test("c", TyChar));
assert test("d", TyInt(Signed)); fail_unless!(test("d", TyInt(Signed)));
assert test("f", TyFloat); fail_unless!(test("f", TyFloat));
assert test("i", TyInt(Signed)); fail_unless!(test("i", TyInt(Signed)));
assert test("o", TyOctal); fail_unless!(test("o", TyOctal));
assert test("s", TyStr); fail_unless!(test("s", TyStr));
assert test("t", TyBits); fail_unless!(test("t", TyBits));
assert test("x", TyHex(CaseLower)); fail_unless!(test("x", TyHex(CaseLower)));
assert test("X", TyHex(CaseUpper)); fail_unless!(test("X", TyHex(CaseUpper)));
assert test("?", TyPoly); fail_unless!(test("?", TyPoly));
} }
#[test] #[test]
@ -453,16 +453,16 @@ pub mod ct {
#[test] #[test]
fn test_peek_num() { fn test_peek_num() {
let s1 = ""; let s1 = "";
assert peek_num(s1, 0, s1.len()).is_none(); fail_unless!(peek_num(s1, 0, s1.len()).is_none());
let s2 = "foo"; let s2 = "foo";
assert peek_num(s2, 0, s2.len()).is_none(); fail_unless!(peek_num(s2, 0, s2.len()).is_none());
let s3 = "123"; let s3 = "123";
assert peek_num(s3, 0, s3.len()) == Some(Parsed::new(123, 3)); fail_unless!(peek_num(s3, 0, s3.len()) == Some(Parsed::new(123, 3)));
let s4 = "123foo"; let s4 = "123foo";
assert peek_num(s4, 0, s4.len()) == Some(Parsed::new(123, 3)); fail_unless!(peek_num(s4, 0, s4.len()) == Some(Parsed::new(123, 3)));
} }
} }

View file

@ -57,11 +57,11 @@ fn test_success() {
do (|| { do (|| {
i = 10; i = 10;
}).finally { }).finally {
assert !failing(); fail_unless!(!failing());
assert i == 10; fail_unless!(i == 10);
i = 20; i = 20;
} }
assert i == 20; fail_unless!(i == 20);
} }
#[test] #[test]
@ -73,8 +73,8 @@ fn test_fail() {
i = 10; i = 10;
fail!(); fail!();
}).finally { }).finally {
assert failing(); fail_unless!(failing());
assert i == 10; fail_unless!(i == 10);
} }
} }
@ -82,7 +82,7 @@ fn test_fail() {
fn test_retval() { fn test_retval() {
let closure: &fn() -> int = || 10; let closure: &fn() -> int = || 10;
let i = do closure.finally { }; let i = do closure.finally { };
assert i == 10; fail_unless!(i == 10);
} }
#[test] #[test]

View file

@ -187,7 +187,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
let prev_i = unsafe { atomic_cxchg(&mut *global_ptr, 0, state_i) }; let prev_i = unsafe { atomic_cxchg(&mut *global_ptr, 0, state_i) };
// Sanity check that we're not trying to reinitialize after shutdown // Sanity check that we're not trying to reinitialize after shutdown
assert prev_i != POISON; fail_unless!(prev_i != POISON);
if prev_i == 0 { if prev_i == 0 {
// Successfully installed the global pointer // Successfully installed the global pointer
@ -201,7 +201,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
let prev_i = unsafe { let prev_i = unsafe {
atomic_cxchg(&mut *global_ptr, state_i, POISON) atomic_cxchg(&mut *global_ptr, state_i, POISON)
}; };
assert prev_i == state_i; fail_unless!(prev_i == state_i);
// Capture the global state object in the at_exit closure // Capture the global state object in the at_exit closure
// so that it is destroyed at the right time // so that it is destroyed at the right time
@ -245,7 +245,7 @@ fn test_clone_rc() {
~shared_mutable_state(10) ~shared_mutable_state(10)
}; };
assert get_shared_immutable_state(&val) == &10; fail_unless!(get_shared_immutable_state(&val) == &10);
} }
} }
} }
@ -273,7 +273,7 @@ fn test_modify() {
match v { match v {
Some(sms) => { Some(sms) => {
let v = get_shared_immutable_state(sms); let v = get_shared_immutable_state(sms);
assert *v == 10; fail_unless!(*v == 10);
None None
}, },
_ => fail!() _ => fail!()

View file

@ -40,7 +40,7 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
let shutdown_port = Cell(shutdown_port); let shutdown_port = Cell(shutdown_port);
let task = get_task_id(); let task = get_task_id();
// Expect the weak task service to be alive // Expect the weak task service to be alive
assert service.try_send(RegisterWeakTask(task, shutdown_chan)); fail_unless!(service.try_send(RegisterWeakTask(task, shutdown_chan)));
unsafe { rust_dec_kernel_live_count(); } unsafe { rust_dec_kernel_live_count(); }
do (|| { do (|| {
f(shutdown_port.take()) f(shutdown_port.take())
@ -102,7 +102,7 @@ fn run_weak_task_service(port: Port<ServiceMsg>) {
RegisterWeakTask(task, shutdown_chan) => { RegisterWeakTask(task, shutdown_chan) => {
let previously_unregistered = let previously_unregistered =
shutdown_map.insert(task, shutdown_chan); shutdown_map.insert(task, shutdown_chan);
assert previously_unregistered; fail_unless!(previously_unregistered);
} }
UnregisterWeakTask(task) => { UnregisterWeakTask(task) => {
match shutdown_map.pop(&task) { match shutdown_map.pop(&task) {

View file

@ -82,7 +82,7 @@ terminate normally, but instead directly return from a function.
~~~ ~~~
fn choose_weighted_item(v: &[Item]) -> Item { fn choose_weighted_item(v: &[Item]) -> Item {
assert !v.is_empty(); fail_unless!(!v.is_empty());
let mut so_far = 0u; let mut so_far = 0u;
for v.each |item| { for v.each |item| {
so_far += item.weight; so_far += item.weight;
@ -110,23 +110,23 @@ mod tests {
pub fn identity_crisis() { pub fn identity_crisis() {
// Writing a test for the identity function. How did it come to this? // Writing a test for the identity function. How did it come to this?
let x = ~[(5, false)]; let x = ~[(5, false)];
//FIXME #3387 assert x.eq(id(copy x)); //FIXME #3387 fail_unless!(x.eq(id(copy x)));
let y = copy x; let y = copy x;
assert x.eq(&id(y)); fail_unless!(x.eq(&id(y)));
} }
#[test] #[test]
pub fn test_swap() { pub fn test_swap() {
let mut x = 31337; let mut x = 31337;
let mut y = 42; let mut y = 42;
swap(&mut x, &mut y); swap(&mut x, &mut y);
assert x == 42; fail_unless!(x == 42);
assert y == 31337; fail_unless!(y == 31337);
} }
#[test] #[test]
pub fn test_replace() { pub fn test_replace() {
let mut x = Some(NonCopyable()); let mut x = Some(NonCopyable());
let y = replace(&mut x, None); let y = replace(&mut x, None);
assert x.is_none(); fail_unless!(x.is_none());
assert y.is_some(); fail_unless!(y.is_some());
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -29,13 +29,13 @@ pure fn builtin_equal<T>(&&a: T, &&b: T) -> bool { return a == b; }
pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { return a == b; } pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { return a == b; }
fn main() { fn main() {
assert (builtin_equal(5, 5)); fail_unless!((builtin_equal(5, 5)));
assert (!builtin_equal(5, 4)); fail_unless!((!builtin_equal(5, 4)));
assert (!vec_equal(~[5, 5], ~[5], bind builtin_equal(_, _))); fail_unless!((!vec_equal(~[5, 5], ~[5], bind builtin_equal(_, _))));
assert (!vec_equal(~[5, 5], ~[5], builtin_equal_int)); fail_unless!((!vec_equal(~[5, 5], ~[5], builtin_equal_int)));
assert (!vec_equal(~[5, 5], ~[5, 4], builtin_equal_int)); fail_unless!((!vec_equal(~[5, 5], ~[5, 4], builtin_equal_int)));
assert (!vec_equal(~[5, 5], ~[4, 5], builtin_equal_int)); fail_unless!((!vec_equal(~[5, 5], ~[4, 5], builtin_equal_int)));
assert (vec_equal(~[5, 5], ~[5, 5], builtin_equal_int)); fail_unless!((vec_equal(~[5, 5], ~[5, 5], builtin_equal_int)));
error!("Pass"); error!("Pass");
} }

View file

@ -14,12 +14,12 @@ use uint::range;
// random uint less than n // random uint less than n
fn under(r : rand::rng, n : uint) -> uint { fn under(r : rand::rng, n : uint) -> uint {
assert n != 0u; r.next() as uint % n fail_unless!(n != 0u); r.next() as uint % n
} }
// random choice from a vec // random choice from a vec
fn choice<T:copy>(r : rand::rng, v : ~[const T]) -> T { fn choice<T:copy>(r : rand::rng, v : ~[const T]) -> T {
assert vec::len(v) != 0u; v[under(r, vec::len(v))] fail_unless!(vec::len(v) != 0u); v[under(r, vec::len(v))]
} }
// k in n chance of being true // k in n chance of being true

View file

@ -371,13 +371,13 @@ pub fn check_whole_compiler(code: ~str, suggested_filename_prefix: &Path,
pub fn removeIfExists(filename: &Path) { pub fn removeIfExists(filename: &Path) {
// So sketchy! // So sketchy!
assert !contains(filename.to_str(), ~" "); fail_unless!(!contains(filename.to_str(), ~" "));
run::program_output(~"bash", ~[~"-c", ~"rm " + filename.to_str()]); run::program_output(~"bash", ~[~"-c", ~"rm " + filename.to_str()]);
} }
pub fn removeDirIfExists(filename: &Path) { pub fn removeDirIfExists(filename: &Path) {
// So sketchy! // So sketchy!
assert !contains(filename.to_str(), ~" "); fail_unless!(!contains(filename.to_str(), ~" "));
run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename.to_str()]); run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename.to_str()]);
} }

View file

@ -13,12 +13,12 @@ use std::rand;
// random uint less than n // random uint less than n
fn under(r : rand::rng, n : uint) -> uint { fn under(r : rand::rng, n : uint) -> uint {
assert n != 0u; r.next() as uint % n fail_unless!(n != 0u); r.next() as uint % n
} }
// random choice from a vec // random choice from a vec
fn choice<T:copy>(r : rand::rng, v : ~[T]) -> T { fn choice<T:copy>(r : rand::rng, v : ~[T]) -> T {
assert vec::len(v) != 0u; v[under(r, vec::len(v))] fail_unless!(vec::len(v) != 0u); v[under(r, vec::len(v))]
} }
// 1 in n chance of being true // 1 in n chance of being true
@ -49,12 +49,12 @@ fn shuffled<T:copy>(r : rand::rng, v : ~[T]) -> ~[T] {
// * weighted_vec is O(total weight) space // * weighted_vec is O(total weight) space
type weighted<T> = { weight: uint, item: T }; type weighted<T> = { weight: uint, item: T };
fn weighted_choice<T:copy>(r : rand::rng, v : ~[weighted<T>]) -> T { fn weighted_choice<T:copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
assert vec::len(v) != 0u; fail_unless!(vec::len(v) != 0u);
let total = 0u; let total = 0u;
for {weight: weight, item: _} in v { for {weight: weight, item: _} in v {
total += weight; total += weight;
} }
assert total >= 0u; fail_unless!(total >= 0u);
let chosen = under(r, total); let chosen = under(r, total);
let so_far = 0u; let so_far = 0u;
for {weight: weight, item: item} in v { for {weight: weight, item: item} in v {

View file

@ -118,7 +118,7 @@ pub fn get_rpath_relative_to_output(os: session::os,
-> Path { -> Path {
use core::os; use core::os;
assert not_win32(os); fail_unless!(not_win32(os));
// Mac doesn't appear to support $ORIGIN // Mac doesn't appear to support $ORIGIN
let prefix = match os { let prefix = match os {
@ -134,8 +134,8 @@ pub fn get_rpath_relative_to_output(os: session::os,
// Find the relative path from one file to another // Find the relative path from one file to another
pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path { pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
assert abs1.is_absolute; fail_unless!(abs1.is_absolute);
assert abs2.is_absolute; fail_unless!(abs2.is_absolute);
let abs1 = abs1.normalize(); let abs1 = abs1.normalize();
let abs2 = abs2.normalize(); let abs2 = abs2.normalize();
debug!("finding relative path from %s to %s", debug!("finding relative path from %s to %s",
@ -144,8 +144,8 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
let split2 = /*bad*/copy abs2.components; let split2 = /*bad*/copy abs2.components;
let len1 = vec::len(split1); let len1 = vec::len(split1);
let len2 = vec::len(split2); let len2 = vec::len(split2);
assert len1 > 0; fail_unless!(len1 > 0);
assert len2 > 0; fail_unless!(len2 > 0);
let max_common_path = uint::min(len1, len2) - 1; let max_common_path = uint::min(len1, len2) - 1;
let mut start_idx = 0; let mut start_idx = 0;
@ -215,7 +215,7 @@ mod test {
pub fn test_rpaths_to_flags() { pub fn test_rpaths_to_flags() {
let flags = rpaths_to_flags(~[Path("path1"), let flags = rpaths_to_flags(~[Path("path1"),
Path("path2")]); Path("path2")]);
assert flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]; fail_unless!(flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
} }
#[test] #[test]
@ -226,13 +226,13 @@ mod test {
debug!("test_prefix_path: %s vs. %s", debug!("test_prefix_path: %s vs. %s",
res.to_str(), res.to_str(),
d.to_str()); d.to_str());
assert str::ends_with(res.to_str(), d.to_str()); fail_unless!(str::ends_with(res.to_str(), d.to_str()));
} }
#[test] #[test]
pub fn test_prefix_rpath_abs() { pub fn test_prefix_rpath_abs() {
let res = get_install_prefix_rpath("triple"); let res = get_install_prefix_rpath("triple");
assert res.is_absolute; fail_unless!(res.is_absolute);
} }
#[test] #[test]
@ -240,7 +240,7 @@ mod test {
let res = minimize_rpaths([Path("rpath1"), let res = minimize_rpaths([Path("rpath1"),
Path("rpath2"), Path("rpath2"),
Path("rpath1")]); Path("rpath1")]);
assert res == ~[Path("rpath1"), Path("rpath2")]; fail_unless!(res == ~[Path("rpath1"), Path("rpath2")]);
} }
#[test] #[test]
@ -249,7 +249,7 @@ mod test {
Path("1a"), Path("4a"),Path("1a"), Path("1a"), Path("4a"),Path("1a"),
Path("2"), Path("3"), Path("4a"), Path("2"), Path("3"), Path("4a"),
Path("3")]); Path("3")]);
assert res == ~[Path("1a"), Path("2"), Path("4a"), Path("3")]; fail_unless!(res == ~[Path("1a"), Path("2"), Path("4a"), Path("3")]);
} }
#[test] #[test]
@ -257,7 +257,7 @@ mod test {
let p1 = Path("/usr/bin/rustc"); let p1 = Path("/usr/bin/rustc");
let p2 = Path("/usr/lib/mylib"); let p2 = Path("/usr/lib/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
assert res == Path("../lib"); fail_unless!(res == Path("../lib"));
} }
#[test] #[test]
@ -265,7 +265,7 @@ mod test {
let p1 = Path("/usr/bin/rustc"); let p1 = Path("/usr/bin/rustc");
let p2 = Path("/usr/bin/../lib/mylib"); let p2 = Path("/usr/bin/../lib/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
assert res == Path("../lib"); fail_unless!(res == Path("../lib"));
} }
#[test] #[test]
@ -273,7 +273,7 @@ mod test {
let p1 = Path("/usr/bin/whatever/rustc"); let p1 = Path("/usr/bin/whatever/rustc");
let p2 = Path("/usr/lib/whatever/mylib"); let p2 = Path("/usr/lib/whatever/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
assert res == Path("../../lib/whatever"); fail_unless!(res == Path("../../lib/whatever"));
} }
#[test] #[test]
@ -281,7 +281,7 @@ mod test {
let p1 = Path("/usr/bin/whatever/../rustc"); let p1 = Path("/usr/bin/whatever/../rustc");
let p2 = Path("/usr/lib/whatever/mylib"); let p2 = Path("/usr/lib/whatever/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
assert res == Path("../lib/whatever"); fail_unless!(res == Path("../lib/whatever"));
} }
#[test] #[test]
@ -289,7 +289,7 @@ mod test {
let p1 = Path("/usr/bin/whatever/../rustc"); let p1 = Path("/usr/bin/whatever/../rustc");
let p2 = Path("/usr/lib/whatever/../mylib"); let p2 = Path("/usr/lib/whatever/../mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
assert res == Path("../lib"); fail_unless!(res == Path("../lib"));
} }
#[test] #[test]
@ -297,7 +297,7 @@ mod test {
let p1 = Path("/1"); let p1 = Path("/1");
let p2 = Path("/2/3"); let p2 = Path("/2/3");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
assert res == Path("2"); fail_unless!(res == Path("2"));
} }
#[test] #[test]
@ -305,7 +305,7 @@ mod test {
let p1 = Path("/1/2"); let p1 = Path("/1/2");
let p2 = Path("/3"); let p2 = Path("/3");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
assert res == Path(".."); fail_unless!(res == Path(".."));
} }
#[test] #[test]
@ -318,7 +318,7 @@ mod test {
debug!("test_relative_tu8: %s vs. %s", debug!("test_relative_tu8: %s vs. %s",
res.to_str(), res.to_str(),
Path(".").to_str()); Path(".").to_str());
assert res == Path("."); fail_unless!(res == Path("."));
} }
#[test] #[test]
@ -328,7 +328,7 @@ mod test {
let o = session::os_linux; let o = session::os_linux;
let res = get_rpath_relative_to_output(o, let res = get_rpath_relative_to_output(o,
&Path("bin/rustc"), &Path("lib/libstd.so")); &Path("bin/rustc"), &Path("lib/libstd.so"));
assert res.to_str() == ~"$ORIGIN/../lib"; fail_unless!(res.to_str() == ~"$ORIGIN/../lib");
} }
#[test] #[test]
@ -337,7 +337,7 @@ mod test {
let o = session::os_freebsd; let o = session::os_freebsd;
let res = get_rpath_relative_to_output(o, let res = get_rpath_relative_to_output(o,
&Path("bin/rustc"), &Path("lib/libstd.so")); &Path("bin/rustc"), &Path("lib/libstd.so"));
assert res.to_str() == ~"$ORIGIN/../lib"; fail_unless!(res.to_str() == ~"$ORIGIN/../lib");
} }
#[test] #[test]
@ -348,7 +348,7 @@ mod test {
let res = get_rpath_relative_to_output(o, let res = get_rpath_relative_to_output(o,
&Path("bin/rustc"), &Path("bin/rustc"),
&Path("lib/libstd.so")); &Path("lib/libstd.so"));
assert res.to_str() == ~"@executable_path/../lib"; fail_unless!(res.to_str() == ~"@executable_path/../lib");
} }
#[test] #[test]
@ -358,6 +358,6 @@ mod test {
res.to_str(), res.to_str(),
os::make_absolute(&Path("lib")).to_str()); os::make_absolute(&Path("lib")).to_str());
assert res == os::make_absolute(&Path("lib")); fail_unless!(res == os::make_absolute(&Path("lib")));
} }
} }

View file

@ -902,7 +902,7 @@ pub mod test {
~"rustc", matches, diagnostic::emit); ~"rustc", matches, diagnostic::emit);
let sess = build_session(sessopts, diagnostic::emit); let sess = build_session(sessopts, diagnostic::emit);
let cfg = build_configuration(sess, ~"whatever", str_input(~"")); let cfg = build_configuration(sess, ~"whatever", str_input(~""));
assert (attr::contains_name(cfg, ~"test")); fail_unless!((attr::contains_name(cfg, ~"test")));
} }
// When the user supplies --test and --cfg test, don't implicitly add // When the user supplies --test and --cfg test, don't implicitly add
@ -922,7 +922,7 @@ pub mod test {
let sess = build_session(sessopts, diagnostic::emit); let sess = build_session(sessopts, diagnostic::emit);
let cfg = build_configuration(sess, ~"whatever", str_input(~"")); let cfg = build_configuration(sess, ~"whatever", str_input(~""));
let test_items = attr::find_meta_items_by_name(cfg, ~"test"); let test_items = attr::find_meta_items_by_name(cfg, ~"test");
assert (vec::len(test_items) == 1u); fail_unless!((vec::len(test_items) == 1u));
} }
} }

View file

@ -378,43 +378,43 @@ pub mod test {
#[test] #[test]
pub fn bin_crate_type_attr_results_in_bin_output() { pub fn bin_crate_type_attr_results_in_bin_output() {
let crate = make_crate(true, false); let crate = make_crate(true, false);
assert !building_library(unknown_crate, crate, false); fail_unless!(!building_library(unknown_crate, crate, false));
} }
#[test] #[test]
pub fn lib_crate_type_attr_results_in_lib_output() { pub fn lib_crate_type_attr_results_in_lib_output() {
let crate = make_crate(false, true); let crate = make_crate(false, true);
assert building_library(unknown_crate, crate, false); fail_unless!(building_library(unknown_crate, crate, false));
} }
#[test] #[test]
pub fn bin_option_overrides_lib_crate_type() { pub fn bin_option_overrides_lib_crate_type() {
let crate = make_crate(false, true); let crate = make_crate(false, true);
assert !building_library(bin_crate, crate, false); fail_unless!(!building_library(bin_crate, crate, false));
} }
#[test] #[test]
pub fn lib_option_overrides_bin_crate_type() { pub fn lib_option_overrides_bin_crate_type() {
let crate = make_crate(true, false); let crate = make_crate(true, false);
assert building_library(lib_crate, crate, false); fail_unless!(building_library(lib_crate, crate, false));
} }
#[test] #[test]
pub fn bin_crate_type_is_default() { pub fn bin_crate_type_is_default() {
let crate = make_crate(false, false); let crate = make_crate(false, false);
assert !building_library(unknown_crate, crate, false); fail_unless!(!building_library(unknown_crate, crate, false));
} }
#[test] #[test]
pub fn test_option_overrides_lib_crate_type() { pub fn test_option_overrides_lib_crate_type() {
let crate = make_crate(false, true); let crate = make_crate(false, true);
assert !building_library(unknown_crate, crate, true); fail_unless!(!building_library(unknown_crate, crate, true));
} }
#[test] #[test]
pub fn test_option_does_not_override_requested_lib_type() { pub fn test_option_does_not_override_requested_lib_type() {
let crate = make_crate(false, false); let crate = make_crate(false, false);
assert building_library(lib_crate, crate, true); fail_unless!(building_library(lib_crate, crate, true));
} }
} }

View file

@ -1460,8 +1460,8 @@ pub struct TypeNames {
} }
pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) { pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
assert tn.type_names.insert(t, s); fail_unless!(tn.type_names.insert(t, s));
assert tn.named_types.insert(s, t); fail_unless!(tn.named_types.insert(s, t));
} }
pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> { pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {

View file

@ -95,7 +95,7 @@ fn warn_if_multiple_versions(e: @mut Env,
} }
})); }));
assert !matches.is_empty(); fail_unless!(!matches.is_empty());
if matches.len() != 1u { if matches.len() != 1u {
diag.handler().warn( diag.handler().warn(

View file

@ -106,7 +106,7 @@ pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] {
} }
pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool { pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool {
assert *lib != ~""; fail_unless!(*lib != ~"");
if cstore.used_libraries.contains(&*lib) { return false; } if cstore.used_libraries.contains(&*lib) { return false; }
cstore.used_libraries.push(/*bad*/ copy *lib); cstore.used_libraries.push(/*bad*/ copy *lib);

View file

@ -1000,7 +1000,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
let meta_items = get_meta_items(attr_doc); let meta_items = get_meta_items(attr_doc);
// Currently it's only possible to have a single meta item on // Currently it's only possible to have a single meta item on
// an attribute // an attribute
assert (vec::len(meta_items) == 1u); fail_unless!((vec::len(meta_items) == 1u));
let meta_item = meta_items[0]; let meta_item = meta_items[0];
attrs.push( attrs.push(
codemap::spanned { codemap::spanned {

View file

@ -1064,7 +1064,7 @@ fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
ebml_w.start_tag(tag_index_buckets_bucket); ebml_w.start_tag(tag_index_buckets_bucket);
for vec::each(**bucket) |elt| { for vec::each(**bucket) |elt| {
ebml_w.start_tag(tag_index_buckets_bucket_elt); ebml_w.start_tag(tag_index_buckets_bucket_elt);
assert elt.pos < 0xffff_ffff; fail_unless!(elt.pos < 0xffff_ffff);
writer.write_be_u32(elt.pos as u32); writer.write_be_u32(elt.pos as u32);
write_fn(writer, elt.val); write_fn(writer, elt.val);
ebml_w.end_tag(); ebml_w.end_tag();
@ -1074,7 +1074,7 @@ fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
ebml_w.end_tag(); ebml_w.end_tag();
ebml_w.start_tag(tag_index_table); ebml_w.start_tag(tag_index_table);
for bucket_locs.each |pos| { for bucket_locs.each |pos| {
assert *pos < 0xffff_ffff; fail_unless!(*pos < 0xffff_ffff);
writer.write_be_u32(*pos as u32); writer.write_be_u32(*pos as u32);
} }
ebml_w.end_tag(); ebml_w.end_tag();
@ -1084,7 +1084,7 @@ fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
fn write_str(writer: io::Writer, &&s: ~str) { writer.write_str(s); } fn write_str(writer: io::Writer, &&s: ~str) { writer.write_str(s); }
fn write_int(writer: io::Writer, &&n: int) { fn write_int(writer: io::Writer, &&n: int) {
assert n < 0x7fff_ffff; fail_unless!(n < 0x7fff_ffff);
writer.write_be_u32(n as u32); writer.write_be_u32(n as u32);
} }
@ -1145,8 +1145,8 @@ fn synthesize_crate_attrs(ecx: @EncodeContext,
fn synthesize_link_attr(ecx: @EncodeContext, +items: ~[@meta_item]) -> fn synthesize_link_attr(ecx: @EncodeContext, +items: ~[@meta_item]) ->
attribute { attribute {
assert !ecx.link_meta.name.is_empty(); fail_unless!(!ecx.link_meta.name.is_empty());
assert !ecx.link_meta.vers.is_empty(); fail_unless!(!ecx.link_meta.vers.is_empty());
let name_item = let name_item =
attr::mk_name_value_item_str(@~"name", attr::mk_name_value_item_str(@~"name",
@ -1212,7 +1212,7 @@ fn encode_crate_deps(ecx: @EncodeContext,
// Sanity-check the crate numbers // Sanity-check the crate numbers
let mut expected_cnum = 1; let mut expected_cnum = 1;
for deps.each |n| { for deps.each |n| {
assert (n.cnum == expected_cnum); fail_unless!((n.cnum == expected_cnum));
expected_cnum += 1; expected_cnum += 1;
} }

View file

@ -140,12 +140,12 @@ fn parse_sigil(st: @mut PState) -> ast::Sigil {
} }
fn parse_vstore(st: @mut PState) -> ty::vstore { fn parse_vstore(st: @mut PState) -> ty::vstore {
assert next(st) == '/'; fail_unless!(next(st) == '/');
let c = peek(st); let c = peek(st);
if '0' <= c && c <= '9' { if '0' <= c && c <= '9' {
let n = parse_int(st) as uint; let n = parse_int(st) as uint;
assert next(st) == '|'; fail_unless!(next(st) == '|');
return ty::vstore_fixed(n); return ty::vstore_fixed(n);
} }
@ -162,7 +162,7 @@ fn parse_substs(st: @mut PState, conv: conv_did) -> ty::substs {
let self_ty = parse_opt(st, || parse_ty(st, conv) ); let self_ty = parse_opt(st, || parse_ty(st, conv) );
assert next(st) == '['; fail_unless!(next(st) == '[');
let mut params: ~[ty::t] = ~[]; let mut params: ~[ty::t] = ~[];
while peek(st) != ']' { params.push(parse_ty(st, conv)); } while peek(st) != ']' { params.push(parse_ty(st, conv)); }
st.pos = st.pos + 1u; st.pos = st.pos + 1u;
@ -179,13 +179,13 @@ fn parse_bound_region(st: @mut PState) -> ty::bound_region {
's' => ty::br_self, 's' => ty::br_self,
'a' => { 'a' => {
let id = parse_int(st) as uint; let id = parse_int(st) as uint;
assert next(st) == '|'; fail_unless!(next(st) == '|');
ty::br_anon(id) ty::br_anon(id)
} }
'[' => ty::br_named(st.tcx.sess.ident_of(parse_str(st, ']'))), '[' => ty::br_named(st.tcx.sess.ident_of(parse_str(st, ']'))),
'c' => { 'c' => {
let id = parse_int(st); let id = parse_int(st);
assert next(st) == '|'; fail_unless!(next(st) == '|');
ty::br_cap_avoid(id, @parse_bound_region(st)) ty::br_cap_avoid(id, @parse_bound_region(st))
}, },
_ => fail!(~"parse_bound_region: bad input") _ => fail!(~"parse_bound_region: bad input")
@ -198,16 +198,16 @@ fn parse_region(st: @mut PState) -> ty::Region {
ty::re_bound(parse_bound_region(st)) ty::re_bound(parse_bound_region(st))
} }
'f' => { 'f' => {
assert next(st) == '['; fail_unless!(next(st) == '[');
let id = parse_int(st); let id = parse_int(st);
assert next(st) == '|'; fail_unless!(next(st) == '|');
let br = parse_bound_region(st); let br = parse_bound_region(st);
assert next(st) == ']'; fail_unless!(next(st) == ']');
ty::re_free(id, br) ty::re_free(id, br)
} }
's' => { 's' => {
let id = parse_int(st); let id = parse_int(st);
assert next(st) == '|'; fail_unless!(next(st) == '|');
ty::re_scope(id) ty::re_scope(id)
} }
't' => { 't' => {
@ -259,18 +259,18 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
} }
'c' => return ty::mk_char(st.tcx), 'c' => return ty::mk_char(st.tcx),
't' => { 't' => {
assert (next(st) == '['); fail_unless!((next(st) == '['));
let def = parse_def(st, NominalType, conv); let def = parse_def(st, NominalType, conv);
let substs = parse_substs(st, conv); let substs = parse_substs(st, conv);
assert next(st) == ']'; fail_unless!(next(st) == ']');
return ty::mk_enum(st.tcx, def, substs); return ty::mk_enum(st.tcx, def, substs);
} }
'x' => { 'x' => {
assert next(st) == '['; fail_unless!(next(st) == '[');
let def = parse_def(st, NominalType, conv); let def = parse_def(st, NominalType, conv);
let substs = parse_substs(st, conv); let substs = parse_substs(st, conv);
let vstore = parse_vstore(st); let vstore = parse_vstore(st);
assert next(st) == ']'; fail_unless!(next(st) == ']');
return ty::mk_trait(st.tcx, def, substs, vstore); return ty::mk_trait(st.tcx, def, substs, vstore);
} }
'p' => { 'p' => {
@ -300,7 +300,7 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
return ty::mk_estr(st.tcx, v); return ty::mk_estr(st.tcx, v);
} }
'T' => { 'T' => {
assert (next(st) == '['); fail_unless!((next(st) == '['));
let mut params = ~[]; let mut params = ~[];
while peek(st) != ']' { params.push(parse_ty(st, conv)); } while peek(st) != ']' { params.push(parse_ty(st, conv)); }
st.pos = st.pos + 1u; st.pos = st.pos + 1u;
@ -319,9 +319,9 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
} }
'#' => { '#' => {
let pos = parse_hex(st); let pos = parse_hex(st);
assert (next(st) == ':'); fail_unless!((next(st) == ':'));
let len = parse_hex(st); let len = parse_hex(st);
assert (next(st) == '#'); fail_unless!((next(st) == '#'));
let key = ty::creader_cache_key {cnum: st.crate, let key = ty::creader_cache_key {cnum: st.crate,
pos: pos, pos: pos,
len: len }; len: len };
@ -342,10 +342,10 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
} }
'B' => ty::mk_opaque_box(st.tcx), 'B' => ty::mk_opaque_box(st.tcx),
'a' => { 'a' => {
assert (next(st) == '['); fail_unless!((next(st) == '['));
let did = parse_def(st, NominalType, conv); let did = parse_def(st, NominalType, conv);
let substs = parse_substs(st, conv); let substs = parse_substs(st, conv);
assert (next(st) == ']'); fail_unless!((next(st) == ']'));
return ty::mk_struct(st.tcx, did, substs); return ty::mk_struct(st.tcx, did, substs);
} }
c => { error!("unexpected char in type string: %c", c); fail!();} c => { error!("unexpected char in type string: %c", c); fail!();}
@ -460,7 +460,7 @@ fn parse_bare_fn_ty(st: @mut PState, conv: conv_did) -> ty::BareFnTy {
} }
fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig { fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig {
assert (next(st) == '['); fail_unless!((next(st) == '['));
let mut inputs: ~[ty::arg] = ~[]; let mut inputs: ~[ty::arg] = ~[];
while peek(st) != ']' { while peek(st) != ']' {
let mode = parse_mode(st); let mode = parse_mode(st);

View file

@ -176,7 +176,7 @@ pub impl ExtendedDecodeContext {
*/ */
// from_id_range should be non-empty // from_id_range should be non-empty
assert !ast_util::empty(self.from_id_range); fail_unless!(!ast_util::empty(self.from_id_range));
(id - self.from_id_range.min + self.to_id_range.min) (id - self.from_id_range.min + self.to_id_range.min)
} }
fn tr_def_id(&self, did: ast::def_id) -> ast::def_id { fn tr_def_id(&self, did: ast::def_id) -> ast::def_id {
@ -213,7 +213,7 @@ pub impl ExtendedDecodeContext {
* refer to the current crate and to the new, inlined node-id. * refer to the current crate and to the new, inlined node-id.
*/ */
assert did.crate == ast::local_crate; fail_unless!(did.crate == ast::local_crate);
ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) } ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) }
} }
fn tr_span(&self, _span: span) -> span { fn tr_span(&self, _span: span) -> span {
@ -1231,7 +1231,7 @@ fn roundtrip(in_item: Option<@ast::item>) {
debug!("expected string: %s", exp_str); debug!("expected string: %s", exp_str);
debug!("actual string : %s", out_str); debug!("actual string : %s", out_str);
assert exp_str == out_str; fail_unless!(exp_str == out_str);
} }
#[test] #[test]
@ -1278,8 +1278,10 @@ fn test_simplification() {
).get()); ).get());
match (item_out, item_exp) { match (item_out, item_exp) {
(ast::ii_item(item_out), ast::ii_item(item_exp)) => { (ast::ii_item(item_out), ast::ii_item(item_exp)) => {
assert pprust::item_to_str(item_out, ext_cx.parse_sess().interner) fail_unless!(pprust::item_to_str(item_out,
== pprust::item_to_str(item_exp, ext_cx.parse_sess().interner); ext_cx.parse_sess().interner)
== pprust::item_to_str(item_exp,
ext_cx.parse_sess().interner));
} }
_ => fail!() _ => fail!()
} }

View file

@ -132,7 +132,7 @@ pub fn raw_pat(p: @pat) -> @pat {
} }
pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) { pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
assert(!pats.is_empty()); fail_unless!((!pats.is_empty()));
let ext = match is_useful(cx, &pats.map(|p| ~[*p]), ~[wild()]) { let ext = match is_useful(cx, &pats.map(|p| ~[*p]), ~[wild()]) {
not_useful => { not_useful => {
// This is good, wildcard pattern isn't reachable // This is good, wildcard pattern isn't reachable

View file

@ -872,7 +872,7 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) { fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool { fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool {
let ident = cx.sess.str_of(ident); let ident = cx.sess.str_of(ident);
assert !ident.is_empty(); fail_unless!(!ident.is_empty());
let ident = ident_without_trailing_underscores(*ident); let ident = ident_without_trailing_underscores(*ident);
let ident = ident_without_leading_underscores(ident); let ident = ident_without_leading_underscores(ident);
char::is_uppercase(str::char_at(ident, 0)) && char::is_uppercase(str::char_at(ident, 0)) &&

View file

@ -777,7 +777,7 @@ pub impl Liveness {
fn live_on_entry(&self, ln: LiveNode, var: Variable) fn live_on_entry(&self, ln: LiveNode, var: Variable)
-> Option<LiveNodeKind> { -> Option<LiveNodeKind> {
assert ln.is_valid(); fail_unless!(ln.is_valid());
let reader = self.users[self.idx(ln, var)].reader; let reader = self.users[self.idx(ln, var)].reader;
if reader.is_valid() {Some(self.ir.lnk(reader))} else {None} if reader.is_valid() {Some(self.ir.lnk(reader))} else {None}
} }
@ -792,14 +792,14 @@ pub impl Liveness {
} }
fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool { fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool {
assert ln.is_valid(); fail_unless!(ln.is_valid());
self.users[self.idx(ln, var)].used self.users[self.idx(ln, var)].used
} }
fn assigned_on_entry(&self, ln: LiveNode, var: Variable) fn assigned_on_entry(&self, ln: LiveNode, var: Variable)
-> Option<LiveNodeKind> { -> Option<LiveNodeKind> {
assert ln.is_valid(); fail_unless!(ln.is_valid());
let writer = self.users[self.idx(ln, var)].writer; let writer = self.users[self.idx(ln, var)].writer;
if writer.is_valid() {Some(self.ir.lnk(writer))} else {None} if writer.is_valid() {Some(self.ir.lnk(writer))} else {None}
} }
@ -1493,11 +1493,11 @@ pub impl Liveness {
// repeat until fixed point is reached: // repeat until fixed point is reached:
while self.merge_from_succ(ln, body_ln, first_merge) { while self.merge_from_succ(ln, body_ln, first_merge) {
first_merge = false; first_merge = false;
assert cond_ln == self.propagate_through_opt_expr(cond, ln); fail_unless!(cond_ln == self.propagate_through_opt_expr(cond, ln));
assert body_ln == self.with_loop_nodes(expr.id, succ, ln, assert body_ln == self.with_loop_nodes(expr.id, succ, ln,
|| { || {
self.propagate_through_block(body, cond_ln) self.propagate_through_block(body, cond_ln)
}); }));
} }
cond_ln cond_ln

View file

@ -463,7 +463,7 @@ pub impl DetermineRpCtxt {
/// variance `variance`. If `id` was already parameterized, then /// variance `variance`. If `id` was already parameterized, then
/// the new variance is joined with the old variance. /// the new variance is joined with the old variance.
fn add_rp(&mut self, id: ast::node_id, variance: region_variance) { fn add_rp(&mut self, id: ast::node_id, variance: region_variance) {
assert id != 0; fail_unless!(id != 0);
let old_variance = self.region_paramd_items.find(&id); let old_variance = self.region_paramd_items.find(&id);
let joined_variance = match old_variance { let joined_variance = match old_variance {
None => variance, None => variance,

View file

@ -1411,7 +1411,7 @@ pub impl Resolver {
match view_path.node { match view_path.node {
view_path_simple(_, full_path, _, _) => { view_path_simple(_, full_path, _, _) => {
let path_len = full_path.idents.len(); let path_len = full_path.idents.len();
assert path_len != 0; fail_unless!(path_len != 0);
for full_path.idents.eachi |i, ident| { for full_path.idents.eachi |i, ident| {
if i != path_len - 1 { if i != path_len - 1 {
@ -2107,7 +2107,7 @@ pub impl Resolver {
// Decrement the count of unresolved imports. // Decrement the count of unresolved imports.
match resolution_result { match resolution_result {
Success(()) => { Success(()) => {
assert self.unresolved_imports >= 1; fail_unless!(self.unresolved_imports >= 1);
self.unresolved_imports -= 1; self.unresolved_imports -= 1;
} }
_ => { _ => {
@ -2123,7 +2123,7 @@ pub impl Resolver {
if !resolution_result.indeterminate() { if !resolution_result.indeterminate() {
match *import_directive.subclass { match *import_directive.subclass {
GlobImport => { GlobImport => {
assert module_.glob_count >= 1; fail_unless!(module_.glob_count >= 1);
module_.glob_count -= 1; module_.glob_count -= 1;
} }
SingleImport(*) => { SingleImport(*) => {
@ -2258,7 +2258,7 @@ pub impl Resolver {
} }
// We've successfully resolved the import. Write the results in. // We've successfully resolved the import. Write the results in.
assert module_.import_resolutions.contains_key(&target); fail_unless!(module_.import_resolutions.contains_key(&target));
let import_resolution = module_.import_resolutions.get(&target); let import_resolution = module_.import_resolutions.get(&target);
match value_result { match value_result {
@ -2320,7 +2320,7 @@ pub impl Resolver {
} }
} }
assert import_resolution.outstanding_references >= 1; fail_unless!(import_resolution.outstanding_references >= 1);
import_resolution.outstanding_references -= 1; import_resolution.outstanding_references -= 1;
debug!("(resolving single import) successfully resolved import"); debug!("(resolving single import) successfully resolved import");
@ -2417,7 +2417,7 @@ pub impl Resolver {
} }
// We've successfully resolved the import. Write the results in. // We've successfully resolved the import. Write the results in.
assert module_.import_resolutions.contains_key(&target); fail_unless!(module_.import_resolutions.contains_key(&target));
let import_resolution = module_.import_resolutions.get(&target); let import_resolution = module_.import_resolutions.get(&target);
match module_result { match module_result {
@ -2442,7 +2442,7 @@ pub impl Resolver {
return Failed; return Failed;
} }
assert import_resolution.outstanding_references >= 1; fail_unless!(import_resolution.outstanding_references >= 1);
import_resolution.outstanding_references -= 1; import_resolution.outstanding_references -= 1;
debug!("(resolving single module import) successfully resolved \ debug!("(resolving single module import) successfully resolved \
@ -2476,7 +2476,7 @@ pub impl Resolver {
return Indeterminate; return Indeterminate;
} }
assert containing_module.glob_count == 0; fail_unless!(containing_module.glob_count == 0);
// Add all resolved imports from the containing module. // Add all resolved imports from the containing module.
for containing_module.import_resolutions.each for containing_module.import_resolutions.each
@ -2664,7 +2664,7 @@ pub impl Resolver {
span: span) span: span)
-> ResolveResult<@mut Module> { -> ResolveResult<@mut Module> {
let module_path_len = module_path.len(); let module_path_len = module_path.len();
assert module_path_len > 0; fail_unless!(module_path_len > 0);
debug!("(resolving module path for import) processing `%s` rooted at \ debug!("(resolving module path for import) processing `%s` rooted at \
`%s`", `%s`",
@ -3016,7 +3016,7 @@ pub impl Resolver {
// If this is a search of all imports, we should be done with glob // If this is a search of all imports, we should be done with glob
// resolution at this point. // resolution at this point.
if name_search_type == SearchItemsAndAllImports { if name_search_type == SearchItemsAndAllImports {
assert module_.glob_count == 0; fail_unless!(module_.glob_count == 0);
} }
// Check the list of resolved imports. // Check the list of resolved imports.

View file

@ -1219,7 +1219,7 @@ pub fn compile_submatch(bcx: block,
/* /*
For an empty match, a fall-through case must exist For an empty match, a fall-through case must exist
*/ */
assert(m.len() > 0u || chk.is_some()); fail_unless!((m.len() > 0u || chk.is_some()));
let _icx = bcx.insn_ctxt("match::compile_submatch"); let _icx = bcx.insn_ctxt("match::compile_submatch");
let mut bcx = bcx; let mut bcx = bcx;
let tcx = bcx.tcx(), dm = tcx.def_map; let tcx = bcx.tcx(), dm = tcx.def_map;

View file

@ -306,8 +306,8 @@ pub fn non_gc_box_cast(bcx: block, val: ValueRef) -> ValueRef {
unsafe { unsafe {
debug!("non_gc_box_cast"); debug!("non_gc_box_cast");
add_comment(bcx, ~"non_gc_box_cast"); add_comment(bcx, ~"non_gc_box_cast");
assert(llvm::LLVMGetPointerAddressSpace(val_ty(val)) == fail_unless!(llvm::LLVMGetPointerAddressSpace(val_ty(val)) ==
gc_box_addrspace || bcx.unreachable); gc_box_addrspace || bcx.unreachable);
let non_gc_t = T_ptr(llvm::LLVMGetElementType(val_ty(val))); let non_gc_t = T_ptr(llvm::LLVMGetElementType(val_ty(val)));
PointerCast(bcx, val, non_gc_t) PointerCast(bcx, val, non_gc_t)
} }
@ -479,7 +479,7 @@ pub fn get_res_dtor(ccx: @CrateContext, did: ast::def_id,
let did = if did.crate != ast::local_crate { let did = if did.crate != ast::local_crate {
inline::maybe_instantiate_inline(ccx, did, true) inline::maybe_instantiate_inline(ccx, did, true)
} else { did }; } else { did };
assert did.crate == ast::local_crate; fail_unless!(did.crate == ast::local_crate);
let (val, _) = let (val, _) =
monomorphize::monomorphic_fn(ccx, did, substs, None, None, None); monomorphize::monomorphic_fn(ccx, did, substs, None, None, None);
@ -1301,7 +1301,7 @@ pub fn cleanup_and_leave(bcx: block,
} }
cur = match cur.parent { cur = match cur.parent {
Some(next) => next, Some(next) => next,
None => { assert upto.is_none(); break; } None => { fail_unless!(upto.is_none()); break; }
}; };
} }
match leave { match leave {
@ -1488,7 +1488,7 @@ pub fn alloc_ty(bcx: block, t: ty::t) -> ValueRef {
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let llty = type_of::type_of(ccx, t); let llty = type_of::type_of(ccx, t);
if ty::type_has_params(t) { log(error, ty_to_str(ccx.tcx, t)); } if ty::type_has_params(t) { log(error, ty_to_str(ccx.tcx, t)); }
assert !ty::type_has_params(t); fail_unless!(!ty::type_has_params(t));
let val = alloca(bcx, llty); let val = alloca(bcx, llty);
return val; return val;
} }
@ -2443,7 +2443,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
// Want parent_id and not id, because id is the dtor's type // Want parent_id and not id, because id is the dtor's type
let class_ty = ty::lookup_item_type(tcx, parent_id).ty; let class_ty = ty::lookup_item_type(tcx, parent_id).ty;
// This code shouldn't be reached if the class is generic // This code shouldn't be reached if the class is generic
assert !ty::type_has_params(class_ty); fail_unless!(!ty::type_has_params(class_ty));
let lldty = unsafe { let lldty = unsafe {
T_fn(~[ T_fn(~[
T_ptr(type_of(ccx, ty::mk_nil(tcx))), T_ptr(type_of(ccx, ty::mk_nil(tcx))),
@ -2463,7 +2463,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
let llfn; let llfn;
match /*bad*/copy (*v).node.kind { match /*bad*/copy (*v).node.kind {
ast::tuple_variant_kind(args) => { ast::tuple_variant_kind(args) => {
assert args.len() != 0u; fail_unless!(args.len() != 0u);
let pth = vec::append(/*bad*/copy *pth, let pth = vec::append(/*bad*/copy *pth,
~[path_name(enm.ident), ~[path_name(enm.ident),
path_name((*v).node.name)]); path_name((*v).node.name)]);

View file

@ -814,7 +814,7 @@ pub fn Phi(cx: block, Ty: TypeRef, vals: &[ValueRef], bbs: &[BasicBlockRef])
-> ValueRef { -> ValueRef {
unsafe { unsafe {
if cx.unreachable { return llvm::LLVMGetUndef(Ty); } if cx.unreachable { return llvm::LLVMGetUndef(Ty); }
assert vals.len() == bbs.len(); fail_unless!(vals.len() == bbs.len());
let phi = EmptyPhi(cx, Ty); let phi = EmptyPhi(cx, Ty);
count_insn(cx, "addincoming"); count_insn(cx, "addincoming");
llvm::LLVMAddIncoming(phi, vec::raw::to_ptr(vals), llvm::LLVMAddIncoming(phi, vec::raw::to_ptr(vals),
@ -1008,7 +1008,7 @@ pub fn Trap(cx: block) {
let T: ValueRef = str::as_c_str(~"llvm.trap", |buf| { let T: ValueRef = str::as_c_str(~"llvm.trap", |buf| {
llvm::LLVMGetNamedFunction(M, buf) llvm::LLVMGetNamedFunction(M, buf)
}); });
assert (T as int != 0); fail_unless!((T as int != 0));
let Args: ~[ValueRef] = ~[]; let Args: ~[ValueRef] = ~[];
unsafe { unsafe {
count_insn(cx, "trap"); count_insn(cx, "trap");
@ -1022,7 +1022,7 @@ pub fn LandingPad(cx: block, Ty: TypeRef, PersFn: ValueRef,
NumClauses: uint) -> ValueRef { NumClauses: uint) -> ValueRef {
unsafe { unsafe {
check_not_terminated(cx); check_not_terminated(cx);
assert !cx.unreachable; fail_unless!(!cx.unreachable);
count_insn(cx, "landingpad"); count_insn(cx, "landingpad");
return llvm::LLVMBuildLandingPad(B(cx), Ty, PersFn, return llvm::LLVMBuildLandingPad(B(cx), Ty, PersFn,
NumClauses as c_uint, noname()); NumClauses as c_uint, noname());

View file

@ -130,9 +130,9 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
} }
ast::def_variant(tid, vid) => { ast::def_variant(tid, vid) => {
// nullary variants are not callable // nullary variants are not callable
assert ty::enum_variant_with_id(bcx.tcx(), fail_unless!(ty::enum_variant_with_id(bcx.tcx(),
tid, tid,
vid).args.len() > 0u; vid).args.len() > 0u);
fn_callee(bcx, trans_fn_ref(bcx, vid, ref_expr.id)) fn_callee(bcx, trans_fn_ref(bcx, vid, ref_expr.id))
} }
ast::def_struct(def_id) => { ast::def_struct(def_id) => {
@ -280,7 +280,7 @@ pub fn trans_fn_ref_with_vtables(
// Create a monomorphic verison of generic functions // Create a monomorphic verison of generic functions
if must_monomorphise { if must_monomorphise {
// Should be either intra-crate or inlined. // Should be either intra-crate or inlined.
assert def_id.crate == ast::local_crate; fail_unless!(def_id.crate == ast::local_crate);
let mut (val, must_cast) = let mut (val, must_cast) =
monomorphize::monomorphic_fn(ccx, def_id, type_params, monomorphize::monomorphic_fn(ccx, def_id, type_params,
@ -704,7 +704,7 @@ pub fn trans_arg_expr(bcx: block,
// FIXME(#3548) use the adjustments table // FIXME(#3548) use the adjustments table
match autoref_arg { match autoref_arg {
DoAutorefArg => { DoAutorefArg => {
assert !bcx.ccx().maps.moves_map.contains_key(&arg_expr.id); fail_unless!(!bcx.ccx().maps.moves_map.contains_key(&arg_expr.id));
val = arg_datum.to_ref_llval(bcx); val = arg_datum.to_ref_llval(bcx);
} }
DontAutorefArg => { DontAutorefArg => {
@ -722,8 +722,8 @@ pub fn trans_arg_expr(bcx: block,
ast::by_val => { ast::by_val => {
// NB: avoid running the take glue. // NB: avoid running the take glue.
assert !bcx.ccx().maps.moves_map.contains_key( fail_unless!(!bcx.ccx().maps.moves_map.contains_key(
&arg_expr.id); &arg_expr.id));
val = arg_datum.to_value_llval(bcx); val = arg_datum.to_value_llval(bcx);
} }

View file

@ -271,7 +271,7 @@ pub fn build_closure(bcx0: block,
let datum = expr::trans_local_var(bcx, cap_var.def); let datum = expr::trans_local_var(bcx, cap_var.def);
match cap_var.mode { match cap_var.mode {
moves::CapRef => { moves::CapRef => {
assert sigil == ast::BorrowedSigil; fail_unless!(sigil == ast::BorrowedSigil);
env_vals.push(EnvValue {action: EnvRef, env_vals.push(EnvValue {action: EnvRef,
datum: datum}); datum: datum});
} }

View file

@ -1339,7 +1339,7 @@ pub fn monomorphize_type(bcx: block, t: ty::t) -> ty::t {
Some(substs) => { Some(substs) => {
ty::subst_tps(bcx.tcx(), substs.tys, substs.self_ty, t) ty::subst_tps(bcx.tcx(), substs.tys, substs.self_ty, t)
} }
_ => { assert !ty::type_has_params(t); t } _ => { fail_unless!(!ty::type_has_params(t)); t }
} }
} }

View file

@ -70,7 +70,7 @@ pub fn const_lit(cx: @CrateContext, e: @ast::expr, lit: ast::lit)
pub fn const_ptrcast(cx: @CrateContext, a: ValueRef, t: TypeRef) -> ValueRef { pub fn const_ptrcast(cx: @CrateContext, a: ValueRef, t: TypeRef) -> ValueRef {
unsafe { unsafe {
let b = llvm::LLVMConstPointerCast(a, T_ptr(t)); let b = llvm::LLVMConstPointerCast(a, T_ptr(t));
assert cx.const_globals.insert(b as int, a); fail_unless!(cx.const_globals.insert(b as int, a));
b b
} }
} }
@ -100,7 +100,7 @@ pub fn const_deref(cx: @CrateContext, v: ValueRef) -> ValueRef {
Some(v) => v, Some(v) => v,
None => v None => v
}; };
assert llvm::LLVMIsGlobalConstant(v) == True; fail_unless!(llvm::LLVMIsGlobalConstant(v) == True);
let v = llvm::LLVMGetInitializer(v); let v = llvm::LLVMGetInitializer(v);
v v
} }
@ -290,7 +290,7 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
let len = llvm::LLVMConstIntGetZExtValue(len) as u64; let len = llvm::LLVMConstIntGetZExtValue(len) as u64;
let len = match ty::get(bt).sty { let len = match ty::get(bt).sty {
ty::ty_estr(*) => {assert len > 0; len - 1}, ty::ty_estr(*) => {fail_unless!(len > 0); len - 1},
_ => len _ => len
}; };
if iv >= len { if iv >= len {
@ -417,14 +417,14 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
} }
} }
ast::expr_path(pth) => { ast::expr_path(pth) => {
assert pth.types.len() == 0; fail_unless!(pth.types.len() == 0);
match cx.tcx.def_map.find(&e.id) { match cx.tcx.def_map.find(&e.id) {
Some(ast::def_fn(def_id, _purity)) => { Some(ast::def_fn(def_id, _purity)) => {
let f = if !ast_util::is_local(def_id) { let f = if !ast_util::is_local(def_id) {
let ty = csearch::get_type(cx.tcx, def_id).ty; let ty = csearch::get_type(cx.tcx, def_id).ty;
base::trans_external_path(cx, def_id, ty) base::trans_external_path(cx, def_id, ty)
} else { } else {
assert ast_util::is_local(def_id); fail_unless!(ast_util::is_local(def_id));
base::get_item_val(cx, def_id.node) base::get_item_val(cx, def_id.node)
}; };
let ety = ty::expr_ty_adjusted(cx.tcx, e); let ety = ty::expr_ty_adjusted(cx.tcx, e);

View file

@ -48,7 +48,7 @@ pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block {
bcx = expr::trans_into(bcx, e, dest); bcx = expr::trans_into(bcx, e, dest);
} }
None => { None => {
assert dest == expr::Ignore || bcx.unreachable; fail_unless!(dest == expr::Ignore || bcx.unreachable);
} }
} }
return bcx; return bcx;

View file

@ -253,19 +253,19 @@ pub impl Datum {
action: CopyAction, datum: Datum) -> block { action: CopyAction, datum: Datum) -> block {
debug!("store_to_datum(self=%s, action=%?, datum=%s)", debug!("store_to_datum(self=%s, action=%?, datum=%s)",
self.to_str(bcx.ccx()), action, datum.to_str(bcx.ccx())); self.to_str(bcx.ccx()), action, datum.to_str(bcx.ccx()));
assert datum.mode.is_by_ref(); fail_unless!(datum.mode.is_by_ref());
self.store_to(bcx, id, action, datum.val) self.store_to(bcx, id, action, datum.val)
} }
fn move_to_datum(&self, bcx: block, action: CopyAction, datum: Datum) fn move_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
-> block { -> block {
assert datum.mode.is_by_ref(); fail_unless!(datum.mode.is_by_ref());
self.move_to(bcx, action, datum.val) self.move_to(bcx, action, datum.val)
} }
fn copy_to_datum(&self, bcx: block, action: CopyAction, datum: Datum) fn copy_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
-> block { -> block {
assert datum.mode.is_by_ref(); fail_unless!(datum.mode.is_by_ref());
self.copy_to(bcx, action, datum.val) self.copy_to(bcx, action, datum.val)
} }
@ -378,7 +378,7 @@ pub impl Datum {
* Schedules this datum for cleanup in `bcx`. The datum * Schedules this datum for cleanup in `bcx`. The datum
* must be an rvalue. */ * must be an rvalue. */
assert self.source == RevokeClean; fail_unless!(self.source == RevokeClean);
match self.mode { match self.mode {
ByValue => { ByValue => {
add_clean_temp_immediate(bcx, self.val, self.ty); add_clean_temp_immediate(bcx, self.val, self.ty);
@ -399,7 +399,7 @@ pub impl Datum {
// Lvalues which potentially need to be dropped // Lvalues which potentially need to be dropped
// must be passed by ref, so that we can zero them // must be passed by ref, so that we can zero them
// out. // out.
assert self.mode.is_by_ref(); fail_unless!(self.mode.is_by_ref());
zero_mem(bcx, self.val, self.ty); zero_mem(bcx, self.val, self.ty);
} }
} }
@ -705,7 +705,7 @@ pub impl Datum {
// changing the type, so I am putting this // changing the type, so I am putting this
// code in place here to do the right // code in place here to do the right
// thing if this change ever goes through. // thing if this change ever goes through.
assert ty::type_is_immediate(ty); fail_unless!(ty::type_is_immediate(ty));
(Some(Datum {ty: ty, ..*self}), bcx) (Some(Datum {ty: ty, ..*self}), bcx)
} }
}; };
@ -746,7 +746,7 @@ pub impl Datum {
// except for changing the type, so I am putting this // except for changing the type, so I am putting this
// code in place here to do the right thing if this // code in place here to do the right thing if this
// change ever goes through. // change ever goes through.
assert ty::type_is_immediate(ty); fail_unless!(ty::type_is_immediate(ty));
(Some(Datum {ty: ty, ..*self}), bcx) (Some(Datum {ty: ty, ..*self}), bcx)
} }
} }
@ -806,7 +806,7 @@ pub impl Datum {
// either we were asked to deref a specific number of times, // either we were asked to deref a specific number of times,
// in which case we should have, or we asked to deref as many // in which case we should have, or we asked to deref as many
// times as we can // times as we can
assert derefs == max || max == uint::max_value; fail_unless!(derefs == max || max == uint::max_value);
DatumBlock { bcx: bcx, datum: datum } DatumBlock { bcx: bcx, datum: datum }
} }
@ -826,7 +826,7 @@ pub impl DatumBlock {
} }
fn assert_by_ref(&self) -> DatumBlock { fn assert_by_ref(&self) -> DatumBlock {
assert self.datum.mode.is_by_ref(); fail_unless!(self.datum.mode.is_by_ref());
*self *self
} }

View file

@ -286,7 +286,7 @@ pub fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock {
debug!("add_env(closure_ty=%s)", ty_to_str(tcx, closure_ty)); debug!("add_env(closure_ty=%s)", ty_to_str(tcx, closure_ty));
let scratch = scratch_datum(bcx, closure_ty, false); let scratch = scratch_datum(bcx, closure_ty, false);
let llfn = GEPi(bcx, scratch.val, [0u, abi::fn_field_code]); let llfn = GEPi(bcx, scratch.val, [0u, abi::fn_field_code]);
assert datum.appropriate_mode() == ByValue; fail_unless!(datum.appropriate_mode() == ByValue);
Store(bcx, datum.to_appropriate_llval(bcx), llfn); Store(bcx, datum.to_appropriate_llval(bcx), llfn);
let llenv = GEPi(bcx, scratch.val, [0u, abi::fn_field_box]); let llenv = GEPi(bcx, scratch.val, [0u, abi::fn_field_box]);
Store(bcx, base::null_env_ptr(bcx), llenv); Store(bcx, base::null_env_ptr(bcx), llenv);
@ -465,7 +465,7 @@ fn trans_rvalue_datum_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
} }
ast::expr_binary(op, lhs, rhs) => { ast::expr_binary(op, lhs, rhs) => {
// if overloaded, would be RvalueDpsExpr // if overloaded, would be RvalueDpsExpr
assert !bcx.ccx().maps.method_map.contains_key(&expr.id); fail_unless!(!bcx.ccx().maps.method_map.contains_key(&expr.id));
return trans_binary(bcx, expr, op, lhs, rhs); return trans_binary(bcx, expr, op, lhs, rhs);
} }
@ -1318,10 +1318,10 @@ fn trans_unary_datum(bcx: block,
let _icx = bcx.insn_ctxt("trans_unary_datum"); let _icx = bcx.insn_ctxt("trans_unary_datum");
// if deref, would be LvalueExpr // if deref, would be LvalueExpr
assert op != ast::deref; fail_unless!(op != ast::deref);
// if overloaded, would be RvalueDpsExpr // if overloaded, would be RvalueDpsExpr
assert !bcx.ccx().maps.method_map.contains_key(&un_expr.id); fail_unless!(!bcx.ccx().maps.method_map.contains_key(&un_expr.id));
let un_ty = expr_ty(bcx, un_expr); let un_ty = expr_ty(bcx, un_expr);
let sub_ty = expr_ty(bcx, sub_expr); let sub_ty = expr_ty(bcx, sub_expr);

View file

@ -398,7 +398,7 @@ pub fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) {
let _icx = bcx.insn_ctxt("make_visit_glue"); let _icx = bcx.insn_ctxt("make_visit_glue");
let mut bcx = bcx; let mut bcx = bcx;
let ty_visitor_name = special_idents::ty_visitor; let ty_visitor_name = special_idents::ty_visitor;
assert bcx.ccx().tcx.intrinsic_defs.contains_key(&ty_visitor_name); fail_unless!(bcx.ccx().tcx.intrinsic_defs.contains_key(&ty_visitor_name));
let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name); let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name);
let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty))); let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty)));
bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, trait_id); bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, trait_id);
@ -486,7 +486,7 @@ pub fn trans_struct_drop(bcx: block,
// Class dtors have no explicit args, so the params should // Class dtors have no explicit args, so the params should
// just consist of the output pointer and the environment // just consist of the output pointer and the environment
// (self) // (self)
assert(params.len() == 2); fail_unless!((params.len() == 2));
// If we need to take a reference to the class (because it's using // If we need to take a reference to the class (because it's using
// the Drop trait), do so now. // the Drop trait), do so now.
@ -670,7 +670,7 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
let _icx = ccx.insn_ctxt("declare_tydesc"); let _icx = ccx.insn_ctxt("declare_tydesc");
// If emit_tydescs already ran, then we shouldn't be creating any new // If emit_tydescs already ran, then we shouldn't be creating any new
// tydescs. // tydescs.
assert !*ccx.finished_tydescs; fail_unless!(!*ccx.finished_tydescs);
let llty = type_of(ccx, t); let llty = type_of(ccx, t);

View file

@ -56,8 +56,8 @@ pub fn monomorphic_fn(ccx: @CrateContext,
} }
}); });
for real_substs.each() |s| { assert !ty::type_has_params(*s); } for real_substs.each() |s| { fail_unless!(!ty::type_has_params(*s)); }
for substs.each() |s| { assert !ty::type_has_params(*s); } for substs.each() |s| { fail_unless!(!ty::type_has_params(*s)); }
let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len()); let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
// XXX: Bad copy. // XXX: Bad copy.
let hash_id = make_mono_id(ccx, fn_id, copy substs, vtables, impl_did_opt, let hash_id = make_mono_id(ccx, fn_id, copy substs, vtables, impl_did_opt,

View file

@ -336,7 +336,7 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block,
-> block { -> block {
use syntax::parse::token::special_idents::tydesc; use syntax::parse::token::special_idents::tydesc;
let final = sub_block(bcx, ~"final"); let final = sub_block(bcx, ~"final");
assert bcx.ccx().tcx.intrinsic_defs.contains_key(&tydesc); fail_unless!(bcx.ccx().tcx.intrinsic_defs.contains_key(&tydesc));
let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc); let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc);
let tydesc_ty = type_of(bcx.ccx(), tydesc_ty); let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
let mut r = Reflector { let mut r = Reflector {

View file

@ -70,7 +70,7 @@ pub fn type_of_fn_from_ty(cx: @CrateContext, fty: ty::t) -> TypeRef {
} }
pub fn type_of_non_gc_box(cx: @CrateContext, t: ty::t) -> TypeRef { pub fn type_of_non_gc_box(cx: @CrateContext, t: ty::t) -> TypeRef {
assert !ty::type_needs_infer(t); fail_unless!(!ty::type_needs_infer(t));
let t_norm = ty::normalize_ty(cx.tcx, t); let t_norm = ty::normalize_ty(cx.tcx, t);
if t != t_norm { if t != t_norm {

View file

@ -1981,7 +1981,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
// If this assertion failures, it is likely because of a // If this assertion failures, it is likely because of a
// failure in the cross-crate inlining code to translate a // failure in the cross-crate inlining code to translate a
// def-id. // def-id.
assert p.def_id.crate == ast::local_crate; fail_unless!(p.def_id.crate == ast::local_crate);
param_bounds_to_contents( param_bounds_to_contents(
cx, cx.ty_param_bounds.get(&p.def_id.node)) cx, cx.ty_param_bounds.get(&p.def_id.node))
@ -3519,7 +3519,7 @@ pub fn trait_supertraits(cx: ctxt,
// Not in the cache. It had better be in the metadata, which means it // Not in the cache. It had better be in the metadata, which means it
// shouldn't be local. // shouldn't be local.
assert !is_local(id); fail_unless!(!is_local(id));
// Get the supertraits out of the metadata and create the // Get the supertraits out of the metadata and create the
// InstantiatedTraitRef for each. // InstantiatedTraitRef for each.
@ -3551,7 +3551,7 @@ pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
// If the lookup in trait_method_cache fails, assume that the trait // If the lookup in trait_method_cache fails, assume that the trait
// method we're trying to look up is in a different crate, and look // method we're trying to look up is in a different crate, and look
// for it there. // for it there.
assert id.crate != ast::local_crate; fail_unless!(id.crate != ast::local_crate);
let result = csearch::get_trait_methods(cx, id); let result = csearch::get_trait_methods(cx, id);
// Store the trait method in the local trait_method_cache so that // Store the trait method in the local trait_method_cache so that
@ -3872,7 +3872,7 @@ pub fn lookup_item_type(cx: ctxt,
return tpt; return tpt;
} }
None => { None => {
assert did.crate != ast::local_crate; fail_unless!(did.crate != ast::local_crate);
let tyt = csearch::get_type(cx, did); let tyt = csearch::get_type(cx, did);
cx.tcache.insert(did, tyt); cx.tcache.insert(did, tyt);
return tyt; return tyt;

Some files were not shown because too many files have changed in this diff Show more