@@ -285,6 +285,67 @@ test!(gitignore_appended_not_replaced {
285285 assert!( contents. contains( r#"qqqqqq"# ) ) ;
286286} ) ;
287287
288+ test ! ( cargo_lock_gitignored_if_lib1 {
289+ fs:: create_dir( & paths:: root( ) . join( ".git" ) ) . unwrap( ) ;
290+
291+ assert_that( cargo_process( "init" ) . arg( "--vcs" ) . arg( "git" )
292+ . env( "USER" , "foo" ) ,
293+ execs( ) . with_status( 0 ) ) ;
294+
295+ assert_that( & paths:: root( ) . join( ".gitignore" ) , existing_file( ) ) ;
296+
297+ let mut contents = String :: new( ) ;
298+ File :: open( & paths:: root( ) . join( ".gitignore" ) ) . unwrap( ) . read_to_string( & mut contents) . unwrap( ) ;
299+ assert!( contents. contains( r#"Cargo.lock"# ) ) ;
300+ } ) ;
301+
302+ test ! ( cargo_lock_gitignored_if_lib2 {
303+ fs:: create_dir( & paths:: root( ) . join( ".git" ) ) . unwrap( ) ;
304+
305+ File :: create( & paths:: root( ) . join( "lib.rs" ) ) . unwrap( ) . write_all( br#""# ) . unwrap( ) ;
306+
307+ assert_that( cargo_process( "init" ) . arg( "--vcs" ) . arg( "git" )
308+ . env( "USER" , "foo" ) ,
309+ execs( ) . with_status( 0 ) ) ;
310+
311+ assert_that( & paths:: root( ) . join( ".gitignore" ) , existing_file( ) ) ;
312+
313+ let mut contents = String :: new( ) ;
314+ File :: open( & paths:: root( ) . join( ".gitignore" ) ) . unwrap( ) . read_to_string( & mut contents) . unwrap( ) ;
315+ assert!( contents. contains( r#"Cargo.lock"# ) ) ;
316+ } ) ;
317+
318+ test ! ( cargo_lock_not_gitignored_if_bin1 {
319+ fs:: create_dir( & paths:: root( ) . join( ".git" ) ) . unwrap( ) ;
320+
321+ assert_that( cargo_process( "init" ) . arg( "--vcs" ) . arg( "git" )
322+ . arg( "--bin" )
323+ . env( "USER" , "foo" ) ,
324+ execs( ) . with_status( 0 ) ) ;
325+
326+ assert_that( & paths:: root( ) . join( ".gitignore" ) , existing_file( ) ) ;
327+
328+ let mut contents = String :: new( ) ;
329+ File :: open( & paths:: root( ) . join( ".gitignore" ) ) . unwrap( ) . read_to_string( & mut contents) . unwrap( ) ;
330+ assert!( !contents. contains( r#"Cargo.lock"# ) ) ;
331+ } ) ;
332+
333+ test ! ( cargo_lock_not_gitignored_if_bin2 {
334+ fs:: create_dir( & paths:: root( ) . join( ".git" ) ) . unwrap( ) ;
335+
336+ File :: create( & paths:: root( ) . join( "main.rs" ) ) . unwrap( ) . write_all( br#""# ) . unwrap( ) ;
337+
338+ assert_that( cargo_process( "init" ) . arg( "--vcs" ) . arg( "git" )
339+ . env( "USER" , "foo" ) ,
340+ execs( ) . with_status( 0 ) ) ;
341+
342+ assert_that( & paths:: root( ) . join( ".gitignore" ) , existing_file( ) ) ;
343+
344+ let mut contents = String :: new( ) ;
345+ File :: open( & paths:: root( ) . join( ".gitignore" ) ) . unwrap( ) . read_to_string( & mut contents) . unwrap( ) ;
346+ assert!( !contents. contains( r#"Cargo.lock"# ) ) ;
347+ } ) ;
348+
288349test ! ( with_argument {
289350 assert_that( cargo_process( "init" ) . arg( "foo" ) . arg( "--vcs" ) . arg( "none" )
290351 . env( "USER" , "foo" ) ,
0 commit comments