@@ -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 } ;
@@ -11,7 +12,7 @@ use std::vec::Vec;
1112/// Assertions for a specific command.
1213#[ derive( Debug ) ]
1314pub struct Assert {
14- cmd : Vec < String > ,
15+ cmd : Vec < OsString > ,
1516 env : Environment ,
1617 current_dir : Option < PathBuf > ,
1718 expect_success : Option < bool > ,
@@ -28,7 +29,7 @@ impl default::Default for Assert {
2829 Assert {
2930 cmd : vec ! [ "cargo" , "run" , "--quiet" , "--" ]
3031 . into_iter ( )
31- . map ( String :: from)
32+ . map ( OsString :: from)
3233 . collect ( ) ,
3334 env : Environment :: inherit ( ) ,
3435 current_dir : None ,
@@ -51,11 +52,17 @@ impl Assert {
5152 /// Run a specific binary of the current crate.
5253 ///
5354 /// Defaults to asserting _successful_ execution.
54- pub fn cargo_binary ( name : & str ) -> Self {
55+ pub fn cargo_binary < S : AsRef < OsStr > > ( name : S ) -> Self {
5556 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)
5966 . collect ( ) ,
6067 ..Self :: default ( )
6168 }
@@ -73,9 +80,9 @@ impl Assert {
7380 /// assert_cli::Assert::command(&["echo", "1337"])
7481 /// .unwrap();
7582 /// ```
76- pub fn command ( cmd : & [ & str ] ) -> Self {
83+ pub fn command < S : AsRef < OsStr > > ( cmd : & [ S ] ) -> Self {
7784 Assert {
78- cmd : cmd. into_iter ( ) . cloned ( ) . map ( String :: from) . collect ( ) ,
85+ cmd : cmd. into_iter ( ) . map ( OsString :: from) . collect ( ) ,
7986 ..Self :: default ( )
8087 }
8188 }
@@ -93,8 +100,8 @@ impl Assert {
93100 /// .unwrap();
94101 ///
95102 /// ```
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) ) ;
98105 self
99106 }
100107
0 commit comments