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