Skip to content

Commit 7a47c1d

Browse files
committed
fix(filesource): make some constructs only available via the test feature
1 parent c7f5367 commit 7a47c1d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/currentprocess/filesource.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
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

48
use enum_dispatch::enum_dispatch;
59

6-
use crate::currentprocess::process;
7-
810
use super::terminalsource::{ColorableTerminal, StreamSelector};
11+
use crate::currentprocess::process;
912

1013
/// Stand-in for std::io::Stdin
1114
pub trait Stdin {
@@ -44,18 +47,22 @@ impl StdinSource for super::OSProcess {
4447

4548
// ----------------------- test support for stdin ------------------
4649

50+
#[cfg(feature = "test")]
4751
struct TestStdinLock<'a> {
4852
inner: MutexGuard<'a, Cursor<String>>,
4953
}
5054

55+
#[cfg(feature = "test")]
5156
impl StdinLock for TestStdinLock<'_> {}
5257

58+
#[cfg(feature = "test")]
5359
impl 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")]
5966
impl 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")]
6876
pub(crate) type TestStdinInner = Arc<Mutex<Cursor<String>>>;
6977

78+
#[cfg(feature = "test")]
7079
struct TestStdin(TestStdinInner);
7180

81+
#[cfg(feature = "test")]
7282
impl 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")]
182193
pub(super) struct TestWriterLock<'a> {
183194
inner: MutexGuard<'a, Vec<u8>>,
184195
}
185196

197+
#[cfg(feature = "test")]
186198
impl WriterLock for TestWriterLock<'_> {}
187199

200+
#[cfg(feature = "test")]
188201
impl Write for TestWriterLock<'_> {
189202
fn write(&mut self, buf: &[u8]) -> Result<usize> {
190203
self.inner.write(buf)

0 commit comments

Comments
 (0)