Skip to content

Commit f864934

Browse files
committed
auto merge of #5628 : brson/rust/assert, r=brson
2 parents a17a9d4 + 1e91595 commit f864934

File tree

862 files changed

+5924
-5937
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

862 files changed

+5924
-5937
lines changed

doc/rust.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ let v = ~[1,2,3];
19711971
19721972
mutate(copy v); // Pass a copy
19731973
1974-
fail_unless!(v[0] == 1); // Original was not modified
1974+
assert!(v[0] == 1); // Original was not modified
19751975
~~~~
19761976

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

24972497

@@ -2519,7 +2519,7 @@ An example of a vector type and its use:
25192519
~~~~
25202520
let v: &[int] = &[7, 5, 3];
25212521
let i: int = v[2];
2522-
fail_unless!(i == 3);
2522+
assert!(i == 3);
25232523
~~~~
25242524

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

29312931
Other operations act on box values as single-word-sized address values. For

doc/tutorial-ffi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ fn unix_time_in_microseconds() -> u64 {
239239
}
240240
}
241241
242-
# fn main() { fail_unless!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
242+
# fn main() { assert!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
243243
~~~~
244244

245245
The `#[nolink]` attribute indicates that there's no foreign library to

doc/tutorial-tasks.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );
297297

298298
Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
299299
(which can also be written with an error string as an argument: `fail!(
300-
~reason)`) and the `fail_unless!` construct (which effectively calls `fail!()`
300+
~reason)`) and the `assert!` construct (which effectively calls `fail!()`
301301
if a boolean expression is false) are both ways to raise exceptions. When a
302302
task raises an exception the task unwinds its stack---running destructors and
303303
freeing memory along the way---and then exits. Unlike exceptions in C++,
@@ -339,7 +339,7 @@ let result: Result<int, ()> = do task::try {
339339
fail!(~"oops!");
340340
}
341341
};
342-
fail_unless!(result.is_err());
342+
assert!(result.is_err());
343343
~~~
344344

345345
Unlike `spawn`, the function spawned using `try` may return a value,
@@ -401,7 +401,7 @@ do spawn { // Bidirectionally linked
401401
// Wait for the supervised child task to exist.
402402
let message = receiver.recv();
403403
// Kill both it and the parent task.
404-
fail_unless!(message != 42);
404+
assert!(message != 42);
405405
}
406406
do try { // Unidirectionally linked
407407
sender.send(42);
@@ -507,13 +507,13 @@ do spawn {
507507
};
508508
509509
from_child.send(22);
510-
fail_unless!(from_child.recv() == ~"22");
510+
assert!(from_child.recv() == ~"22");
511511
512512
from_child.send(23);
513513
from_child.send(0);
514514
515-
fail_unless!(from_child.recv() == ~"23");
516-
fail_unless!(from_child.recv() == ~"0");
515+
assert!(from_child.recv() == ~"23");
516+
assert!(from_child.recv() == ~"0");
517517
518518
# }
519519
~~~~

doc/tutorial.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ expression to the given type.
381381
~~~~
382382
let x: float = 4.0;
383383
let y: uint = x as uint;
384-
fail_unless!(y == 4u);
384+
assert!(y == 4u);
385385
~~~~
386386

387387
## Syntax extensions
@@ -850,8 +850,8 @@ Ending the function with a semicolon like so is equivalent to returning `()`.
850850
fn line(a: int, b: int, x: int) -> int { a * x + b }
851851
fn oops(a: int, b: int, x: int) -> () { a * x + b; }
852852
853-
fail_unless!(8 == line(5, 3, 1));
854-
fail_unless!(() == oops(5, 3, 1));
853+
assert!(8 == line(5, 3, 1));
854+
assert!(() == oops(5, 3, 1));
855855
~~~~
856856

857857
As with `match` expressions and `let` bindings, function arguments support
@@ -1417,8 +1417,8 @@ and [`core::str`]. Here are some examples.
14171417
let crayons = [Almond, AntiqueBrass, Apricot];
14181418
14191419
// Check the length of the vector
1420-
fail_unless!(crayons.len() == 3);
1421-
fail_unless!(!crayons.is_empty());
1420+
assert!(crayons.len() == 3);
1421+
assert!(!crayons.is_empty());
14221422
14231423
// Iterate over a vector, obtaining a pointer to each element
14241424
for crayons.each |crayon| {

src/compiletest/compiletest.rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn parse_config(args: ~[~str]) -> config {
6565
getopts::optflag(~"jit"),
6666
getopts::optflag(~"newrt")];
6767

68-
fail_unless!(!args.is_empty());
68+
assert!(!args.is_empty());
6969
let args_ = vec::tail(args);
7070
let matches =
7171
&match getopts::getopts(args_, opts) {

src/compiletest/procsrv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
2525
let mut env = os::env();
2626

2727
// Make sure we include the aux directory in the path
28-
fail_unless!(prog.ends_with(~".exe"));
28+
assert!(prog.ends_with(~".exe"));
2929
let aux_path = prog.slice(0u, prog.len() - 4u) + ~".libaux";
3030
3131
env = do vec::map(env) |pair| {

src/libcore/at_vec.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,30 @@ pub fn test() {
292292
}
293293

294294
assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]);
295-
fail_unless!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
296-
fail_unless!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
295+
assert!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
296+
assert!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
297297
}
298298

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

304304
#[test]
305305
pub fn test_from_owned() {
306-
fail_unless!(from_owned::<int>(~[]) == @[]);
307-
fail_unless!(from_owned(~[true]) == @[true]);
308-
fail_unless!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
309-
fail_unless!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
310-
fail_unless!(from_owned(~[~[42]]) == @[~[42]]);
306+
assert!(from_owned::<int>(~[]) == @[]);
307+
assert!(from_owned(~[true]) == @[true]);
308+
assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
309+
assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
310+
assert!(from_owned(~[~[42]]) == @[~[42]]);
311311
}
312312
313313
#[test]
314314
pub fn test_from_slice() {
315-
fail_unless!(from_slice::<int>([]) == @[]);
316-
fail_unless!(from_slice([true]) == @[true]);
317-
fail_unless!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
318-
fail_unless!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
319-
fail_unless!(from_slice([@[42]]) == @[@[42]]);
315+
assert!(from_slice::<int>([]) == @[]);
316+
assert!(from_slice([true]) == @[true]);
317+
assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
318+
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
319+
assert!(from_slice([@[42]]) == @[@[42]]);
320320
}
321321

src/libcore/bool.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,20 @@ pub fn test_bool_from_str() {
8686
use from_str::FromStr;
8787

8888
do all_values |v| {
89-
fail_unless!(Some(v) == FromStr::from_str(to_str(v)))
89+
assert!(Some(v) == FromStr::from_str(to_str(v)))
9090
}
9191
}
9292

9393
#[test]
9494
pub fn test_bool_to_str() {
95-
fail_unless!(to_str(false) == ~"false");
96-
fail_unless!(to_str(true) == ~"true");
95+
assert!(to_str(false) == ~"false");
96+
assert!(to_str(true) == ~"true");
9797
}
9898

9999
#[test]
100100
pub fn test_bool_to_bit() {
101101
do all_values |v| {
102-
fail_unless!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
102+
assert!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
103103
}
104104
}
105105

src/libcore/cast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
5050
*
5151
* # Example
5252
*
53-
* fail_unless!(transmute("L") == ~[76u8, 0u8]);
53+
* assert!(transmute("L") == ~[76u8, 0u8]);
5454
*/
5555
#[inline(always)]
5656
pub unsafe fn transmute<L, G>(thing: L) -> G {
@@ -116,7 +116,7 @@ pub mod tests {
116116

117117
#[test]
118118
pub fn test_reinterpret_cast() {
119-
fail_unless!(1u == unsafe { reinterpret_cast(&1) });
119+
assert!(1u == unsafe { reinterpret_cast(&1) });
120120
}
121121

122122
#[test]
@@ -127,8 +127,8 @@ pub mod tests {
127127
let ptr: *int = transmute(box); // refcount 2
128128
let _box1: @~str = reinterpret_cast(&ptr);
129129
let _box2: @~str = reinterpret_cast(&ptr);
130-
fail_unless!(*_box1 == ~"box box box");
131-
fail_unless!(*_box2 == ~"box box box");
130+
assert!(*_box1 == ~"box box box");
131+
assert!(*_box2 == ~"box box box");
132132
// Will destroy _box1 and _box2. Without the bump, this would
133133
// use-after-free. With too many bumps, it would leak.
134134
}
@@ -140,15 +140,15 @@ pub mod tests {
140140
unsafe {
141141
let x = @100u8;
142142
let x: *BoxRepr = transmute(x);
143-
fail_unless!((*x).data == 100);
143+
assert!((*x).data == 100);
144144
let _x: @int = transmute(x);
145145
}
146146
}
147147
148148
#[test]
149149
pub fn test_transmute2() {
150150
unsafe {
151-
fail_unless!(~[76u8, 0u8] == transmute(~"L"));
151+
assert!(~[76u8, 0u8] == transmute(~"L"));
152152
}
153153
}
154154
}

src/libcore/cell.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ pub impl<T> Cell<T> {
8080
#[test]
8181
fn test_basic() {
8282
let value_cell = Cell(~10);
83-
fail_unless!(!value_cell.is_empty());
83+
assert!(!value_cell.is_empty());
8484
let value = value_cell.take();
85-
fail_unless!(value == ~10);
86-
fail_unless!(value_cell.is_empty());
85+
assert!(value == ~10);
86+
assert!(value_cell.is_empty());
8787
value_cell.put_back(value);
88-
fail_unless!(!value_cell.is_empty());
88+
assert!(!value_cell.is_empty());
8989
}
9090

9191
#[test]

src/libcore/char.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub fn escape_unicode(c: char) -> ~str {
200200
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
201201
else if c <= '\uffff' { ('u', 4u) }
202202
else { ('U', 8u) });
203-
fail_unless!(str::len(s) <= pad);
203+
assert!(str::len(s) <= pad);
204204
let mut out = ~"\\";
205205
unsafe {
206206
str::push_str(&mut out, str::from_char(c));
@@ -258,32 +258,32 @@ impl Eq for char {
258258

259259
#[test]
260260
fn test_is_lowercase() {
261-
fail_unless!(is_lowercase('a'));
262-
fail_unless!(is_lowercase('ö'));
263-
fail_unless!(is_lowercase('ß'));
264-
fail_unless!(!is_lowercase('Ü'));
265-
fail_unless!(!is_lowercase('P'));
261+
assert!(is_lowercase('a'));
262+
assert!(is_lowercase('ö'));
263+
assert!(is_lowercase('ß'));
264+
assert!(!is_lowercase('Ü'));
265+
assert!(!is_lowercase('P'));
266266
}
267267

268268
#[test]
269269
fn test_is_uppercase() {
270-
fail_unless!(!is_uppercase('h'));
271-
fail_unless!(!is_uppercase('ä'));
272-
fail_unless!(!is_uppercase('ß'));
273-
fail_unless!(is_uppercase('Ö'));
274-
fail_unless!(is_uppercase('T'));
270+
assert!(!is_uppercase('h'));
271+
assert!(!is_uppercase('ä'));
272+
assert!(!is_uppercase('ß'));
273+
assert!(is_uppercase('Ö'));
274+
assert!(is_uppercase('T'));
275275
}
276276

277277
#[test]
278278
fn test_is_whitespace() {
279-
fail_unless!(is_whitespace(' '));
280-
fail_unless!(is_whitespace('\u2007'));
281-
fail_unless!(is_whitespace('\t'));
282-
fail_unless!(is_whitespace('\n'));
279+
assert!(is_whitespace(' '));
280+
assert!(is_whitespace('\u2007'));
281+
assert!(is_whitespace('\t'));
282+
assert!(is_whitespace('\n'));
283283

284-
fail_unless!(!is_whitespace('a'));
285-
fail_unless!(!is_whitespace('_'));
286-
fail_unless!(!is_whitespace('\u0000'));
284+
assert!(!is_whitespace('a'));
285+
assert!(!is_whitespace('_'));
286+
assert!(!is_whitespace('\u0000'));
287287
}
288288

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

302-
fail_unless!(to_digit(' ', 10u).is_none());
303-
fail_unless!(to_digit('$', 36u).is_none());
302+
assert!(to_digit(' ', 10u).is_none());
303+
assert!(to_digit('$', 36u).is_none());
304304
}
305305

306306
#[test]
307307
fn test_is_ascii() {
308-
fail_unless!(str::all(~"banana", is_ascii));
309-
fail_unless!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
308+
assert!(str::all(~"banana", is_ascii));
309+
assert!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
310310
}
311311
312312
#[test]
313313
fn test_is_digit() {
314-
fail_unless!(is_digit('2'));
315-
fail_unless!(is_digit('7'));
316-
fail_unless!(! is_digit('c'));
317-
fail_unless!(! is_digit('i'));
318-
fail_unless!(! is_digit('z'));
319-
fail_unless!(! is_digit('Q'));
314+
assert!(is_digit('2'));
315+
assert!(is_digit('7'));
316+
assert!(! is_digit('c'));
317+
assert!(! is_digit('i'));
318+
assert!(! is_digit('z'));
319+
assert!(! is_digit('Q'));
320320
}
321321
322322
#[test]

src/libcore/cmp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ mod test {
177177

178178
#[test]
179179
fn test_int_totaleq() {
180-
fail_unless!(5.equals(&5));
181-
fail_unless!(!2.equals(&17));
180+
assert!(5.equals(&5));
181+
assert!(!2.equals(&17));
182182
}
183183
}

src/libcore/comm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,6 @@ pub mod test {
465465
let _chan = chan;
466466
}
467467

468-
fail_unless!(!port.peek());
468+
assert!(!port.peek());
469469
}
470470
}

0 commit comments

Comments
 (0)