]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/debug-assertions/debug.rs
a0ccc75afd05b5c6ea9f0029dc69049abd7d444c
[rust.git] / src / test / run-make / debug-assertions / debug.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![deny(warnings)]
12
13 use std::env;
14 use std::thread;
15
16 fn main() {
17     let should_fail = env::args().nth(1) == Some("bad".to_string());
18
19     assert_eq!(thread::spawn(debug_assert_eq).join().is_err(), should_fail);
20     assert_eq!(thread::spawn(debug_assert).join().is_err(), should_fail);
21     assert_eq!(thread::spawn(overflow).join().is_err(), should_fail);
22 }
23
24 fn debug_assert_eq() {
25     let mut hit1 = false;
26     let mut hit2 = false;
27     debug_assert_eq!({ hit1 = true; 1 }, { hit2 = true; 2 });
28     assert!(!hit1);
29     assert!(!hit2);
30 }
31
32 fn debug_assert() {
33     let mut hit = false;
34     debug_assert!({ hit = true; false });
35     assert!(!hit);
36 }
37
38 fn overflow() {
39     fn add(a: u8, b: u8) -> u8 { a + b }
40
41     add(200u8, 200u8);
42 }