@@ -561,22 +561,40 @@ mod spawn {
561
561
}
562
562
563
563
mod script {
564
- use std:: ffi:: { OsStr , OsString } ;
565
- use std:: path:: { Path , PathBuf } ;
566
-
567
564
use gix_testtools:: bstr:: ByteSlice ;
568
-
569
- fn script_path ( filename : impl AsRef < Path > ) -> crate :: Result < PathBuf > {
570
- let mut path = gix_testtools:: scripted_fixture_read_only ( "scripts.sh" ) ?;
571
- path. push ( filename) ;
565
+ use std:: path:: Path ;
566
+
567
+ /// Get the path to a script created by the `scripts.sh` fixture.
568
+ ///
569
+ /// The path uses `/` as a separator. On Windows, it achieves this by replacing each
570
+ /// occurrence of `\` with `/`. This does not always preserve usability, and sometimes
571
+ /// does not even preserve meaning. In particular, `\\?\` paths would often become less
572
+ /// usable (though `std` recognizes `//?/`) and occasionally incorrect (if a component
573
+ /// contained a literal `/` on a strange filesystem), and NT object manager paths such as
574
+ /// those that begin with `\??\` (which `std` recognizes, when they refer to entries on a
575
+ /// filesystem) are always broken. But they might be good enough to use in the test suite.
576
+ ///
577
+ /// This fails if the path is not valid Unicode (as `String` is a bit easier to use here).
578
+ fn script_path ( filename : impl AsRef < Path > ) -> crate :: Result < String > {
579
+ let path = gix_testtools:: scripted_fixture_read_only ( "scripts.sh" ) ?
580
+ . join ( filename)
581
+ . to_str ( )
582
+ . map ( |p| {
583
+ if cfg ! ( windows) {
584
+ p. replace ( '\\' , "/" )
585
+ } else {
586
+ p. to_owned ( )
587
+ }
588
+ } )
589
+ . expect ( "valid UTF-8" ) ;
572
590
Ok ( path)
573
591
}
574
592
575
593
fn script_stdout_lines (
576
- path : impl Into < OsString > ,
577
- args : Option < & [ & OsStr ] > , // Let us test calling vs. not calling `args` (rather than calling with `[]`).
594
+ path : & str ,
595
+ args : Option < & [ & str ] > , // Let us test calling vs. not calling `args` (rather than calling with `[]`).
578
596
indirect : bool ,
579
- ) -> crate :: Result < Vec < OsString > > {
597
+ ) -> crate :: Result < Vec < String > > {
580
598
let mut prep = gix_command:: prepare ( path) ;
581
599
if indirect {
582
600
prep. use_shell = true ;
@@ -592,15 +610,15 @@ mod spawn {
592
610
let lines = out
593
611
. stdout
594
612
. lines ( )
595
- . map ( |line| line. to_os_str ( ) . expect ( "valid UTF-8" ) )
613
+ . map ( |line| line. to_str ( ) . expect ( "valid UTF-8" ) )
596
614
. map ( ToOwned :: to_owned)
597
615
. collect ( ) ;
598
616
Ok ( lines)
599
617
}
600
618
601
619
fn do_trivial ( indirect : bool ) -> crate :: Result {
602
620
let path = script_path ( "trivial" ) ?;
603
- let lines = script_stdout_lines ( path, None , indirect) ?;
621
+ let lines = script_stdout_lines ( & path, None , indirect) ?;
604
622
assert_eq ! ( lines, [ "Hello, world!" ] ) ;
605
623
Ok ( ( ) )
606
624
}
@@ -634,8 +652,8 @@ mod spawn {
634
652
635
653
fn do_name_with_args ( indirect : bool ) -> crate :: Result {
636
654
let path = script_path ( "name-and-args" ) ?;
637
- let args = [ "foo" , "bar baz" , "quux" ] . map ( OsStr :: new ) ;
638
- let expected: Vec < _ > = std:: iter:: once ( path. as_os_str ( ) ) . chain ( args) . collect ( ) ;
655
+ let args = [ "foo" , "bar baz" , "quux" ] ;
656
+ let expected: Vec < _ > = std:: iter:: once ( path. as_str ( ) ) . chain ( args) . collect ( ) ;
639
657
let lines = script_stdout_lines ( & path, Some ( & args) , indirect) ?;
640
658
assert_eq ! ( lines, expected) ;
641
659
Ok ( ( ) )
0 commit comments