@@ -93,13 +93,13 @@ impl<'s, T: ToString, Z: ToString> EnvironmentItem for &'s (T, Z) {
93
93
}
94
94
95
95
impl < ' s , T > From < T > for Environment
96
- where T : IntoIterator , T :: Item : EnvironmentItem
96
+ where
97
+ T : IntoIterator ,
98
+ T :: Item : EnvironmentItem
97
99
{
98
100
fn from ( v : T ) -> Self {
99
101
Self {
100
- vars : v. into_iter ( )
101
- . map ( |k| k. to_environment_tuple ( ) )
102
- . collect ( ) ,
102
+ vars : v. into_iter ( ) . map ( |k| k. to_environment_tuple ( ) ) . collect ( ) ,
103
103
inherit : false ,
104
104
}
105
105
}
@@ -109,7 +109,7 @@ impl<'s, T> From<T> for Environment
109
109
#[ cfg( test) ]
110
110
mod test {
111
111
use super :: * ;
112
- use :: Assert ;
112
+ use Assert ;
113
113
114
114
fn command ( ) -> Assert {
115
115
Assert :: command ( & [ "printenv" ] )
@@ -119,10 +119,7 @@ mod test {
119
119
fn take_ownership ( ) {
120
120
let x = Environment :: inherit ( ) ;
121
121
122
- command ( )
123
- . with_env ( x. clone ( ) )
124
- . with_env ( & x)
125
- . with_env ( x) ;
122
+ command ( ) . with_env ( x. clone ( ) ) . with_env ( & x) . with_env ( x) ;
126
123
}
127
124
128
125
#[ test]
@@ -138,11 +135,14 @@ mod test {
138
135
fn in_place_mod2 ( ) {
139
136
let x = Environment :: inherit ( ) ;
140
137
141
- assert ! ( command( )
142
- . with_env( & x. insert( "key" , "value" ) . insert( "key" , "vv" ) )
143
- . stdout( ) . contains( "key=vv" )
144
- . execute( )
145
- . is_ok( ) ) ;
138
+ assert ! (
139
+ command( )
140
+ . with_env( & x. insert( "key" , "value" ) . insert( "key" , "vv" ) )
141
+ . stdout( )
142
+ . contains( "key=vv" )
143
+ . execute( )
144
+ . is_ok( )
145
+ ) ;
146
146
// Granted, `insert` moved `x`, so we can no longer reference it, even
147
147
// though only a reference was passed to `with_env`
148
148
}
@@ -152,55 +152,144 @@ mod test {
152
152
// In-place modification while allowing later accesses to the `Environment`
153
153
let y = Environment :: empty ( ) ;
154
154
155
- assert_eq ! ( y. clone( ) . insert( "key" , "value" ) . compile( ) , vec![ ( "key" . to_string( ) , "value" . to_string( ) ) ] ) ;
156
- assert ! ( command( )
157
- . with_env( y)
158
- . stdout( ) . not( ) . contains( "key=value" )
159
- . execute( ) . is_ok( ) ) ;
155
+ assert_eq ! (
156
+ y. clone( ) . insert( "key" , "value" ) . compile( ) ,
157
+ vec![ ( "key" . to_string( ) , "value" . to_string( ) ) ]
158
+ ) ;
159
+
160
+ assert ! (
161
+ command( )
162
+ . with_env( y)
163
+ . stdout( )
164
+ . not( )
165
+ . contains( "key=value" )
166
+ . execute( )
167
+ . is_ok( )
168
+ ) ;
160
169
}
161
170
162
171
#[ test]
163
172
fn empty_env ( ) {
164
173
// In-place modification while allowing later accesses to the `Environment`
165
174
let y = Environment :: empty ( ) ;
166
175
167
- assert ! ( command( )
168
- . with_env( y)
169
- . stdout( ) . is( "" )
170
- . execute( ) . is_ok( ) ) ;
176
+ assert ! ( command( ) . with_env( y) . stdout( ) . is( "" ) . execute( ) . is_ok( ) ) ;
171
177
}
172
178
#[ test]
173
179
fn take_vec ( ) {
174
180
let v = vec ! [ ( "bar" . to_string( ) , "baz" . to_string( ) ) ] ;
175
181
176
- assert ! ( command( ) . with_env( & vec![ ( "bar" , "baz" ) ] ) . stdout( ) . contains( "bar=baz" ) . execute( ) . is_ok( ) ) ;
177
- assert ! ( command( ) . with_env( & v) . stdout( ) . contains( "bar=baz" ) . execute( ) . is_ok( ) ) ;
178
- assert ! ( command( ) . with_env( & vec![ ( "bar" , "baz" ) ] ) . stdout( ) . isnt( "" ) . execute( ) . is_ok( ) ) ;
182
+ assert ! (
183
+ command( )
184
+ . with_env( & vec![ ( "bar" , "baz" ) ] )
185
+ . stdout( )
186
+ . contains( "bar=baz" )
187
+ . execute( )
188
+ . is_ok( )
189
+ ) ;
190
+
191
+ assert ! (
192
+ command( )
193
+ . with_env( & v)
194
+ . stdout( )
195
+ . contains( "bar=baz" )
196
+ . execute( )
197
+ . is_ok( )
198
+ ) ;
199
+
200
+ assert ! (
201
+ command( )
202
+ . with_env( & vec![ ( "bar" , "baz" ) ] )
203
+ . stdout( )
204
+ . isnt( "" )
205
+ . execute( )
206
+ . is_ok( )
207
+ ) ;
179
208
}
180
209
181
210
#[ test]
182
211
fn take_slice_of_strs ( ) {
183
- assert ! ( command( ) . with_env( & [ ( "bar" , "BAZ" ) ] ) . stdout( ) . contains( "bar=BAZ" ) . execute( ) . is_ok( ) ) ;
184
- assert ! ( command( ) . with_env( & [ ( "bar" , "BAZ" ) ] [ ..] ) . stdout( ) . contains( "bar=BAZ" ) . execute( ) . is_ok( ) ) ;
185
- assert ! ( command( ) . with_env( [ ( "bar" , "BAZ" ) ] . as_ref( ) ) . stdout( ) . contains( "bar=BAZ" ) . execute( ) . is_ok( ) ) ;
212
+ assert ! (
213
+ command( )
214
+ . with_env( & [ ( "bar" , "BAZ" ) ] )
215
+ . stdout( )
216
+ . contains( "bar=BAZ" )
217
+ . execute( )
218
+ . is_ok( )
219
+ ) ;
220
+
221
+ assert ! (
222
+ command( )
223
+ . with_env( & [ ( "bar" , "BAZ" ) ] [ ..] )
224
+ . stdout( )
225
+ . contains( "bar=BAZ" )
226
+ . execute( )
227
+ . is_ok( )
228
+ ) ;
229
+
230
+ assert ! (
231
+ command( )
232
+ . with_env( [ ( "bar" , "BAZ" ) ] . as_ref( ) )
233
+ . stdout( )
234
+ . contains( "bar=BAZ" )
235
+ . execute( )
236
+ . is_ok( )
237
+ ) ;
186
238
}
187
239
188
240
#[ test]
189
241
fn take_slice_of_strings ( ) {
190
242
// same deal as above
191
243
192
- assert ! ( command( ) . with_env( & [ ( "bar" . to_string( ) , "BAZ" . to_string( ) ) ] ) . stdout( ) . contains( "bar=BAZ" ) . execute( ) . is_ok( ) ) ;
193
- assert ! ( command( ) . with_env( & [ ( "bar" . to_string( ) , "BAZ" . to_string( ) ) ] [ ..] ) . stdout( ) . contains( "bar=BAZ" ) . execute( ) . is_ok( ) ) ;
244
+ assert ! (
245
+ command( )
246
+ . with_env( & [ ( "bar" . to_string( ) , "BAZ" . to_string( ) ) ] )
247
+ . stdout( )
248
+ . contains( "bar=BAZ" )
249
+ . execute( )
250
+ . is_ok( )
251
+ ) ;
252
+
253
+ assert ! (
254
+ command( )
255
+ . with_env( & [ ( "bar" . to_string( ) , "BAZ" . to_string( ) ) ] [ ..] )
256
+ . stdout( )
257
+ . contains( "bar=BAZ" )
258
+ . execute( )
259
+ . is_ok( )
260
+ ) ;
194
261
}
195
262
196
263
#[ test]
197
264
fn take_slice ( ) {
198
- assert ! ( command( ) . with_env( & [ ( "hey" , "ho" ) ] ) . stdout( ) . contains( "hey=ho" ) . execute( ) . is_ok( ) ) ;
199
- assert ! ( command( ) . with_env( & [ ( "hey" , "ho" . to_string( ) ) ] ) . stdout( ) . contains( "hey=ho" ) . execute( ) . is_ok( ) ) ;
265
+ assert ! (
266
+ command( )
267
+ . with_env( & [ ( "hey" , "ho" ) ] )
268
+ . stdout( )
269
+ . contains( "hey=ho" )
270
+ . execute( )
271
+ . is_ok( )
272
+ ) ;
273
+
274
+ assert ! (
275
+ command( )
276
+ . with_env( & [ ( "hey" , "ho" . to_string( ) ) ] )
277
+ . stdout( )
278
+ . contains( "hey=ho" )
279
+ . execute( )
280
+ . is_ok( )
281
+ ) ;
200
282
}
201
283
202
284
#[ test]
203
285
fn take_string_i32 ( ) {
204
- assert ! ( command( ) . with_env( & [ ( "bar" , 3 as i32 ) ] ) . stdout( ) . contains( "bar=3" ) . execute( ) . is_ok( ) ) ;
286
+ assert ! (
287
+ command( )
288
+ . with_env( & [ ( "bar" , 3 as i32 ) ] )
289
+ . stdout( )
290
+ . contains( "bar=3" )
291
+ . execute( )
292
+ . is_ok( )
293
+ ) ;
205
294
}
206
295
}
0 commit comments