|
0 |
Avoid tests creating log files in the crate directory.
|
|
1 |
|
|
2 |
for the main test this is done by using the tempfile crate to create a temporary directory.
|
|
3 |
|
|
4 |
a couple of documentation examples are also marked as no-run to stop them running as doctests
|
|
5 |
and creating log files.
|
|
6 |
|
|
7 |
Index: simplelog/Cargo.toml
|
|
8 |
===================================================================
|
|
9 |
--- simplelog.orig/Cargo.toml
|
|
10 |
+++ simplelog/Cargo.toml
|
|
11 |
@@ -53,6 +53,9 @@ features = [
|
|
12 |
"macros",
|
|
13 |
]
|
|
14 |
|
|
15 |
+[dev-dependencies.tempfile]
|
|
16 |
+version = "3"
|
|
17 |
+
|
|
18 |
[features]
|
|
19 |
default = [
|
|
20 |
"termcolor",
|
|
21 |
Index: simplelog/src/lib.rs
|
|
22 |
===================================================================
|
|
23 |
--- simplelog.orig/src/lib.rs
|
|
24 |
+++ simplelog/src/lib.rs
|
|
25 |
@@ -101,7 +101,7 @@ mod tests {
|
|
26 |
#[test]
|
|
27 |
fn test() {
|
|
28 |
let mut i = 0;
|
|
29 |
-
|
|
30 |
+ let tempdir = tempfile::tempdir().unwrap();
|
|
31 |
CombinedLogger::init({
|
|
32 |
let mut vec = Vec::new();
|
|
33 |
let mut conf_builder = ConfigBuilder::new();
|
|
34 |
@@ -115,7 +115,7 @@ mod tests {
|
|
35 |
vec.push(WriteLogger::new(
|
|
36 |
LevelFilter::Error,
|
|
37 |
conf_thread_name,
|
|
38 |
- File::create("thread_naming.log").unwrap(),
|
|
39 |
+ File::create(tempdir.path().join("thread_naming.log")).unwrap(),
|
|
40 |
) as Box<dyn SharedLogger>);
|
|
41 |
|
|
42 |
for elem in vec![
|
|
43 |
@@ -148,7 +148,7 @@ mod tests {
|
|
44 |
vec.push(WriteLogger::new(
|
|
45 |
LevelFilter::Error,
|
|
46 |
conf.clone(),
|
|
47 |
- File::create(&format!("error_{}.log", i)).unwrap(),
|
|
48 |
+ File::create(tempdir.path().join(&format!("error_{}.log", i))).unwrap(),
|
|
49 |
) as Box<dyn SharedLogger>);
|
|
50 |
#[cfg(feature = "test")]
|
|
51 |
vec.push(TestLogger::new(LevelFilter::Error, conf.clone()));
|
|
52 |
@@ -167,7 +167,7 @@ mod tests {
|
|
53 |
vec.push(WriteLogger::new(
|
|
54 |
LevelFilter::Warn,
|
|
55 |
conf.clone(),
|
|
56 |
- File::create(&format!("warn_{}.log", i)).unwrap(),
|
|
57 |
+ File::create(tempdir.path().join(&format!("warn_{}.log", i))).unwrap(),
|
|
58 |
) as Box<dyn SharedLogger>);
|
|
59 |
#[cfg(feature = "test")]
|
|
60 |
vec.push(TestLogger::new(LevelFilter::Warn, conf.clone()));
|
|
61 |
@@ -186,7 +186,7 @@ mod tests {
|
|
62 |
vec.push(WriteLogger::new(
|
|
63 |
LevelFilter::Info,
|
|
64 |
conf.clone(),
|
|
65 |
- File::create(&format!("info_{}.log", i)).unwrap(),
|
|
66 |
+ File::create(tempdir.path().join(&format!("info_{}.log", i))).unwrap(),
|
|
67 |
) as Box<dyn SharedLogger>);
|
|
68 |
#[cfg(feature = "test")]
|
|
69 |
vec.push(TestLogger::new(LevelFilter::Info, conf.clone()));
|
|
70 |
@@ -205,7 +205,7 @@ mod tests {
|
|
71 |
vec.push(WriteLogger::new(
|
|
72 |
LevelFilter::Debug,
|
|
73 |
conf.clone(),
|
|
74 |
- File::create(&format!("debug_{}.log", i)).unwrap(),
|
|
75 |
+ File::create(tempdir.path().join(&format!("debug_{}.log", i))).unwrap(),
|
|
76 |
) as Box<dyn SharedLogger>);
|
|
77 |
#[cfg(feature = "test")]
|
|
78 |
vec.push(TestLogger::new(LevelFilter::Debug, conf.clone()));
|
|
79 |
@@ -224,7 +224,7 @@ mod tests {
|
|
80 |
vec.push(WriteLogger::new(
|
|
81 |
LevelFilter::Trace,
|
|
82 |
conf.clone(),
|
|
83 |
- File::create(&format!("trace_{}.log", i)).unwrap(),
|
|
84 |
+ File::create(tempdir.path().join(&format!("trace_{}.log", i))).unwrap(),
|
|
85 |
) as Box<dyn SharedLogger>);
|
|
86 |
#[cfg(feature = "test")]
|
|
87 |
vec.push(TestLogger::new(LevelFilter::Trace, conf.clone()));
|
|
88 |
@@ -241,7 +241,7 @@ mod tests {
|
|
89 |
trace!("Test Trace");
|
|
90 |
|
|
91 |
let mut thread_naming = String::new();
|
|
92 |
- File::open("thread_naming.log")
|
|
93 |
+ File::open(tempdir.path().join("thread_naming.log"))
|
|
94 |
.unwrap()
|
|
95 |
.read_to_string(&mut thread_naming)
|
|
96 |
.unwrap();
|
|
97 |
@@ -252,27 +252,27 @@ mod tests {
|
|
98 |
|
|
99 |
for j in 1..i {
|
|
100 |
let mut error = String::new();
|
|
101 |
- File::open(&format!("error_{}.log", j))
|
|
102 |
+ File::open(tempdir.path().join(&format!("error_{}.log", j)))
|
|
103 |
.unwrap()
|
|
104 |
.read_to_string(&mut error)
|
|
105 |
.unwrap();
|
|
106 |
let mut warn = String::new();
|
|
107 |
- File::open(&format!("warn_{}.log", j))
|
|
108 |
+ File::open(tempdir.path().join(&format!("warn_{}.log", j)))
|
|
109 |
.unwrap()
|
|
110 |
.read_to_string(&mut warn)
|
|
111 |
.unwrap();
|
|
112 |
let mut info = String::new();
|
|
113 |
- File::open(&format!("info_{}.log", j))
|
|
114 |
+ File::open(tempdir.path().join(&format!("info_{}.log", j)))
|
|
115 |
.unwrap()
|
|
116 |
.read_to_string(&mut info)
|
|
117 |
.unwrap();
|
|
118 |
let mut debug = String::new();
|
|
119 |
- File::open(&format!("debug_{}.log", j))
|
|
120 |
+ File::open(tempdir.path().join(&format!("debug_{}.log", j)))
|
|
121 |
.unwrap()
|
|
122 |
.read_to_string(&mut debug)
|
|
123 |
.unwrap();
|
|
124 |
let mut trace = String::new();
|
|
125 |
- File::open(&format!("trace_{}.log", j))
|
|
126 |
+ File::open(tempdir.path().join(&format!("trace_{}.log", j)))
|
|
127 |
.unwrap()
|
|
128 |
.read_to_string(&mut trace)
|
|
129 |
.unwrap();
|
|
130 |
Index: simplelog/src/loggers/comblog.rs
|
|
131 |
===================================================================
|
|
132 |
--- simplelog.orig/src/loggers/comblog.rs
|
|
133 |
+++ simplelog/src/loggers/comblog.rs
|
|
134 |
@@ -29,7 +29,7 @@ impl CombinedLogger {
|
|
135 |
/// Fails if another logger is already set globally.
|
|
136 |
///
|
|
137 |
/// # Examples
|
|
138 |
- /// ```
|
|
139 |
+ /// ``` no-run
|
|
140 |
/// # extern crate simplelog;
|
|
141 |
/// # use simplelog::*;
|
|
142 |
/// # use std::fs::File;
|
|
143 |
@@ -60,7 +60,7 @@ impl CombinedLogger {
|
|
144 |
/// All loggers need to implement log::Log.
|
|
145 |
///
|
|
146 |
/// # Examples
|
|
147 |
- /// ```
|
|
148 |
+ /// ``` no-run
|
|
149 |
/// # extern crate simplelog;
|
|
150 |
/// # use simplelog::*;
|
|
151 |
/// # use std::fs::File;
|
|
152 |
Index: simplelog/src/loggers/writelog.rs
|
|
153 |
===================================================================
|
|
154 |
--- simplelog.orig/src/loggers/writelog.rs
|
|
155 |
+++ simplelog/src/loggers/writelog.rs
|
|
156 |
@@ -27,7 +27,7 @@ impl<W: Write + Send + 'static> WriteLog
|
|
157 |
/// Fails if another Logger was already initialized.
|
|
158 |
///
|
|
159 |
/// # Examples
|
|
160 |
- /// ```
|
|
161 |
+ /// ``` no-run
|
|
162 |
/// # extern crate simplelog;
|
|
163 |
/// # use simplelog::*;
|
|
164 |
/// # use std::fs::File;
|
|
165 |
@@ -48,7 +48,7 @@ impl<W: Write + Send + 'static> WriteLog
|
|
166 |
/// Takes the desired `Level`, `Config` and `Write` struct as arguments. They cannot be changed later on.
|
|
167 |
///
|
|
168 |
/// # Examples
|
|
169 |
- /// ```
|
|
170 |
+ /// ``` no-run
|
|
171 |
/// # extern crate simplelog;
|
|
172 |
/// # use simplelog::*;
|
|
173 |
/// # use std::fs::File;
|