@@ -17,6 +17,18 @@ fn build_temp_file(dir: &TempDir) -> PathBuf {
17
17
file_path
18
18
}
19
19
20
+ fn link_it ( link_path : PathBuf , file_path_s : & str , is_soft : bool ) -> String {
21
+ let link_name_s = link_path. to_str ( ) . unwrap ( ) ;
22
+ let mut c = Command :: new ( "ln" ) ;
23
+ if is_soft {
24
+ c. arg ( "-s" ) ;
25
+ }
26
+ c. arg ( file_path_s) ;
27
+ c. arg ( link_name_s) ;
28
+ assert ! ( c. output( ) . is_ok( ) ) ;
29
+ return link_name_s. into ( ) ;
30
+ }
31
+
20
32
#[ cfg_attr( target_os = "windows" , ignore) ]
21
33
#[ test]
22
34
pub fn test_soft_sym_link ( ) {
@@ -26,13 +38,7 @@ pub fn test_soft_sym_link() {
26
38
let file_path_s = file. to_str ( ) . unwrap ( ) ;
27
39
28
40
let link_name = dir. path ( ) . join ( "the_link" ) ;
29
- let link_name_s = link_name. to_str ( ) . unwrap ( ) ;
30
- let c = Command :: new ( "ln" )
31
- . arg ( "-s" )
32
- . arg ( file_path_s)
33
- . arg ( link_name_s)
34
- . output ( ) ;
35
- assert ! ( c. is_ok( ) ) ;
41
+ let link_name_s = link_it ( link_name, file_path_s, true ) ;
36
42
37
43
let c = format ! ( " ├── {}" , link_name_s) ;
38
44
let b = format ! ( " ┌── {}" , file_path_s) ;
@@ -61,12 +67,7 @@ pub fn test_hard_sym_link() {
61
67
let file_path_s = file. to_str ( ) . unwrap ( ) ;
62
68
63
69
let link_name = dir. path ( ) . join ( "the_link" ) ;
64
- let link_name_s = link_name. to_str ( ) . unwrap ( ) ;
65
- let c = Command :: new ( "ln" )
66
- . arg ( file_path_s)
67
- . arg ( link_name_s)
68
- . output ( ) ;
69
- assert ! ( c. is_ok( ) ) ;
70
+ link_it ( link_name, file_path_s, false ) ;
70
71
71
72
let file_output = format ! ( " ┌── {}" , file_path_s) ;
72
73
let dirs_output = format ! ( "─┴ {}" , dir_s) ;
@@ -82,21 +83,44 @@ pub fn test_hard_sym_link() {
82
83
assert ! ( output. contains( file_output. as_str( ) ) ) ;
83
84
}
84
85
86
+ #[ cfg_attr( target_os = "windows" , ignore) ]
87
+ #[ test]
88
+ pub fn test_hard_sym_link_no_dup_multi_arg ( ) {
89
+ let dir = Builder :: new ( ) . tempdir ( ) . unwrap ( ) ;
90
+ let dir_link = Builder :: new ( ) . tempdir ( ) . unwrap ( ) ;
91
+ let file = build_temp_file ( & dir) ;
92
+ let dir_s = dir. path ( ) . to_str ( ) . unwrap ( ) ;
93
+ let dir_link_s = dir_link. path ( ) . to_str ( ) . unwrap ( ) ;
94
+ let file_path_s = file. to_str ( ) . unwrap ( ) ;
95
+
96
+ let link_name = dir_link. path ( ) . join ( "the_link" ) ;
97
+ let link_name_s = link_it ( link_name, file_path_s, false ) ;
98
+
99
+ let mut cmd = Command :: cargo_bin ( "dust" ) . unwrap ( ) ;
100
+
101
+ // Mac test runners create long filenames in tmp directories
102
+ let output = cmd
103
+ . args ( [ "-p" , "-c" , "-w 999" , "-b" , dir_link_s, dir_s] )
104
+ . unwrap ( )
105
+ . stdout ;
106
+
107
+ // The link or the file should appeart but not both
108
+ let output = str:: from_utf8 ( & output) . unwrap ( ) ;
109
+ println ! ( "cmd:\n {:?}" , cmd) ;
110
+ println ! ( "output:\n {:?}" , output) ;
111
+ let has_file_only = output. contains ( file_path_s) && !output. contains ( & link_name_s) ;
112
+ let has_link_only = !output. contains ( file_path_s) && output. contains ( & link_name_s) ;
113
+ assert ! ( has_file_only || has_link_only)
114
+ }
115
+
85
116
#[ cfg_attr( target_os = "windows" , ignore) ]
86
117
#[ test]
87
118
pub fn test_recursive_sym_link ( ) {
88
119
let dir = Builder :: new ( ) . tempdir ( ) . unwrap ( ) ;
89
120
let dir_s = dir. path ( ) . to_str ( ) . unwrap ( ) ;
90
121
91
122
let link_name = dir. path ( ) . join ( "the_link" ) ;
92
- let link_name_s = link_name. to_str ( ) . unwrap ( ) ;
93
-
94
- let c = Command :: new ( "ln" )
95
- . arg ( "-s" )
96
- . arg ( dir_s)
97
- . arg ( link_name_s)
98
- . output ( ) ;
99
- assert ! ( c. is_ok( ) ) ;
123
+ let link_name_s = link_it ( link_name, dir_s, true ) ;
100
124
101
125
let a = format ! ( "─┬ {}" , dir_s) ;
102
126
let b = format ! ( " └── {}" , link_name_s) ;
0 commit comments