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 } ;
32
43use enum_dispatch:: enum_dispatch;
54
5+ use super :: terminalsource:: { ColorableTerminal , StreamSelector } ;
66use crate :: currentprocess:: process;
77
8- use super :: terminalsource:: { ColorableTerminal , StreamSelector } ;
8+ #[ cfg( feature = "test" ) ]
9+ use std:: {
10+ io:: Cursor ,
11+ sync:: { Arc , Mutex , MutexGuard } ,
12+ } ;
913
1014/// Stand-in for std::io::Stdin
1115pub trait Stdin {
@@ -44,18 +48,22 @@ impl StdinSource for super::OSProcess {
4448
4549// ----------------------- test support for stdin ------------------
4650
51+ #[ cfg( feature = "test" ) ]
4752struct TestStdinLock < ' a > {
4853 inner : MutexGuard < ' a , Cursor < String > > ,
4954}
5055
56+ #[ cfg( feature = "test" ) ]
5157impl StdinLock for TestStdinLock < ' _ > { }
5258
59+ #[ cfg( feature = "test" ) ]
5360impl Read for TestStdinLock < ' _ > {
5461 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
5562 self . inner . read ( buf)
5663 }
5764}
5865
66+ #[ cfg( feature = "test" ) ]
5967impl BufRead for TestStdinLock < ' _ > {
6068 fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > {
6169 self . inner . fill_buf ( )
@@ -65,10 +73,13 @@ impl BufRead for TestStdinLock<'_> {
6573 }
6674}
6775
76+ #[ cfg( feature = "test" ) ]
6877pub ( crate ) type TestStdinInner = Arc < Mutex < Cursor < String > > > ;
6978
79+ #[ cfg( feature = "test" ) ]
7080struct TestStdin ( TestStdinInner ) ;
7181
82+ #[ cfg( feature = "test" ) ]
7283impl Stdin for TestStdin {
7384 fn lock ( & self ) -> Box < dyn StdinLock + ' _ > {
7485 Box :: new ( TestStdinLock {
@@ -179,12 +190,15 @@ impl StderrSource for super::OSProcess {
179190
180191// ----------------------- test support for writers ------------------
181192
193+ #[ cfg( feature = "test" ) ]
182194pub ( super ) struct TestWriterLock < ' a > {
183195 inner : MutexGuard < ' a , Vec < u8 > > ,
184196}
185197
198+ #[ cfg( feature = "test" ) ]
186199impl WriterLock for TestWriterLock < ' _ > { }
187200
201+ #[ cfg( feature = "test" ) ]
188202impl Write for TestWriterLock < ' _ > {
189203 fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize > {
190204 self . inner . write ( buf)
0 commit comments