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)]
19#[allow(dead_code)]
20struct NoopFailurePersistence;
21
22impl FailurePersistence for NoopFailurePersistence {
23    fn load_persisted_failures2(
24        &self,
25        _source_file: Option<&'static str>,
26    ) -> Vec<PersistedSeed> {
27        Vec::new()
28    }
29
30    fn save_persisted_failure2(
31        &mut self,
32        _source_file: Option<&'static str>,
33        _seed: PersistedSeed,
34        _shrunken_value: &dyn fmt::Debug,
35    ) {
36    }
37
38    fn box_clone(&self) -> Box<dyn FailurePersistence> {
39        Box::new(NoopFailurePersistence)
40    }
41
42    fn eq(&self, other: &dyn FailurePersistence) -> bool {
43        other
44            .as_any()
45            .downcast_ref::<Self>()
46            .map_or(false, |x| x == self)
47    }
48
49    fn as_any(&self) -> &dyn Any {
50        self
51    }
52}
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57    use crate::test_runner::failure_persistence::tests::*;
58
59    #[test]
60    fn default_load_is_empty() {
61        assert!(NoopFailurePersistence::default()
62            .load_persisted_failures2(None)
63            .is_empty());
64        assert!(NoopFailurePersistence::default()
65            .load_persisted_failures2(HI_PATH)
66            .is_empty());
67    }
68
69    #[test]
70    fn seeds_not_recoverable() {
71        let mut p = NoopFailurePersistence::default();
72        p.save_persisted_failure2(HI_PATH, INC_SEED, &"");
73        assert!(p.load_persisted_failures2(HI_PATH).is_empty());
74        assert!(p.load_persisted_failures2(None).is_empty());
75        assert!(p.load_persisted_failures2(UNREL_PATH).is_empty());
76    }
77}