1
0
Fork 0

add regression test for #31

This commit is contained in:
edef 2016-08-30 18:26:42 -04:00
parent 1994ffee27
commit bbfa5a43bc
1 changed files with 28 additions and 1 deletions

View File

@ -1,5 +1,6 @@
// This file is part of libfringe, a low-level green threading library.
// Copyright (c) whitequark <whitequark@whitequark.org>
// Copyright (c) whitequark <whitequark@whitequark.org>,
// edef <edef@edef.eu>
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
@ -81,3 +82,29 @@ fn with_owned_stack() {
assert_eq!(add_one.resume(1), Some(2));
assert_eq!(add_one.resume(2), Some(3));
}
#[test]
fn forget_yielded() {
struct Dropper(*mut bool);
unsafe impl Send for Dropper {}
impl Drop for Dropper {
fn drop(&mut self) {
unsafe {
if *self.0 {
panic!("double drop!")
}
*self.0 = true;
}
}
}
let stack = fringe::OsStack::new(1<<16).unwrap();
let mut generator = Generator::new(stack, |yielder, ()| {
let mut flag = false;
yielder.suspend(Dropper(&mut flag as *mut bool));
});
generator.resume(());
generator.resume(());
}