From bbfa5a43bc65bb86b45ccaf2e3f8f6e5888e7654 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 30 Aug 2016 18:26:42 -0400 Subject: [PATCH] add regression test for #31 --- tests/generator.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/generator.rs b/tests/generator.rs index 042eb0a..7884b9b 100644 --- a/tests/generator.rs +++ b/tests/generator.rs @@ -1,5 +1,6 @@ // This file is part of libfringe, a low-level green threading library. -// Copyright (c) whitequark +// Copyright (c) whitequark , +// edef // Licensed under the Apache License, Version 2.0, or the MIT license , 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(()); +}