Skip to content

Commit 3a549b7

Browse files
committed
TestProcess and friends should be test only
Before we had the test feature we had to rely on link time optimisation to remove this code, but there is no need to compile it at all for non-test builds.
1 parent 86ed53c commit 3a549b7

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

src/currentprocess.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
use std::boxed::Box;
22
use std::cell::RefCell;
3-
use std::collections::HashMap;
43
use std::default::Default;
54
use std::fmt::Debug;
6-
use std::io::Cursor;
75
use std::panic;
8-
use std::path::{Path, PathBuf};
6+
use std::path::PathBuf;
97
use std::sync::Once;
10-
use std::sync::{Arc, Mutex};
8+
#[cfg(feature = "test")]
9+
use std::{
10+
collections::HashMap,
11+
io::Cursor,
12+
path::Path,
13+
sync::{Arc, Mutex},
14+
};
1115

1216
use home::env as home;
17+
#[cfg(feature = "test")]
1318
use rand::{thread_rng, Rng};
1419

1520
pub(crate) mod argsource;
@@ -204,7 +209,7 @@ impl ProcessSource for OSProcess {
204209
}
205210

206211
// ------------ test process ----------------
207-
212+
#[cfg(feature = "test")]
208213
#[derive(Clone, Debug, Default)]
209214
pub struct TestProcess {
210215
pub cwd: PathBuf,
@@ -216,6 +221,7 @@ pub struct TestProcess {
216221
pub stderr: TestWriterInner,
217222
}
218223

224+
#[cfg(feature = "test")]
219225
impl TestProcess {
220226
pub fn new<P: AsRef<Path>, A: AsRef<str>>(
221227
cwd: P,
@@ -257,6 +263,7 @@ impl TestProcess {
257263
}
258264
}
259265

266+
#[cfg(feature = "test")]
260267
impl ProcessSource for TestProcess {
261268
fn id(&self) -> u64 {
262269
self.id

src/currentprocess/argsource.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl<T: From<String>> Iterator for VecArgs<T> {
5252
}
5353
}
5454

55+
#[cfg(feature = "test")]
5556
impl ArgSource for super::TestProcess {
5657
fn args(&self) -> Box<dyn Iterator<Item = String>> {
5758
Box::new(VecArgs::<String>::from(&self.args))

src/currentprocess/cwdsource.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl CurrentDirSource for super::OSProcess {
1515
}
1616
}
1717

18+
#[cfg(feature = "test")]
1819
impl CurrentDirSource for super::TestProcess {
1920
fn current_dir(&self) -> io::Result<PathBuf> {
2021
Ok(self.cwd.clone())

src/currentprocess/filesource.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl Stdin for TestStdin {
7373
}
7474
}
7575

76+
#[cfg(feature = "test")]
7677
impl StdinSource for super::TestProcess {
7778
fn stdin(&self) -> Box<dyn Stdin> {
7879
Box::new(TestStdin(self.stdin.clone()))
@@ -193,12 +194,14 @@ impl Isatty for TestWriter {
193194
}
194195
}
195196

197+
#[cfg(feature = "test")]
196198
impl StdoutSource for super::TestProcess {
197199
fn stdout(&self) -> Box<dyn Writer> {
198200
Box::new(TestWriter(self.stdout.clone()))
199201
}
200202
}
201203

204+
#[cfg(feature = "test")]
202205
impl StderrSource for super::TestProcess {
203206
fn stderr(&self) -> Box<dyn Writer> {
204207
Box::new(TestWriter(self.stderr.clone()))

src/currentprocess/homethunk.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/// Adapts currentprocess to the trait home::Env
22
use std::ffi::OsString;
33
use std::io;
4+
#[cfg(feature = "test")]
45
use std::ops::Deref;
56
use std::path::PathBuf;
67

78
use home::env as home;
89

9-
use super::CurrentDirSource;
1010
use super::HomeProcess;
1111
use super::OSProcess;
12-
use super::TestProcess;
13-
use super::VarSource;
12+
#[cfg(feature = "test")]
13+
use super::{CurrentDirSource, TestProcess, VarSource};
1414

1515
impl home::Env for Box<dyn HomeProcess + 'static> {
1616
fn home_dir(&self) -> Option<PathBuf> {
@@ -24,6 +24,7 @@ impl home::Env for Box<dyn HomeProcess + 'static> {
2424
}
2525
}
2626

27+
#[cfg(feature = "test")]
2728
impl home::Env for TestProcess {
2829
fn home_dir(&self) -> Option<PathBuf> {
2930
self.var("HOME").ok().map(|v| v.into())

src/currentprocess/varsource.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl VarSource for super::OSProcess {
2020
}
2121
}
2222

23+
#[cfg(feature = "test")]
2324
impl VarSource for super::TestProcess {
2425
fn var(&self, key: &str) -> std::result::Result<String, env::VarError> {
2526
match self.var_os(key) {

0 commit comments

Comments
 (0)