Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit 3a528a9

Browse files
committed
switch to OsString
Signed-off-by: Freyskeyd <[email protected]>
1 parent 8cb7289 commit 3a528a9

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Assert CLI
2-
32
> **Test CLI Applications** - This crate checks the output of a child process is as expected.
43
54
[![Build Status](https://travis-ci.org/killercup/assert_cli.svg)](https://travis-ci.org/killercup/assert_cli) [![Documentation](https://img.shields.io/badge/docs-master-blue.svg)][Documentation]

src/environment.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use std::ffi::OsString;
12
/// Structure to deal with environment variables
23
#[derive(Clone, Debug, PartialEq, Eq)]
34
pub struct Environment {
45
/// Customized environment variables
5-
vars: Vec<(String, String)>,
6+
vars: Vec<(OsString, OsString)>,
67
/// Define if the structure must inherit
78
inherit: bool,
89
}
@@ -24,8 +25,10 @@ impl Environment {
2425
/// ```rust
2526
/// extern crate assert_cli;
2627
///
28+
/// use std::ffi::OsString;
29+
///
2730
/// let e = assert_cli::Environment::inherit().compile();
28-
/// let e_: Vec<(String, String)> = ::std::env::vars().collect();
31+
/// let e_: Vec<(OsString, OsString)> = ::std::env::vars_os().collect();
2932
///
3033
/// assert_eq!(e, e_);
3134
/// ```
@@ -57,18 +60,20 @@ impl Environment {
5760
/// ```rust
5861
/// extern crate assert_cli;
5962
///
63+
/// use std::ffi::OsString;
64+
///
6065
/// let e = assert_cli::Environment::empty().insert("foo", "bar").compile();
61-
/// assert_eq!(e, vec![("foo".to_string(), "bar".to_string())]);
66+
/// assert_eq!(e, vec![(OsString::from("foo"), OsString::from("bar"))]);
6267
/// ```
63-
pub fn insert<S1: Into<String>, S2: Into<String>>(mut self, key: S1, val: S2) -> Self {
68+
pub fn insert<S1: Into<OsString>, S2: Into<OsString>>(mut self, key: S1, val: S2) -> Self {
6469
self.vars.push((key.into(), val.into()));
6570
self
6671
}
6772

6873
/// Compile Environment object
69-
pub fn compile(self) -> Vec<(String, String)> {
74+
pub fn compile(self) -> Vec<(OsString, OsString)> {
7075
if self.inherit {
71-
::std::env::vars().chain(self.vars).collect()
76+
::std::env::vars_os().chain(self.vars).collect()
7277
} else {
7378
self.vars
7479
}
@@ -83,12 +88,15 @@ impl<'a> From<&'a Environment> for Environment {
8388
}
8489

8590
pub trait EnvironmentItem {
86-
fn to_environment_tuple(&self) -> (String, String);
91+
fn to_environment_tuple(&self) -> (OsString, OsString);
8792
}
8893

8994
impl<'s, T: ToString, Z: ToString> EnvironmentItem for &'s (T, Z) {
90-
fn to_environment_tuple(&self) -> (String, String) {
91-
(self.0.to_string(), self.1.to_string())
95+
fn to_environment_tuple(&self) -> (OsString, OsString) {
96+
(
97+
OsString::from(self.0.to_string()),
98+
OsString::from(self.1.to_string()),
99+
)
92100
}
93101
}
94102

@@ -128,7 +136,10 @@ mod test {
128136

129137
let y = y.insert("key", "value");
130138

131-
assert_eq!(y.compile(), vec![("key".to_string(), "value".to_string())]);
139+
assert_eq!(
140+
y.compile(),
141+
vec![(OsString::from("key"), OsString::from("value"))]
142+
);
132143
}
133144

134145
#[test]
@@ -154,7 +165,7 @@ mod test {
154165

155166
assert_eq!(
156167
y.clone().insert("key", "value").compile(),
157-
vec![("key".to_string(), "value".to_string())]
168+
vec![(OsString::from("key"), OsString::from("value"))]
158169
);
159170

160171
assert!(

0 commit comments

Comments
 (0)