Skip to content

librustc: Remove fail_unless! #5628

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ let v = ~[1,2,3];

mutate(copy v); // Pass a copy

fail_unless!(v[0] == 1); // Original was not modified
assert!(v[0] == 1); // Original was not modified
~~~~

### Unary move expressions
Expand Down Expand Up @@ -2491,7 +2491,7 @@ An example of a tuple type and its use:
type Pair<'self> = (int,&'self str);
let p: Pair<'static> = (10,"hello");
let (a, b) = p;
fail_unless!(b != "world");
assert!(b != "world");
~~~~


Expand Down Expand Up @@ -2519,7 +2519,7 @@ An example of a vector type and its use:
~~~~
let v: &[int] = &[7, 5, 3];
let i: int = v[2];
fail_unless!(i == 3);
assert!(i == 3);
~~~~

All in-bounds elements of a vector are always initialized,
Expand Down Expand Up @@ -2925,7 +2925,7 @@ example of an _implicit dereference_ operation performed on box values:
~~~~~~~~
struct Foo { y: int }
let x = @Foo{y: 10};
fail_unless!(x.y == 10);
assert!(x.y == 10);
~~~~~~~~

Other operations act on box values as single-word-sized address values. For
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn unix_time_in_microseconds() -> u64 {
}
}

# fn main() { fail_unless!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
# fn main() { assert!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
~~~~

The `#[nolink]` attribute indicates that there's no foreign library to
Expand Down
12 changes: 6 additions & 6 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );

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!(
~reason)`) and the `fail_unless!` construct (which effectively calls `fail!()`
~reason)`) and the `assert!` construct (which effectively calls `fail!()`
if a boolean expression is false) are both ways to raise exceptions. When a
task raises an exception the task unwinds its stack---running destructors and
freeing memory along the way---and then exits. Unlike exceptions in C++,
Expand Down Expand Up @@ -339,7 +339,7 @@ let result: Result<int, ()> = do task::try {
fail!(~"oops!");
}
};
fail_unless!(result.is_err());
assert!(result.is_err());
~~~

Unlike `spawn`, the function spawned using `try` may return a value,
Expand Down Expand Up @@ -401,7 +401,7 @@ do spawn { // Bidirectionally linked
// Wait for the supervised child task to exist.
let message = receiver.recv();
// Kill both it and the parent task.
fail_unless!(message != 42);
assert!(message != 42);
}
do try { // Unidirectionally linked
sender.send(42);
Expand Down Expand Up @@ -507,13 +507,13 @@ do spawn {
};

from_child.send(22);
fail_unless!(from_child.recv() == ~"22");
assert!(from_child.recv() == ~"22");

from_child.send(23);
from_child.send(0);

fail_unless!(from_child.recv() == ~"23");
fail_unless!(from_child.recv() == ~"0");
assert!(from_child.recv() == ~"23");
assert!(from_child.recv() == ~"0");

# }
~~~~
Expand Down
10 changes: 5 additions & 5 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ expression to the given type.
~~~~
let x: float = 4.0;
let y: uint = x as uint;
fail_unless!(y == 4u);
assert!(y == 4u);
~~~~

## Syntax extensions
Expand Down Expand Up @@ -850,8 +850,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 oops(a: int, b: int, x: int) -> () { a * x + b; }

fail_unless!(8 == line(5, 3, 1));
fail_unless!(() == oops(5, 3, 1));
assert!(8 == line(5, 3, 1));
assert!(() == oops(5, 3, 1));
~~~~

As with `match` expressions and `let` bindings, function arguments support
Expand Down Expand Up @@ -1417,8 +1417,8 @@ and [`core::str`]. Here are some examples.
let crayons = [Almond, AntiqueBrass, Apricot];

// Check the length of the vector
fail_unless!(crayons.len() == 3);
fail_unless!(!crayons.is_empty());
assert!(crayons.len() == 3);
assert!(!crayons.is_empty());

// Iterate over a vector, obtaining a pointer to each element
for crayons.each |crayon| {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn parse_config(args: ~[~str]) -> config {
getopts::optflag(~"jit"),
getopts::optflag(~"newrt")];

fail_unless!(!args.is_empty());
assert!(!args.is_empty());
let args_ = vec::tail(args);
let matches =
&match getopts::getopts(args_, opts) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
let mut env = os::env();

// Make sure we include the aux directory in the path
fail_unless!(prog.ends_with(~".exe"));
assert!(prog.ends_with(~".exe"));
let aux_path = prog.slice(0u, prog.len() - 4u) + ~".libaux";

env = do vec::map(env) |pair| {
Expand Down
26 changes: 13 additions & 13 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,30 @@ pub fn test() {
}

assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]);
fail_unless!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
fail_unless!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
assert!(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]);
}

#[test]
pub fn append_test() {
fail_unless!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
}

#[test]
pub fn test_from_owned() {
fail_unless!(from_owned::<int>(~[]) == @[]);
fail_unless!(from_owned(~[true]) == @[true]);
fail_unless!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
fail_unless!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
fail_unless!(from_owned(~[~[42]]) == @[~[42]]);
assert!(from_owned::<int>(~[]) == @[]);
assert!(from_owned(~[true]) == @[true]);
assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
assert!(from_owned(~[~[42]]) == @[~[42]]);
}

#[test]
pub fn test_from_slice() {
fail_unless!(from_slice::<int>([]) == @[]);
fail_unless!(from_slice([true]) == @[true]);
fail_unless!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
fail_unless!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
fail_unless!(from_slice([@[42]]) == @[@[42]]);
assert!(from_slice::<int>([]) == @[]);
assert!(from_slice([true]) == @[true]);
assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
assert!(from_slice([@[42]]) == @[@[42]]);
}

8 changes: 4 additions & 4 deletions src/libcore/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ pub fn test_bool_from_str() {
use from_str::FromStr;

do all_values |v| {
fail_unless!(Some(v) == FromStr::from_str(to_str(v)))
assert!(Some(v) == FromStr::from_str(to_str(v)))
}
}

#[test]
pub fn test_bool_to_str() {
fail_unless!(to_str(false) == ~"false");
fail_unless!(to_str(true) == ~"true");
assert!(to_str(false) == ~"false");
assert!(to_str(true) == ~"true");
}

#[test]
pub fn test_bool_to_bit() {
do all_values |v| {
fail_unless!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
assert!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
*
* # Example
*
* fail_unless!(transmute("L") == ~[76u8, 0u8]);
* assert!(transmute("L") == ~[76u8, 0u8]);
*/
#[inline(always)]
pub unsafe fn transmute<L, G>(thing: L) -> G {
Expand Down Expand Up @@ -116,7 +116,7 @@ pub mod tests {

#[test]
pub fn test_reinterpret_cast() {
fail_unless!(1u == unsafe { reinterpret_cast(&1) });
assert!(1u == unsafe { reinterpret_cast(&1) });
}

#[test]
Expand All @@ -127,8 +127,8 @@ pub mod tests {
let ptr: *int = transmute(box); // refcount 2
let _box1: @~str = reinterpret_cast(&ptr);
let _box2: @~str = reinterpret_cast(&ptr);
fail_unless!(*_box1 == ~"box box box");
fail_unless!(*_box2 == ~"box box box");
assert!(*_box1 == ~"box box box");
assert!(*_box2 == ~"box box box");
// Will destroy _box1 and _box2. Without the bump, this would
// use-after-free. With too many bumps, it would leak.
}
Expand All @@ -140,15 +140,15 @@ pub mod tests {
unsafe {
let x = @100u8;
let x: *BoxRepr = transmute(x);
fail_unless!((*x).data == 100);
assert!((*x).data == 100);
let _x: @int = transmute(x);
}
}

#[test]
pub fn test_transmute2() {
unsafe {
fail_unless!(~[76u8, 0u8] == transmute(~"L"));
assert!(~[76u8, 0u8] == transmute(~"L"));
}
}
}
8 changes: 4 additions & 4 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ pub impl<T> Cell<T> {
#[test]
fn test_basic() {
let value_cell = Cell(~10);
fail_unless!(!value_cell.is_empty());
assert!(!value_cell.is_empty());
let value = value_cell.take();
fail_unless!(value == ~10);
fail_unless!(value_cell.is_empty());
assert!(value == ~10);
assert!(value_cell.is_empty());
value_cell.put_back(value);
fail_unless!(!value_cell.is_empty());
assert!(!value_cell.is_empty());
}

#[test]
Expand Down
56 changes: 28 additions & 28 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn escape_unicode(c: char) -> ~str {
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
else if c <= '\uffff' { ('u', 4u) }
else { ('U', 8u) });
fail_unless!(str::len(s) <= pad);
assert!(str::len(s) <= pad);
let mut out = ~"\\";
unsafe {
str::push_str(&mut out, str::from_char(c));
Expand Down Expand Up @@ -258,32 +258,32 @@ impl Eq for char {

#[test]
fn test_is_lowercase() {
fail_unless!(is_lowercase('a'));
fail_unless!(is_lowercase('ö'));
fail_unless!(is_lowercase('ß'));
fail_unless!(!is_lowercase('Ü'));
fail_unless!(!is_lowercase('P'));
assert!(is_lowercase('a'));
assert!(is_lowercase('ö'));
assert!(is_lowercase('ß'));
assert!(!is_lowercase('Ü'));
assert!(!is_lowercase('P'));
}

#[test]
fn test_is_uppercase() {
fail_unless!(!is_uppercase('h'));
fail_unless!(!is_uppercase('ä'));
fail_unless!(!is_uppercase('ß'));
fail_unless!(is_uppercase('Ö'));
fail_unless!(is_uppercase('T'));
assert!(!is_uppercase('h'));
assert!(!is_uppercase('ä'));
assert!(!is_uppercase('ß'));
assert!(is_uppercase('Ö'));
assert!(is_uppercase('T'));
}

#[test]
fn test_is_whitespace() {
fail_unless!(is_whitespace(' '));
fail_unless!(is_whitespace('\u2007'));
fail_unless!(is_whitespace('\t'));
fail_unless!(is_whitespace('\n'));
assert!(is_whitespace(' '));
assert!(is_whitespace('\u2007'));
assert!(is_whitespace('\t'));
assert!(is_whitespace('\n'));

fail_unless!(!is_whitespace('a'));
fail_unless!(!is_whitespace('_'));
fail_unless!(!is_whitespace('\u0000'));
assert!(!is_whitespace('a'));
assert!(!is_whitespace('_'));
assert!(!is_whitespace('\u0000'));
}

#[test]
Expand All @@ -299,24 +299,24 @@ fn test_to_digit() {
assert_eq!(to_digit('z', 36u), Some(35u));
assert_eq!(to_digit('Z', 36u), Some(35u));

fail_unless!(to_digit(' ', 10u).is_none());
fail_unless!(to_digit('$', 36u).is_none());
assert!(to_digit(' ', 10u).is_none());
assert!(to_digit('$', 36u).is_none());
}

#[test]
fn test_is_ascii() {
fail_unless!(str::all(~"banana", is_ascii));
fail_unless!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
assert!(str::all(~"banana", is_ascii));
assert!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
}

#[test]
fn test_is_digit() {
fail_unless!(is_digit('2'));
fail_unless!(is_digit('7'));
fail_unless!(! is_digit('c'));
fail_unless!(! is_digit('i'));
fail_unless!(! is_digit('z'));
fail_unless!(! is_digit('Q'));
assert!(is_digit('2'));
assert!(is_digit('7'));
assert!(! is_digit('c'));
assert!(! is_digit('i'));
assert!(! is_digit('z'));
assert!(! is_digit('Q'));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod test {

#[test]
fn test_int_totaleq() {
fail_unless!(5.equals(&5));
fail_unless!(!2.equals(&17));
assert!(5.equals(&5));
assert!(!2.equals(&17));
}
}
2 changes: 1 addition & 1 deletion src/libcore/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,6 @@ pub mod test {
let _chan = chan;
}

fail_unless!(!port.peek());
assert!(!port.peek());
}
}
Loading