Repository: plotters-rs/plotters (language: rust)

Issue:
[BUG] Some assertion failure make the entire test process abort
**Describe the bug**
Some tests utilizing `MockedBackend::drop_check` make the entire test process *abort*, even though one of them just *fail*. Here is a `cargo test`'s output when this happens:

```
PS C:\Users\shinmili\source\repos\plotters> cargo test
   Compiling plotters v0.3.3 (C:\Users\shinmili\source\repos\plotters\plotters)
    Finished test [unoptimized + debuginfo] target(s) in 16.60s
     Running unittests src\lib.rs (target\debug\deps\plotters-f2a6e518f0c7ca43.exe)

running 70 tests
test coord::ranged1d::combinators::partial_axis::test::test_make_partial_axis ... ok
test coord::ranged1d::combinators::group_by::test::test_group_by ... ok
test coord::ranged1d::combinators::logarithmic::test::regression_test_issue_143 ... ok

(...snip...)

test drawing::area::drawing_area_tests::test_titled ... ok
test chart::context::test::test_chart_context_3d ... ok
test chart::context::test::test_chart_context ... ok
thread panicked while panicking. aborting.
error: test failed, to rerun pass '--lib'

Caused by:
  process didn't exit successfully: `C:\Users\shinmili\source\repos\plotters\target\debug\deps\plotters-f2a6e518f0c7ca43.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
```

The "panic while panicking" is caused by assertions in `drop_check`'s arguments. When an assertion (different from the one in `drop_check`) fails, the test thread panics, and stack unwinding calls `MockedBackend::drop`, which calls tester-defined drop-time assertions. When these assertions also fail because of the suspended execution, that leads to "panic while panicking."

**To Reproduce**
Taking `test_split_evenly` test as an example, change the test as follows (simulating the changed code make the test fail):

```diff  
diff --git a/plotters/src/drawing/area.rs b/plotters/src/drawing/area.rs
index 2e5c3fe..ebbb98f 100644
--- a/plotters/src/drawing/area.rs
+++ b/plotters/src/drawing/area.rs
@@ -575,7 +575,7 @@ mod drawing_area_tests {
                     let colors = colors.clone();
                     m.check_draw_rect(move |c, _, f, u, d| {
                         assert_eq!(c, colors[col * 3 + row].to_rgba());
-                        assert_eq!(f, true);
+                        assert_eq!(f, false);
                         assert_eq!(u, (300 * row as i32 + 2.min(row) as i32, 300 * col as i32));
                         assert_eq!(
                             d,
```

This modification will make `cargo test` print the error above.

**Version Information**
The latest master 714a59acd78c675ac63f22dec247a9d2ec3abc01



Discussion / hints:

Fix patch:
diff --git a/plotters/src/drawing/backend_impl/mocked.rs b/plotters/src/drawing/backend_impl/mocked.rs
index da6bfecc..7569e732 100644
--- a/plotters/src/drawing/backend_impl/mocked.rs
+++ b/plotters/src/drawing/backend_impl/mocked.rs
@@ -269,6 +269,13 @@ impl DrawingBackend for MockedBackend {
 
 impl Drop for MockedBackend {
     fn drop(&mut self) {
+        // `self.drop_check` is typically a testing function; it can panic.
+        // The current `drop` call may be a part of stack unwinding caused
+        // by another panic. If so, we should never call it.
+        if std::thread::panicking() {
+            return;
+        }
+
         let mut temp = None;
         std::mem::swap(&mut temp, &mut self.drop_check);
 


Test patch: