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