File tree Expand file tree Collapse file tree 6 files changed +22
-8
lines changed Expand file tree Collapse file tree 6 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 1
1
use std:: boxed:: Box ;
2
2
use std:: cell:: RefCell ;
3
- use std:: collections:: HashMap ;
4
3
use std:: default:: Default ;
5
4
use std:: fmt:: Debug ;
6
- use std:: io:: Cursor ;
7
5
use std:: panic;
8
- use std:: path:: { Path , PathBuf } ;
6
+ use std:: path:: PathBuf ;
9
7
use std:: sync:: Once ;
10
- use std:: sync:: { Arc , Mutex } ;
8
+ #[ cfg( feature = "test" ) ]
9
+ use std:: {
10
+ collections:: HashMap ,
11
+ io:: Cursor ,
12
+ path:: Path ,
13
+ sync:: { Arc , Mutex } ,
14
+ } ;
11
15
12
16
use home:: env as home;
17
+ #[ cfg( feature = "test" ) ]
13
18
use rand:: { thread_rng, Rng } ;
14
19
15
20
pub ( crate ) mod argsource;
@@ -204,7 +209,7 @@ impl ProcessSource for OSProcess {
204
209
}
205
210
206
211
// ------------ test process ----------------
207
-
212
+ # [ cfg ( feature = "test" ) ]
208
213
#[ derive( Clone , Debug , Default ) ]
209
214
pub struct TestProcess {
210
215
pub cwd : PathBuf ,
@@ -216,6 +221,7 @@ pub struct TestProcess {
216
221
pub stderr : TestWriterInner ,
217
222
}
218
223
224
+ #[ cfg( feature = "test" ) ]
219
225
impl TestProcess {
220
226
pub fn new < P : AsRef < Path > , A : AsRef < str > > (
221
227
cwd : P ,
@@ -257,6 +263,7 @@ impl TestProcess {
257
263
}
258
264
}
259
265
266
+ #[ cfg( feature = "test" ) ]
260
267
impl ProcessSource for TestProcess {
261
268
fn id ( & self ) -> u64 {
262
269
self . id
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ impl<T: From<String>> Iterator for VecArgs<T> {
52
52
}
53
53
}
54
54
55
+ #[ cfg( feature = "test" ) ]
55
56
impl ArgSource for super :: TestProcess {
56
57
fn args ( & self ) -> Box < dyn Iterator < Item = String > > {
57
58
Box :: new ( VecArgs :: < String > :: from ( & self . args ) )
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ impl CurrentDirSource for super::OSProcess {
15
15
}
16
16
}
17
17
18
+ #[ cfg( feature = "test" ) ]
18
19
impl CurrentDirSource for super :: TestProcess {
19
20
fn current_dir ( & self ) -> io:: Result < PathBuf > {
20
21
Ok ( self . cwd . clone ( ) )
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ impl Stdin for TestStdin {
73
73
}
74
74
}
75
75
76
+ #[ cfg( feature = "test" ) ]
76
77
impl StdinSource for super :: TestProcess {
77
78
fn stdin ( & self ) -> Box < dyn Stdin > {
78
79
Box :: new ( TestStdin ( self . stdin . clone ( ) ) )
@@ -193,12 +194,14 @@ impl Isatty for TestWriter {
193
194
}
194
195
}
195
196
197
+ #[ cfg( feature = "test" ) ]
196
198
impl StdoutSource for super :: TestProcess {
197
199
fn stdout ( & self ) -> Box < dyn Writer > {
198
200
Box :: new ( TestWriter ( self . stdout . clone ( ) ) )
199
201
}
200
202
}
201
203
204
+ #[ cfg( feature = "test" ) ]
202
205
impl StderrSource for super :: TestProcess {
203
206
fn stderr ( & self ) -> Box < dyn Writer > {
204
207
Box :: new ( TestWriter ( self . stderr . clone ( ) ) )
Original file line number Diff line number Diff line change 1
1
/// Adapts currentprocess to the trait home::Env
2
2
use std:: ffi:: OsString ;
3
3
use std:: io;
4
+ #[ cfg( feature = "test" ) ]
4
5
use std:: ops:: Deref ;
5
6
use std:: path:: PathBuf ;
6
7
7
8
use home:: env as home;
8
9
9
- use super :: CurrentDirSource ;
10
10
use super :: HomeProcess ;
11
11
use super :: OSProcess ;
12
- use super :: TestProcess ;
13
- use super :: VarSource ;
12
+ # [ cfg ( feature = "test" ) ]
13
+ use super :: { CurrentDirSource , TestProcess , VarSource } ;
14
14
15
15
impl home:: Env for Box < dyn HomeProcess + ' static > {
16
16
fn home_dir ( & self ) -> Option < PathBuf > {
@@ -24,6 +24,7 @@ impl home::Env for Box<dyn HomeProcess + 'static> {
24
24
}
25
25
}
26
26
27
+ #[ cfg( feature = "test" ) ]
27
28
impl home:: Env for TestProcess {
28
29
fn home_dir ( & self ) -> Option < PathBuf > {
29
30
self . var ( "HOME" ) . ok ( ) . map ( |v| v. into ( ) )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ impl VarSource for super::OSProcess {
20
20
}
21
21
}
22
22
23
+ #[ cfg( feature = "test" ) ]
23
24
impl VarSource for super :: TestProcess {
24
25
fn var ( & self , key : & str ) -> std:: result:: Result < String , env:: VarError > {
25
26
match self . var_os ( key) {
You can’t perform that action at this time.
0 commit comments