@@ -3,6 +3,7 @@ use error_chain::ChainedError;
3
3
use errors:: * ;
4
4
use output:: { OutputAssertion , OutputKind } ;
5
5
use std:: default;
6
+ use std:: ffi:: { OsStr , OsString } ;
6
7
use std:: io:: Write ;
7
8
use std:: path:: PathBuf ;
8
9
use std:: process:: { Command , Stdio } ;
@@ -12,7 +13,7 @@ use std::vec::Vec;
12
13
#[ derive( Debug ) ]
13
14
#[ must_use]
14
15
pub struct Assert {
15
- cmd : Vec < String > ,
16
+ cmd : Vec < OsString > ,
16
17
env : Environment ,
17
18
current_dir : Option < PathBuf > ,
18
19
expect_success : Option < bool > ,
@@ -29,7 +30,7 @@ impl default::Default for Assert {
29
30
Assert {
30
31
cmd : vec ! [ "cargo" , "run" , "--quiet" , "--" ]
31
32
. into_iter ( )
32
- . map ( String :: from)
33
+ . map ( OsString :: from)
33
34
. collect ( ) ,
34
35
env : Environment :: inherit ( ) ,
35
36
current_dir : None ,
@@ -52,11 +53,17 @@ impl Assert {
52
53
/// Run a specific binary of the current crate.
53
54
///
54
55
/// Defaults to asserting _successful_ execution.
55
- pub fn cargo_binary ( name : & str ) -> Self {
56
+ pub fn cargo_binary < S : AsRef < OsStr > > ( name : S ) -> Self {
56
57
Assert {
57
- cmd : vec ! [ "cargo" , "run" , "--quiet" , "--bin" , name, "--" ]
58
- . into_iter ( )
59
- . map ( String :: from)
58
+ cmd : vec ! [
59
+ OsStr :: new( "cargo" ) ,
60
+ OsStr :: new( "run" ) ,
61
+ OsStr :: new( "--quiet" ) ,
62
+ OsStr :: new( "--bin" ) ,
63
+ name. as_ref( ) ,
64
+ OsStr :: new( "--" ) ,
65
+ ] . into_iter ( )
66
+ . map ( OsString :: from)
60
67
. collect ( ) ,
61
68
..Self :: default ( )
62
69
}
@@ -74,9 +81,9 @@ impl Assert {
74
81
/// assert_cli::Assert::command(&["echo", "1337"])
75
82
/// .unwrap();
76
83
/// ```
77
- pub fn command ( cmd : & [ & str ] ) -> Self {
84
+ pub fn command < S : AsRef < OsStr > > ( cmd : & [ S ] ) -> Self {
78
85
Assert {
79
- cmd : cmd. into_iter ( ) . cloned ( ) . map ( String :: from) . collect ( ) ,
86
+ cmd : cmd. into_iter ( ) . map ( OsString :: from) . collect ( ) ,
80
87
..Self :: default ( )
81
88
}
82
89
}
@@ -94,8 +101,8 @@ impl Assert {
94
101
/// .unwrap();
95
102
///
96
103
/// ```
97
- pub fn with_args ( mut self , args : & [ & str ] ) -> Self {
98
- self . cmd . extend ( args. into_iter ( ) . cloned ( ) . map ( String :: from) ) ;
104
+ pub fn with_args < S : AsRef < OsStr > > ( mut self , args : & [ S ] ) -> Self {
105
+ self . cmd . extend ( args. into_iter ( ) . map ( OsString :: from) ) ;
99
106
self
100
107
}
101
108
0 commit comments