File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -40,3 +40,39 @@ macro_rules! rtabort(
40
40
} )
41
41
)
42
42
43
+ macro_rules! assert_once_ever(
44
+ ( $( $msg: expr) ,+) => ( {
45
+ // FIXME(#8472) extra function should not be needed to hide unsafe
46
+ fn assert_once_ever( ) {
47
+ unsafe {
48
+ static mut already_happened: int = 0 ;
49
+ // Double-check lock to avoid a swap in the common case.
50
+ if already_happened != 0 ||
51
+ :: unstable:: intrinsics:: atomic_xchg_relaxed( & mut already_happened, 1 ) != 0 {
52
+ fail!( fmt!( "assert_once_ever happened twice: %s" , fmt!( $( $msg) ,+) ) ) ;
53
+ }
54
+ }
55
+ }
56
+ assert_once_ever( ) ;
57
+ } )
58
+ )
59
+
60
+ #[ cfg( test) ]
61
+ mod tests {
62
+ #[ test]
63
+ fn test_assert_once_ever_ok ( ) {
64
+ assert_once_ever ! ( "help i'm stuck in an" ) ;
65
+ assert_once_ever ! ( "assertion error message" ) ;
66
+ }
67
+
68
+ #[ test] #[ ignore( cfg( windows) ) ] #[ should_fail]
69
+ fn test_assert_once_ever_fail ( ) {
70
+ use task;
71
+
72
+ fn f ( ) { assert_once_ever ! ( "if you're seeing this... good!" ) }
73
+
74
+ // linked & watched, naturally
75
+ task:: spawn ( f) ;
76
+ task:: spawn ( f) ;
77
+ }
78
+ }
Original file line number Diff line number Diff line change @@ -323,6 +323,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
323
323
// task tree, shut down the schedulers and set the exit code.
324
324
let handles = Cell :: new ( handles) ;
325
325
let on_exit: ~fn ( bool ) = |exit_success| {
326
+ assert_once_ever ! ( "last task exiting" ) ;
326
327
327
328
let mut handles = handles. take ( ) ;
328
329
for handle in handles. mut_iter ( ) {
You can’t perform that action at this time.
0 commit comments