@@ -63,7 +63,7 @@ fn both_lib_and_bin() {
63
63
"[ERROR] can't specify both lib and binary outputs" ) ) ;
64
64
}
65
65
66
- fn bin_already_exists ( explicit : bool , rellocation : & str ) {
66
+ fn bin_already_exists ( explicit : bool , rellocation : & str , needs_bin_section : bool ) {
67
67
let path = paths:: root ( ) . join ( "foo" ) ;
68
68
fs:: create_dir_all ( & path. join ( "src" ) ) . unwrap ( ) ;
69
69
@@ -94,36 +94,47 @@ fn bin_already_exists(explicit: bool, rellocation: &str) {
94
94
let mut new_content = Vec :: new ( ) ;
95
95
File :: open ( & sourcefile_path) . unwrap ( ) . read_to_end ( & mut new_content) . unwrap ( ) ;
96
96
assert_eq ! ( Vec :: from( content as & [ u8 ] ) , new_content) ;
97
+
98
+ let mut cargo_content = String :: new ( ) ;
99
+ File :: open ( & paths:: root ( ) . join ( "foo/Cargo.toml" ) ) . unwrap ( ) . read_to_string ( & mut cargo_content) . unwrap ( ) ;
100
+ // Check that Cargo.toml has a bin section pointing to the correct location (if needed)
101
+ if needs_bin_section {
102
+ assert ! ( cargo_content. contains( r#"[[bin]]"# ) ) ;
103
+ assert_that ( & paths:: root ( ) . join ( "foo/src/main.rs" ) , is_not ( existing_file ( ) ) ) ;
104
+ } else {
105
+ assert ! ( !cargo_content. contains( r#"[[bin]]"# ) ) ;
106
+ assert_that ( & paths:: root ( ) . join ( "foo/src/main.rs" ) , existing_file ( ) ) ;
107
+ }
97
108
}
98
109
99
110
#[ test]
100
111
fn bin_already_exists_explicit ( ) {
101
- bin_already_exists ( true , "src/main.rs" )
112
+ bin_already_exists ( true , "src/main.rs" , false )
102
113
}
103
114
104
115
#[ test]
105
116
fn bin_already_exists_implicit ( ) {
106
- bin_already_exists ( false , "src/main.rs" )
117
+ bin_already_exists ( false , "src/main.rs" , false )
107
118
}
108
119
109
120
#[ test]
110
121
fn bin_already_exists_explicit_nosrc ( ) {
111
- bin_already_exists ( true , "main.rs" )
122
+ bin_already_exists ( true , "main.rs" , true )
112
123
}
113
124
114
125
#[ test]
115
126
fn bin_already_exists_implicit_nosrc ( ) {
116
- bin_already_exists ( false , "main.rs" )
127
+ bin_already_exists ( false , "main.rs" , true )
117
128
}
118
129
119
130
#[ test]
120
131
fn bin_already_exists_implicit_namenosrc ( ) {
121
- bin_already_exists ( false , "foo.rs" )
132
+ bin_already_exists ( false , "foo.rs" , true )
122
133
}
123
134
124
135
#[ test]
125
136
fn bin_already_exists_implicit_namesrc ( ) {
126
- bin_already_exists ( false , "src/foo.rs" )
137
+ bin_already_exists ( false , "src/foo.rs" , true )
127
138
}
128
139
129
140
#[ test]
@@ -190,7 +201,7 @@ cannot automatically generate Cargo.toml as the main target would be ambiguous
190
201
assert_that ( & paths:: root ( ) . join ( "foo/Cargo.toml" ) , is_not ( existing_file ( ) ) ) ;
191
202
}
192
203
193
- fn lib_already_exists ( rellocation : & str ) {
204
+ fn lib_already_exists ( rellocation : & str , needs_lib_section : bool ) {
194
205
let path = paths:: root ( ) . join ( "foo" ) ;
195
206
fs:: create_dir_all ( & path. join ( "src" ) ) . unwrap ( ) ;
196
207
@@ -213,16 +224,38 @@ fn lib_already_exists(rellocation: &str) {
213
224
let mut new_content = Vec :: new ( ) ;
214
225
File :: open ( & sourcefile_path) . unwrap ( ) . read_to_end ( & mut new_content) . unwrap ( ) ;
215
226
assert_eq ! ( Vec :: from( content as & [ u8 ] ) , new_content) ;
227
+
228
+ let mut cargo_content = String :: new ( ) ;
229
+ File :: open ( & paths:: root ( ) . join ( "foo/Cargo.toml" ) ) . unwrap ( ) . read_to_string ( & mut cargo_content) . unwrap ( ) ;
230
+ // Check that Cargo.toml has a lib section pointing to the correct location (if needed)
231
+ if needs_lib_section {
232
+ assert ! ( cargo_content. contains( r#"[lib]"# ) ) ;
233
+ assert_that ( & paths:: root ( ) . join ( "foo/src/lib.rs" ) , is_not ( existing_file ( ) ) ) ;
234
+ } else {
235
+ assert ! ( !cargo_content. contains( r#"[lib]"# ) ) ;
236
+ assert_that ( & paths:: root ( ) . join ( "foo/src/lib.rs" ) , existing_file ( ) ) ;
237
+ }
238
+
216
239
}
217
240
218
241
#[ test]
219
242
fn lib_already_exists_src ( ) {
220
- lib_already_exists ( "src/lib.rs" )
243
+ lib_already_exists ( "src/lib.rs" , false )
221
244
}
222
245
223
246
#[ test]
224
247
fn lib_already_exists_nosrc ( ) {
225
- lib_already_exists ( "lib.rs" )
248
+ lib_already_exists ( "lib.rs" , true )
249
+ }
250
+
251
+ #[ test]
252
+ fn no_lib_already_exists_src_add_lib_section ( ) {
253
+ lib_already_exists ( "src/foo.rs" , true )
254
+ }
255
+
256
+ #[ test]
257
+ fn no_lib_already_exists_nosrc_add_lib_section ( ) {
258
+ lib_already_exists ( "foo.rs" , true )
226
259
}
227
260
228
261
#[ test]
0 commit comments