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+ } ;
37
48use enum_dispatch:: enum_dispatch;
59
6- use crate :: currentprocess:: process;
7-
810use super :: terminalsource:: { ColorableTerminal , StreamSelector } ;
11+ use crate :: currentprocess:: process;
912
1013/// Stand-in for std::io::Stdin
1114pub trait Stdin {
@@ -44,18 +47,22 @@ impl StdinSource for super::OSProcess {
4447
4548// ----------------------- test support for stdin ------------------
4649
50+ #[ cfg( feature = "test" ) ]
4751struct TestStdinLock < ' a > {
4852 inner : MutexGuard < ' a , Cursor < String > > ,
4953}
5054
55+ #[ cfg( feature = "test" ) ]
5156impl StdinLock for TestStdinLock < ' _ > { }
5257
58+ #[ cfg( feature = "test" ) ]
5359impl Read for TestStdinLock < ' _ > {
5460 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
5561 self . inner . read ( buf)
5662 }
5763}
5864
65+ #[ cfg( feature = "test" ) ]
5966impl BufRead for TestStdinLock < ' _ > {
6067 fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > {
6168 self . inner . fill_buf ( )
@@ -65,10 +72,13 @@ impl BufRead for TestStdinLock<'_> {
6572 }
6673}
6774
75+ #[ cfg( feature = "test" ) ]
6876pub ( crate ) type TestStdinInner = Arc < Mutex < Cursor < String > > > ;
6977
78+ #[ cfg( feature = "test" ) ]
7079struct TestStdin ( TestStdinInner ) ;
7180
81+ #[ cfg( feature = "test" ) ]
7282impl Stdin for TestStdin {
7383 fn lock ( & self ) -> Box < dyn StdinLock + ' _ > {
7484 Box :: new ( TestStdinLock {
@@ -179,12 +189,15 @@ impl StderrSource for super::OSProcess {
179189
180190// ----------------------- test support for writers ------------------
181191
192+ #[ cfg( feature = "test" ) ]
182193pub ( super ) struct TestWriterLock < ' a > {
183194 inner : MutexGuard < ' a , Vec < u8 > > ,
184195}
185196
197+ #[ cfg( feature = "test" ) ]
186198impl WriterLock for TestWriterLock < ' _ > { }
187199
200+ #[ cfg( feature = "test" ) ]
188201impl Write for TestWriterLock < ' _ > {
189202 fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize > {
190203 self . inner . write ( buf)
0 commit comments