@@ -3,6 +3,7 @@ use error_chain::ChainedError;
33use errors:: * ;
44use output:: { OutputAssertion , OutputKind } ;
55use std:: default;
6+ use std:: ffi:: { OsStr , OsString } ;
67use std:: io:: Write ;
78use std:: path:: PathBuf ;
89use std:: process:: { Command , Stdio } ;
@@ -12,7 +13,7 @@ use std::vec::Vec;
1213#[ derive( Debug ) ]
1314#[ must_use]
1415pub struct Assert {
15- cmd : Vec < String > ,
16+ cmd : Vec < OsString > ,
1617 env : Environment ,
1718 current_dir : Option < PathBuf > ,
1819 expect_success : Option < bool > ,
@@ -29,7 +30,7 @@ impl default::Default for Assert {
2930 Assert {
3031 cmd : vec ! [ "cargo" , "run" , "--quiet" , "--" ]
3132 . into_iter ( )
32- . map ( String :: from)
33+ . map ( OsString :: from)
3334 . collect ( ) ,
3435 env : Environment :: inherit ( ) ,
3536 current_dir : None ,
@@ -52,11 +53,17 @@ impl Assert {
5253 /// Run a specific binary of the current crate.
5354 ///
5455 /// Defaults to asserting _successful_ execution.
55- pub fn cargo_binary ( name : & str ) -> Self {
56+ pub fn cargo_binary < S : AsRef < OsStr > > ( name : S ) -> Self {
5657 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)
6067 . collect ( ) ,
6168 ..Self :: default ( )
6269 }
@@ -74,9 +81,9 @@ impl Assert {
7481 /// assert_cli::Assert::command(&["echo", "1337"])
7582 /// .unwrap();
7683 /// ```
77- pub fn command ( cmd : & [ & str ] ) -> Self {
84+ pub fn command < S : AsRef < OsStr > > ( cmd : & [ S ] ) -> Self {
7885 Assert {
79- cmd : cmd. into_iter ( ) . cloned ( ) . map ( String :: from) . collect ( ) ,
86+ cmd : cmd. into_iter ( ) . map ( OsString :: from) . collect ( ) ,
8087 ..Self :: default ( )
8188 }
8289 }
@@ -94,8 +101,8 @@ impl Assert {
94101 /// .unwrap();
95102 ///
96103 /// ```
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) ) ;
99106 self
100107 }
101108
0 commit comments