Skip to content

Commit 00f94f5

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

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/currentprocess/filesource.rs

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

43
use enum_dispatch::enum_dispatch;
54

5+
use super::terminalsource::{ColorableTerminal, StreamSelector};
66
use 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
1115
pub trait Stdin {
@@ -44,18 +48,22 @@ impl StdinSource for super::OSProcess {
4448

4549
// ----------------------- test support for stdin ------------------
4650

51+
#[cfg(feature = "test")]
4752
struct TestStdinLock<'a> {
4853
inner: MutexGuard<'a, Cursor<String>>,
4954
}
5055

56+
#[cfg(feature = "test")]
5157
impl StdinLock for TestStdinLock<'_> {}
5258

59+
#[cfg(feature = "test")]
5360
impl 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")]
5967
impl 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")]
6877
pub(crate) type TestStdinInner = Arc<Mutex<Cursor<String>>>;
6978

79+
#[cfg(feature = "test")]
7080
struct TestStdin(TestStdinInner);
7181

82+
#[cfg(feature = "test")]
7283
impl 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")]
182194
pub(super) struct TestWriterLock<'a> {
183195
inner: MutexGuard<'a, Vec<u8>>,
184196
}
185197

198+
#[cfg(feature = "test")]
186199
impl WriterLock for TestWriterLock<'_> {}
187200

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

0 commit comments

Comments
 (0)