@@ -702,8 +702,9 @@ to proceed despite this, pass the `--allow-dirty` flag
702702#[ test]
703703fn generated_manifest ( ) {
704704 Package :: new ( "abc" , "1.0.0" ) . publish ( ) ;
705- Package :: new ( "def" , "1.0.0" ) . publish ( ) ;
705+ Package :: new ( "def" , "1.0.0" ) . alternative ( true ) . publish ( ) ;
706706 Package :: new ( "ghi" , "1.0.0" ) . publish ( ) ;
707+
707708 let p = project ( "foo" )
708709 . file ( "Cargo.toml" , r#"
709710 cargo-features = ["alternative-registries"]
@@ -995,3 +996,160 @@ Caused by:
995996consider adding `cargo-features = [\" epoch\" ]` to the manifest
996997" ) ) ) ;
997998}
999+
1000+ #[ test]
1001+ fn package_lockfile ( ) {
1002+ let p = project ( "foo" )
1003+ . file ( "Cargo.toml" , r#"
1004+ cargo-features = ["publish-lockfile"]
1005+
1006+ [project]
1007+ name = "foo"
1008+ version = "0.0.1"
1009+ authors = []
1010+ license = "MIT"
1011+ description = "foo"
1012+ publish-lockfile = true
1013+ "# )
1014+ . file ( "src/main.rs" , "fn main() {}" )
1015+ . build ( ) ;
1016+
1017+ assert_that ( p. cargo ( "package" ) . masquerade_as_nightly_cargo ( ) ,
1018+ execs ( ) . with_status ( 0 ) . with_stderr ( & format ! ( "\
1019+ [WARNING] manifest has no documentation[..]
1020+ See [..]
1021+ [PACKAGING] foo v0.0.1 ({dir})
1022+ [VERIFYING] foo v0.0.1 ({dir})
1023+ [COMPILING] foo v0.0.1 ({dir}[..])
1024+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1025+ " ,
1026+ dir = p. url( ) ) ) ) ;
1027+ assert_that ( & p. root ( ) . join ( "target/package/foo-0.0.1.crate" ) , existing_file ( ) ) ;
1028+ assert_that ( p. cargo ( "package" ) . arg ( "-l" ) . masquerade_as_nightly_cargo ( ) ,
1029+ execs ( ) . with_status ( 0 ) . with_stdout ( "\
1030+ Cargo.lock
1031+ Cargo.toml
1032+ src[/]main.rs
1033+ " ) ) ;
1034+ assert_that ( p. cargo ( "package" ) . masquerade_as_nightly_cargo ( ) ,
1035+ execs ( ) . with_status ( 0 ) . with_stdout ( "" ) ) ;
1036+
1037+ let f = File :: open ( & p. root ( ) . join ( "target/package/foo-0.0.1.crate" ) ) . unwrap ( ) ;
1038+ let mut rdr = GzDecoder :: new ( f) ;
1039+ let mut contents = Vec :: new ( ) ;
1040+ rdr. read_to_end ( & mut contents) . unwrap ( ) ;
1041+ let mut ar = Archive :: new ( & contents[ ..] ) ;
1042+ for f in ar. entries ( ) . unwrap ( ) {
1043+ let f = f. unwrap ( ) ;
1044+ let fname = f. header ( ) . path_bytes ( ) ;
1045+ let fname = & * fname;
1046+ assert ! ( fname == b"foo-0.0.1/Cargo.toml" ||
1047+ fname == b"foo-0.0.1/Cargo.toml.orig" ||
1048+ fname == b"foo-0.0.1/Cargo.lock" ||
1049+ fname == b"foo-0.0.1/src/main.rs" ,
1050+ "unexpected filename: {:?}" , f. header( ) . path( ) )
1051+ }
1052+ }
1053+
1054+ #[ test]
1055+ fn package_lockfile_git_repo ( ) {
1056+ let p = project ( "foo" ) . build ( ) ;
1057+
1058+ // Create a Git repository containing a minimal Rust project.
1059+ let _ = git:: repo ( & paths:: root ( ) . join ( "foo" ) )
1060+ . file ( "Cargo.toml" , r#"
1061+ cargo-features = ["publish-lockfile"]
1062+
1063+ [project]
1064+ name = "foo"
1065+ version = "0.0.1"
1066+ license = "MIT"
1067+ description = "foo"
1068+ documentation = "foo"
1069+ homepage = "foo"
1070+ repository = "foo"
1071+ publish-lockfile = true
1072+ "# )
1073+ . file ( "src/main.rs" , "fn main() {}" )
1074+ . build ( ) ;
1075+ assert_that ( p. cargo ( "package" ) . arg ( "-l" ) . masquerade_as_nightly_cargo ( ) ,
1076+ execs ( ) . with_status ( 0 ) . with_stdout ( "\
1077+ Cargo.lock
1078+ Cargo.toml
1079+ src/main.rs
1080+ " ) ) ;
1081+ }
1082+
1083+ #[ test]
1084+ fn no_lock_file_with_library ( ) {
1085+ let p = project ( "foo" )
1086+ . file ( "Cargo.toml" , r#"
1087+ cargo-features = ["publish-lockfile"]
1088+
1089+ [project]
1090+ name = "foo"
1091+ version = "0.0.1"
1092+ authors = []
1093+ license = "MIT"
1094+ description = "foo"
1095+ publish-lockfile = true
1096+ "# )
1097+ . file ( "src/lib.rs" , "" )
1098+ . build ( ) ;
1099+
1100+ assert_that ( p. cargo ( "package" ) . masquerade_as_nightly_cargo ( ) ,
1101+ execs ( ) . with_status ( 0 ) ) ;
1102+
1103+ let f = File :: open ( & p. root ( ) . join ( "target/package/foo-0.0.1.crate" ) ) . unwrap ( ) ;
1104+ let mut rdr = GzDecoder :: new ( f) ;
1105+ let mut contents = Vec :: new ( ) ;
1106+ rdr. read_to_end ( & mut contents) . unwrap ( ) ;
1107+ let mut ar = Archive :: new ( & contents[ ..] ) ;
1108+ for f in ar. entries ( ) . unwrap ( ) {
1109+ let f = f. unwrap ( ) ;
1110+ let fname = f. header ( ) . path ( ) . unwrap ( ) ;
1111+ assert ! ( !fname. ends_with( "Cargo.lock" ) ) ;
1112+ }
1113+ }
1114+
1115+ #[ test]
1116+ fn lock_file_and_workspace ( ) {
1117+ let p = project ( "foo" )
1118+ . file ( "Cargo.toml" , r#"
1119+ [workspace]
1120+ members = ["foo"]
1121+ "# )
1122+ . file ( "foo/Cargo.toml" , r#"
1123+ cargo-features = ["publish-lockfile"]
1124+
1125+ [package]
1126+ name = "foo"
1127+ version = "0.0.1"
1128+ authors = []
1129+ license = "MIT"
1130+ description = "foo"
1131+ publish-lockfile = true
1132+ "# )
1133+ . file ( "foo/src/main.rs" , "fn main() {}" )
1134+ . build ( ) ;
1135+
1136+ assert_that ( p. cargo ( "package" )
1137+ . cwd ( p. root ( ) . join ( "foo" ) )
1138+ . masquerade_as_nightly_cargo ( ) ,
1139+ execs ( ) . with_status ( 0 ) ) ;
1140+
1141+ let f = File :: open ( & p. root ( ) . join ( "target/package/foo-0.0.1.crate" ) ) . unwrap ( ) ;
1142+ let mut rdr = GzDecoder :: new ( f) ;
1143+ let mut contents = Vec :: new ( ) ;
1144+ rdr. read_to_end ( & mut contents) . unwrap ( ) ;
1145+ let mut ar = Archive :: new ( & contents[ ..] ) ;
1146+ assert ! (
1147+ ar. entries( ) . unwrap( )
1148+ . into_iter( )
1149+ . any( |f|{
1150+ let f = f. unwrap( ) ;
1151+ let fname = f. header( ) . path( ) . unwrap( ) ;
1152+ fname. ends_with( "Cargo.lock" )
1153+ } )
1154+ ) ;
1155+ }
0 commit comments