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 11use std:: boxed:: Box ;
22use std:: cell:: RefCell ;
3- use std:: collections:: HashMap ;
43use std:: default:: Default ;
54use std:: fmt:: Debug ;
6- use std:: io:: Cursor ;
75use std:: panic;
8- use std:: path:: { Path , PathBuf } ;
6+ use std:: path:: PathBuf ;
97use 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+ } ;
1115
1216use home:: env as home;
17+ #[ cfg( feature = "test" ) ]
1318use rand:: { thread_rng, Rng } ;
1419
1520pub ( crate ) mod argsource;
@@ -204,7 +209,7 @@ impl ProcessSource for OSProcess {
204209}
205210
206211// ------------ test process ----------------
207-
212+ # [ cfg ( feature = "test" ) ]
208213#[ derive( Clone , Debug , Default ) ]
209214pub struct TestProcess {
210215 pub cwd : PathBuf ,
@@ -216,6 +221,7 @@ pub struct TestProcess {
216221 pub stderr : TestWriterInner ,
217222}
218223
224+ #[ cfg( feature = "test" ) ]
219225impl TestProcess {
220226 pub fn new < P : AsRef < Path > , A : AsRef < str > > (
221227 cwd : P ,
@@ -257,6 +263,7 @@ impl TestProcess {
257263 }
258264}
259265
266+ #[ cfg( feature = "test" ) ]
260267impl ProcessSource for TestProcess {
261268 fn id ( & self ) -> u64 {
262269 self . id
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ impl<T: From<String>> Iterator for VecArgs<T> {
5252 }
5353}
5454
55+ #[ cfg( feature = "test" ) ]
5556impl ArgSource for super :: TestProcess {
5657 fn args ( & self ) -> Box < dyn Iterator < Item = String > > {
5758 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 {
1515 }
1616}
1717
18+ #[ cfg( feature = "test" ) ]
1819impl CurrentDirSource for super :: TestProcess {
1920 fn current_dir ( & self ) -> io:: Result < PathBuf > {
2021 Ok ( self . cwd . clone ( ) )
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ impl Stdin for TestStdin {
7373 }
7474}
7575
76+ #[ cfg( feature = "test" ) ]
7677impl StdinSource for super :: TestProcess {
7778 fn stdin ( & self ) -> Box < dyn Stdin > {
7879 Box :: new ( TestStdin ( self . stdin . clone ( ) ) )
@@ -193,12 +194,14 @@ impl Isatty for TestWriter {
193194 }
194195}
195196
197+ #[ cfg( feature = "test" ) ]
196198impl StdoutSource for super :: TestProcess {
197199 fn stdout ( & self ) -> Box < dyn Writer > {
198200 Box :: new ( TestWriter ( self . stdout . clone ( ) ) )
199201 }
200202}
201203
204+ #[ cfg( feature = "test" ) ]
202205impl StderrSource for super :: TestProcess {
203206 fn stderr ( & self ) -> Box < dyn Writer > {
204207 Box :: new ( TestWriter ( self . stderr . clone ( ) ) )
Original file line number Diff line number Diff line change 11/// Adapts currentprocess to the trait home::Env
22use std:: ffi:: OsString ;
33use std:: io;
4+ #[ cfg( feature = "test" ) ]
45use std:: ops:: Deref ;
56use std:: path:: PathBuf ;
67
78use home:: env as home;
89
9- use super :: CurrentDirSource ;
1010use super :: HomeProcess ;
1111use super :: OSProcess ;
12- use super :: TestProcess ;
13- use super :: VarSource ;
12+ # [ cfg ( feature = "test" ) ]
13+ use super :: { CurrentDirSource , TestProcess , VarSource } ;
1414
1515impl home:: Env for Box < dyn HomeProcess + ' static > {
1616 fn home_dir ( & self ) -> Option < PathBuf > {
@@ -24,6 +24,7 @@ impl home::Env for Box<dyn HomeProcess + 'static> {
2424 }
2525}
2626
27+ #[ cfg( feature = "test" ) ]
2728impl home:: Env for TestProcess {
2829 fn home_dir ( & self ) -> Option < PathBuf > {
2930 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 {
2020 }
2121}
2222
23+ #[ cfg( feature = "test" ) ]
2324impl VarSource for super :: TestProcess {
2425 fn var ( & self , key : & str ) -> std:: result:: Result < String , env:: VarError > {
2526 match self . var_os ( key) {
You can’t perform that action at this time.
0 commit comments