libsyntax: Implement assert
as a macro (called fail_unless!
on a transitionary basis to avoid conflicting with the keyword right now). r=brson
This commit is contained in:
parent
54b2cad8b3
commit
154488df19
3 changed files with 31 additions and 12 deletions
|
@ -300,6 +300,14 @@ fn core_macros() -> ~str {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
macro_rules! fail_unless(
|
||||||
|
($cond:expr) => {
|
||||||
|
if !$cond {
|
||||||
|
die!(~\"assertion failed: \" + stringify!($cond))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
macro_rules! condition (
|
macro_rules! condition (
|
||||||
|
|
||||||
{ $c:ident: $in:ty -> $out:ty; } => {
|
{ $c:ident: $in:ty -> $out:ty; } => {
|
||||||
|
|
|
@ -200,19 +200,24 @@ fn to_str(in: @ident_interner, t: Token) -> ~str {
|
||||||
DOC_COMMENT(s) => *in.get(s),
|
DOC_COMMENT(s) => *in.get(s),
|
||||||
EOF => ~"<eof>",
|
EOF => ~"<eof>",
|
||||||
INTERPOLATED(ref nt) => {
|
INTERPOLATED(ref nt) => {
|
||||||
~"an interpolated " +
|
match nt {
|
||||||
match (*nt) {
|
&nt_expr(e) => ::print::pprust::expr_to_str(e, in),
|
||||||
nt_item(*) => ~"item",
|
_ => {
|
||||||
nt_block(*) => ~"block",
|
~"an interpolated " +
|
||||||
nt_stmt(*) => ~"statement",
|
match (*nt) {
|
||||||
nt_pat(*) => ~"pattern",
|
nt_item(*) => ~"item",
|
||||||
nt_expr(*) => ~"expression",
|
nt_block(*) => ~"block",
|
||||||
nt_ty(*) => ~"type",
|
nt_stmt(*) => ~"statement",
|
||||||
nt_ident(*) => ~"identifier",
|
nt_pat(*) => ~"pattern",
|
||||||
nt_path(*) => ~"path",
|
nt_expr(*) => fail ~"should have been handled above",
|
||||||
nt_tt(*) => ~"tt",
|
nt_ty(*) => ~"type",
|
||||||
nt_matchers(*) => ~"matcher sequence"
|
nt_ident(*) => ~"identifier",
|
||||||
|
nt_path(*) => ~"path",
|
||||||
|
nt_tt(*) => ~"tt",
|
||||||
|
nt_matchers(*) => ~"matcher sequence"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
src/test/run-fail/assert-as-macro.rs
Normal file
6
src/test/run-fail/assert-as-macro.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// error-pattern:assertion failed: 1 == 2
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
fail_unless!(1 == 2);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue