1
- use std:: io:: { self , BufRead , Cursor , Read , Result , Write } ;
2
- use std:: sync:: { Arc , Mutex , MutexGuard } ;
1
+ use std:: io:: { self , BufRead , Read , Result , Write } ;
2
+ #[ cfg( feature = "test" ) ]
3
+ use std:: {
4
+ io:: Cursor ,
5
+ sync:: { Arc , Mutex , MutexGuard } ,
6
+ } ;
3
7
4
8
use enum_dispatch:: enum_dispatch;
5
9
6
- use crate :: currentprocess:: process;
7
-
8
10
use super :: terminalsource:: { ColorableTerminal , StreamSelector } ;
11
+ use crate :: currentprocess:: process;
9
12
10
13
/// Stand-in for std::io::Stdin
11
14
pub trait Stdin {
@@ -44,18 +47,22 @@ impl StdinSource for super::OSProcess {
44
47
45
48
// ----------------------- test support for stdin ------------------
46
49
50
+ #[ cfg( feature = "test" ) ]
47
51
struct TestStdinLock < ' a > {
48
52
inner : MutexGuard < ' a , Cursor < String > > ,
49
53
}
50
54
55
+ #[ cfg( feature = "test" ) ]
51
56
impl StdinLock for TestStdinLock < ' _ > { }
52
57
58
+ #[ cfg( feature = "test" ) ]
53
59
impl Read for TestStdinLock < ' _ > {
54
60
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
55
61
self . inner . read ( buf)
56
62
}
57
63
}
58
64
65
+ #[ cfg( feature = "test" ) ]
59
66
impl BufRead for TestStdinLock < ' _ > {
60
67
fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > {
61
68
self . inner . fill_buf ( )
@@ -65,10 +72,13 @@ impl BufRead for TestStdinLock<'_> {
65
72
}
66
73
}
67
74
75
+ #[ cfg( feature = "test" ) ]
68
76
pub ( crate ) type TestStdinInner = Arc < Mutex < Cursor < String > > > ;
69
77
78
+ #[ cfg( feature = "test" ) ]
70
79
struct TestStdin ( TestStdinInner ) ;
71
80
81
+ #[ cfg( feature = "test" ) ]
72
82
impl Stdin for TestStdin {
73
83
fn lock ( & self ) -> Box < dyn StdinLock + ' _ > {
74
84
Box :: new ( TestStdinLock {
@@ -179,12 +189,15 @@ impl StderrSource for super::OSProcess {
179
189
180
190
// ----------------------- test support for writers ------------------
181
191
192
+ #[ cfg( feature = "test" ) ]
182
193
pub ( super ) struct TestWriterLock < ' a > {
183
194
inner : MutexGuard < ' a , Vec < u8 > > ,
184
195
}
185
196
197
+ #[ cfg( feature = "test" ) ]
186
198
impl WriterLock for TestWriterLock < ' _ > { }
187
199
200
+ #[ cfg( feature = "test" ) ]
188
201
impl Write for TestWriterLock < ' _ > {
189
202
fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize > {
190
203
self . inner . write ( buf)
0 commit comments