Skip to content

Commit a79dd12

Browse files
committed
Lighten test dependencies related to os_str_bytes
- Use only the needed feature. - Don't use it on Unix-like systems, where we can do without it.
1 parent 7d9005e commit a79dd12

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

gix-command/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ shell-words = "1.0"
2424

2525
[dev-dependencies]
2626
gix-testtools = { path = "../tests/tools" }
27+
28+
[target.'cfg(not(unix))'.dev-dependencies]
2729
os_str_bytes = { version = "^6.6.1", default-features = false, features = ["conversions"] }

gix-command/tests/command.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -562,20 +562,27 @@ mod spawn {
562562
use std::ffi::{OsStr, OsString};
563563
use std::path::Path;
564564

565-
use gix_testtools::bstr::{BString, ByteSlice, ByteVec};
566-
use os_str_bytes::OsStringBytes;
565+
use gix_testtools::bstr::{BString, ByteVec};
567566

568567
fn script_path(filename: impl AsRef<Path>) -> crate::Result<OsString> {
569-
// TODO(msrv): At 1.74, change into_raw_vec to into_encoded_bytes and don't depend on os_str_bytes.
570-
let native_path: BString = gix_testtools::scripted_fixture_read_only("scripts.sh")?
568+
let native_path = gix_testtools::scripted_fixture_read_only("scripts.sh")?
571569
.join(filename)
572-
.into_os_string()
573-
.into_raw_vec()
574-
.into();
575-
let unix_path = gix_path::to_unix_separators_on_windows(native_path)
576-
.to_os_str()?
577-
.to_owned();
578-
Ok(unix_path)
570+
.into_os_string();
571+
#[cfg(unix)]
572+
{
573+
Ok(native_path)
574+
}
575+
#[cfg(not(unix))]
576+
{
577+
// TODO(msrv): At 1.74, change into_raw_vec to into_encoded_bytes and don't depend on os_str_bytes.
578+
use gix_testtools::bstr::ByteSlice;
579+
use os_str_bytes::OsStringBytes;
580+
let raw_native_path: BString = native_path.into_raw_vec().into();
581+
let slash_path = gix_path::to_unix_separators_on_windows(raw_native_path)
582+
.to_os_str()?
583+
.to_owned();
584+
Ok(slash_path)
585+
}
579586
}
580587

581588
fn script_stdout(
@@ -599,8 +606,18 @@ mod spawn {
599606
}
600607

601608
fn concatenate(prefix: OsString, suffix: &str) -> BString {
602-
// TODO(msrv): At 1.74, change into_raw_vec to into_encoded_bytes and don't depend on os_str_bytes.
603-
let mut buffer: BString = prefix.into_raw_vec().into();
609+
// TODO(msrv): At 1.74, use into_encoded_bytes instead of into_vec and into_raw_vec,
610+
// and don't depend on os_str_bytes.
611+
#[cfg(unix)]
612+
let mut buffer: BString = {
613+
use std::os::unix::ffi::OsStringExt;
614+
prefix.into_vec().into()
615+
};
616+
#[cfg(not(unix))]
617+
let mut buffer: BString = {
618+
use os_str_bytes::OsStringBytes;
619+
prefix.into_raw_vec().into()
620+
};
604621
buffer.push_str(suffix);
605622
buffer
606623
}

0 commit comments

Comments
 (0)