File tree 3 files changed +18
-8
lines changed
3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 1
1
use byteorder:: { BigEndian , ByteOrder } ;
2
2
use std:: env;
3
- use std:: path:: PathBuf ;
4
3
#[ cfg( unix) ]
5
4
use std:: io:: { self , BufRead } ;
6
5
@@ -21,8 +20,12 @@ fn main() {
21
20
22
21
// If there were no arguments, access stdin and test working dir.
23
22
if std:: env:: args ( ) . len ( ) <= 1 {
23
+ // CWD should be crate root.
24
+ // We have to normalize slashes, as the env var might be set for a different target's conventions.
24
25
let env_dir = env:: current_dir ( ) . unwrap ( ) ;
25
- let crate_dir = PathBuf :: from ( env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
26
+ let env_dir = env_dir. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
27
+ let crate_dir = env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
28
+ let crate_dir = crate_dir. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
26
29
assert_eq ! ( env_dir, crate_dir) ;
27
30
28
31
#[ cfg( unix) ]
Original file line number Diff line number Diff line change @@ -4,8 +4,13 @@ use std::path::PathBuf;
4
4
fn main ( ) {
5
5
println ! ( "subcrate running" ) ;
6
6
7
- let env_dir = env:: current_dir ( ) . unwrap ( ) ;
8
- let crate_dir = PathBuf :: from ( env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
9
7
// CWD should be workspace root, i.e., one level up from crate root.
10
- assert_eq ! ( env_dir, crate_dir. parent( ) . unwrap( ) ) ;
8
+ // We have to normalize slashes, as the env var might be set for a different target's conventions.
9
+ let env_dir = env:: current_dir ( ) . unwrap ( ) ;
10
+ let env_dir = env_dir. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
11
+ let crate_dir = env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
12
+ let crate_dir = crate_dir. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
13
+ let crate_dir = PathBuf :: from ( crate_dir) ;
14
+ let crate_dir = crate_dir. parent ( ) . unwrap ( ) . to_string_lossy ( ) ;
15
+ assert_eq ! ( env_dir, crate_dir) ;
11
16
}
Original file line number Diff line number Diff line change 1
1
use std:: env;
2
- use std:: path:: PathBuf ;
3
2
4
3
fn main ( ) {
5
4
println ! ( "subcrate testing" ) ;
6
5
7
- let env_dir = env:: current_dir ( ) . unwrap ( ) ;
8
- let crate_dir = PathBuf :: from ( env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
9
6
// CWD should be crate root.
7
+ // We have to normalize slashes, as the env var might be set for a different target's conventions.
8
+ let env_dir = env:: current_dir ( ) . unwrap ( ) ;
9
+ let env_dir = env_dir. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
10
+ let crate_dir = env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
11
+ let crate_dir = crate_dir. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
10
12
assert_eq ! ( env_dir, crate_dir) ;
11
13
}
You can’t perform that action at this time.
0 commit comments