Skip to content

Commit 5e22ea3

Browse files
committed
add in-memory tests
1 parent b2cab11 commit 5e22ea3

File tree

4 files changed

+816
-432
lines changed

4 files changed

+816
-432
lines changed

.github/workflows/rust.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ jobs:
9797
# Run the ignored tests that expect the above setup
9898
- name: Build | Test
9999
run: cargo test --workspace --all-features -- --include-ignored
100+
101+
- name: Test (no default features)
102+
run: cargo test --workspace --no-default-features
100103
cargo-deny:
101104
runs-on: ubuntu-22.04
102105
steps:

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
//! To find which rustc executable binary is using:
77
//!
88
//! ```no_run
9+
//! # #[cfg(feature = "real-sys")]
10+
//! # {
911
//! use which::which;
1012
//! use std::path::PathBuf;
1113
//!
1214
//! let result = which("rustc").unwrap();
1315
//! assert_eq!(result, PathBuf::from("/usr/bin/rustc"));
14-
//!
16+
//! # }
1517
//! ```
1618
1719
#![forbid(unsafe_code)]
@@ -411,6 +413,8 @@ impl<'a, TSys: Sys, F: NonFatalErrorHandler + 'a> WhichConfig<TSys, F> {
411413
///
412414
/// # Example
413415
/// ```
416+
/// # #[cfg(feature = "real-sys")]
417+
/// # {
414418
/// # use which::WhichConfig;
415419
/// let mut nonfatal_errors = Vec::new();
416420
///
@@ -424,18 +428,22 @@ impl<'a, TSys: Sys, F: NonFatalErrorHandler + 'a> WhichConfig<TSys, F> {
424428
/// if !nonfatal_errors.is_empty() {
425429
/// println!("nonfatal errors encountered: {nonfatal_errors:?}");
426430
/// }
431+
/// # }
427432
/// ```
428433
///
429434
/// You could also log it if you choose
430435
///
431436
/// ```
437+
/// # #[cfg(feature = "real-sys")]
438+
/// # {
432439
/// # use which::WhichConfig;
433440
/// WhichConfig::new()
434441
/// .binary_name("tar".into())
435442
/// .nonfatal_error_handler(|e| eprintln!("{e}"))
436443
/// .all_results()
437444
/// .unwrap()
438445
/// .collect::<Vec<_>>();
446+
/// # }
439447
/// ```
440448
pub fn nonfatal_error_handler<NewF>(self, handler: NewF) -> WhichConfig<TSys, NewF> {
441449
WhichConfig {

src/sys.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ pub trait Sys: Clone {
7979
/// and isn't conditionally compiled with `#[cfg(windows)]` so that it
8080
/// can work in Wasm.
8181
fn env_windows_path_ext(&self) -> Cow<'static, [String]> {
82-
Cow::Owned(self.env_var(OsStr::new("PATHEXT"))
83-
.map(|pathext| { parse_path_ext(&pathext) })
84-
// PATHEXT not being set or not being a proper Unicode string is exceedingly
85-
// improbable and would probably break Windows badly. Still, don't crash:
86-
.unwrap_or_default())
82+
Cow::Owned(
83+
self.env_var(OsStr::new("PATHEXT"))
84+
.map(|pathext| parse_path_ext(&pathext))
85+
// PATHEXT not being set or not being a proper Unicode string is exceedingly
86+
// improbable and would probably break Windows badly. Still, don't crash:
87+
.unwrap_or_default(),
88+
)
8789
}
8890
/// Gets the metadata of the provided path, following symlinks.
8991
fn metadata(&self, path: &Path) -> io::Result<Self::Metadata>;
@@ -233,14 +235,14 @@ impl Sys for RealSys {
233235

234236
fn parse_path_ext(pathext: &str) -> Vec<String> {
235237
pathext
236-
.split(';')
237-
.filter_map(|s| {
238-
if s.as_bytes().first() == Some(&b'.') {
239-
Some(s.to_owned())
240-
} else {
241-
// Invalid segment; just ignore it.
242-
None
243-
}
244-
})
245-
.collect()
246-
}
238+
.split(';')
239+
.filter_map(|s| {
240+
if s.as_bytes().first() == Some(&b'.') {
241+
Some(s.to_owned())
242+
} else {
243+
// Invalid segment; just ignore it.
244+
None
245+
}
246+
})
247+
.collect()
248+
}

0 commit comments

Comments
 (0)