File tree 3 files changed +53
-5
lines changed
3 files changed +53
-5
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " assert_fs"
3
- version = " 0.11.3 "
3
+ version = " 0.12.0 "
4
4
authors = [
" Ed Page <[email protected] >" ]
5
5
description = " Filesystem fixtures and assertions for testing."
6
6
license = " MIT OR Apache-2.0"
Original file line number Diff line number Diff line change @@ -96,21 +96,45 @@ impl TempDir {
96
96
97
97
/// Conditionally persist the temporary directory for debug purposes.
98
98
///
99
+ /// Note: this operation is not reversible, i.e. `into_persist_if(false)` is a no-op.
100
+ ///
99
101
/// # Examples
100
102
///
101
103
/// ```no_run
102
104
/// use assert_fs::fixture::TempDir;
103
105
///
104
- /// let tmp_dir = TempDir::new().unwrap().persist_if(true);
106
+ /// let tmp_dir = TempDir::new()
107
+ /// .unwrap()
108
+ /// .into_persist_if(std::env::var_os("TEST_PERSIST_FILES").is_some());
105
109
///
106
110
/// // Ensure deletion happens.
107
111
/// tmp_dir.close().unwrap();
108
112
/// ```
109
- pub fn persist_if ( self , yes : bool ) -> Self {
113
+ pub fn into_persist_if ( self , yes : bool ) -> Self {
110
114
if !yes {
111
115
return self ;
112
116
}
113
117
118
+ self . into_persist ( )
119
+ }
120
+
121
+ /// Persist the temporary directory for debug purposes.
122
+ ///
123
+ /// Note: this operation is not reversible, i.e. `into_persist_if(false)` is a no-op.
124
+ ///
125
+ /// # Examples
126
+ ///
127
+ /// ```no_run
128
+ /// use assert_fs::fixture::TempDir;
129
+ ///
130
+ /// let tmp_dir = TempDir::new()
131
+ /// .unwrap()
132
+ /// .into_persist();
133
+ ///
134
+ /// // Ensure deletion happens.
135
+ /// tmp_dir.close().unwrap();
136
+ /// ```
137
+ pub fn into_persist ( self ) -> Self {
114
138
let path = match self . temp {
115
139
Inner :: Temp ( temp) => temp. into_path ( ) ,
116
140
Inner :: Persisted ( path) => path,
Original file line number Diff line number Diff line change @@ -101,21 +101,45 @@ impl NamedTempFile {
101
101
102
102
/// Conditionally persist the temporary file for debug purposes.
103
103
///
104
+ /// Note: this operation is not reversible, i.e. `into_persist_if(false)` is a no-op.
105
+ ///
104
106
/// # Examples
105
107
///
106
108
/// ```no_run
107
109
/// use assert_fs::fixture::NamedTempFile;
108
110
///
109
- /// let tmp_file = NamedTempFile::new("foo.rs").unwrap().persist_if(true);
111
+ /// let tmp_file = NamedTempFile::new("foo.rs")
112
+ /// .unwrap()
113
+ /// .into_persist_if(std::env::var_os("TEST_PERSIST_FILES").is_some());
110
114
///
111
115
/// // Ensure deletion happens.
112
116
/// tmp_file.close().unwrap();
113
117
/// ```
114
- pub fn persist_if ( mut self , yes : bool ) -> Self {
118
+ pub fn into_persist_if ( self , yes : bool ) -> Self {
115
119
if !yes {
116
120
return self ;
117
121
}
118
122
123
+ self . into_persist ( )
124
+ }
125
+
126
+ /// Persist the temporary file for debug purposes.
127
+ ///
128
+ /// Note: this operation is not reversible, i.e. `into_persist_if(false)` is a no-op.
129
+ ///
130
+ /// # Examples
131
+ ///
132
+ /// ```no_run
133
+ /// use assert_fs::fixture::NamedTempFile;
134
+ ///
135
+ /// let tmp_file = NamedTempFile::new("foo.rs")
136
+ /// .unwrap()
137
+ /// .into_persist();
138
+ ///
139
+ /// // Ensure deletion happens.
140
+ /// tmp_file.close().unwrap();
141
+ /// ```
142
+ pub fn into_persist ( mut self ) -> Self {
119
143
let mut temp = Inner :: Persisted ;
120
144
:: std:: mem:: swap ( & mut self . temp , & mut temp) ;
121
145
if let Inner :: Temp ( temp) = temp {
You can’t perform that action at this time.
0 commit comments