proptest/test_runner/failure_persistence/
noop.rs

1//-
2// Copyright 2017, 2018 The proptest developers
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use crate::std_facade::{fmt, Box, Vec};
11use core::any::Any;
12
13use crate::test_runner::failure_persistence::{
14    FailurePersistence, PersistedSeed,
15};
16
17/// Failure persistence option that loads and saves nothing at all.
18#[derive(Debug, Default, PartialEq)]
19struct NoopFailurePersistence;
20
21impl FailurePersistence for NoopFailurePersistence {
22    fn load_persisted_failures2(
23        &self,
24        _source_file: Option<&'static str>,
25    ) -> Vec<PersistedSeed> {
26        Vec::new()
27    }
28
29    fn save_persisted_failure2(
30        &mut self,
31        _source_file: Option<&'static str>,
32        _seed: PersistedSeed,
33        _shrunken_value: &dyn fmt::Debug,
34    ) {
35    }
36
37    fn box_clone(&self) -> Box<dyn FailurePersistence> {
38        Box::new(NoopFailurePersistence)
39    }
40
41    fn eq(&self, other: &dyn FailurePersistence) -> bool {
42        other
43            .as_any()
44            .downcast_ref::<Self>()
45            .map_or(false, |x| x == self)
46    }
47
48    fn as_any(&self) -> &dyn Any {
49        self
50    }
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56    use crate::test_runner::failure_persistence::tests::*;
57
58    #[test]
59    fn default_load_is_empty() {
60        assert!(NoopFailurePersistence::default()
61            .load_persisted_failures2(None)
62            .is_empty());
63        assert!(NoopFailurePersistence::default()
64            .load_persisted_failures2(HI_PATH)
65            .is_empty());
66    }
67
68    #[test]
69    fn seeds_not_recoverable() {
70        let mut p = NoopFailurePersistence::default();
71        p.save_persisted_failure2(HI_PATH, INC_SEED, &"");
72        assert!(p.load_persisted_failures2(HI_PATH).is_empty());
73        assert!(p.load_persisted_failures2(None).is_empty());
74        assert!(p.load_persisted_failures2(UNREL_PATH).is_empty());
75    }
76}