Initial test that the compiler runs destructors in the right order.
This commit is contained in:
parent
765a2b3ecf
commit
7dd464fdb5
29
src/test/run-pass/destructor-ordering.rs
Normal file
29
src/test/run-pass/destructor-ordering.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// We share an instance of this type among all the destructor-order
|
||||
// checkers. It tracks how many destructors have run so far and
|
||||
// 'fail's when one runs out of order.
|
||||
// FIXME: Make it easier to collect a failure message.
|
||||
state obj order_tracker(mutable int init) {
|
||||
fn assert_order(int expected, str fail_message) {
|
||||
if (expected != init) {
|
||||
log expected;
|
||||
log " != ";
|
||||
log init;
|
||||
log fail_message;
|
||||
fail;
|
||||
}
|
||||
init += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
obj dorder(@order_tracker tracker, int order, str message) {
|
||||
drop {
|
||||
tracker.assert_order(order, message);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
auto tracker = @order_tracker(0);
|
||||
dorder(tracker, 1, "Reverse decl order");
|
||||
dorder(tracker, 0, "Reverse decl order");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user