Skip to content

Commit ebb5764

Browse files
committed
Move publish-lockfile tests to a dedicated file.
1 parent 73ed6a5 commit ebb5764

File tree

3 files changed

+172
-167
lines changed

3 files changed

+172
-167
lines changed

tests/testsuite/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ mod profile_overrides;
6868
mod profile_targets;
6969
mod profiles;
7070
mod publish;
71+
mod publish_lockfile;
7172
mod read_manifest;
7273
mod registry;
7374
mod rename_deps;

tests/testsuite/package.rs

Lines changed: 0 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,173 +1018,6 @@ Caused by:
10181018
.run();
10191019
}
10201020

1021-
#[test]
1022-
fn package_lockfile() {
1023-
let p = project()
1024-
.file(
1025-
"Cargo.toml",
1026-
r#"
1027-
cargo-features = ["publish-lockfile"]
1028-
1029-
[project]
1030-
name = "foo"
1031-
version = "0.0.1"
1032-
authors = []
1033-
license = "MIT"
1034-
description = "foo"
1035-
publish-lockfile = true
1036-
"#,
1037-
)
1038-
.file("src/main.rs", "fn main() {}")
1039-
.build();
1040-
1041-
p.cargo("package")
1042-
.masquerade_as_nightly_cargo()
1043-
.with_stderr(
1044-
"\
1045-
[WARNING] manifest has no documentation[..]
1046-
See [..]
1047-
[PACKAGING] foo v0.0.1 ([CWD])
1048-
[VERIFYING] foo v0.0.1 ([CWD])
1049-
[COMPILING] foo v0.0.1 ([CWD][..])
1050-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1051-
",
1052-
)
1053-
.run();
1054-
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
1055-
p.cargo("package -l")
1056-
.masquerade_as_nightly_cargo()
1057-
.with_stdout(
1058-
"\
1059-
Cargo.lock
1060-
Cargo.toml
1061-
src/main.rs
1062-
",
1063-
)
1064-
.run();
1065-
p.cargo("package")
1066-
.masquerade_as_nightly_cargo()
1067-
.with_stdout("")
1068-
.run();
1069-
1070-
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
1071-
validate_crate_contents(
1072-
f,
1073-
"foo-0.0.1.crate",
1074-
&["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"],
1075-
&[],
1076-
);
1077-
}
1078-
1079-
#[test]
1080-
fn package_lockfile_git_repo() {
1081-
let p = project().build();
1082-
1083-
// Create a Git repository containing a minimal Rust project.
1084-
let _ = git::repo(&paths::root().join("foo"))
1085-
.file(
1086-
"Cargo.toml",
1087-
r#"
1088-
cargo-features = ["publish-lockfile"]
1089-
1090-
[project]
1091-
name = "foo"
1092-
version = "0.0.1"
1093-
license = "MIT"
1094-
description = "foo"
1095-
documentation = "foo"
1096-
homepage = "foo"
1097-
repository = "foo"
1098-
publish-lockfile = true
1099-
"#,
1100-
)
1101-
.file("src/main.rs", "fn main() {}")
1102-
.build();
1103-
p.cargo("package -l")
1104-
.masquerade_as_nightly_cargo()
1105-
.with_stdout(
1106-
"\
1107-
.cargo_vcs_info.json
1108-
Cargo.lock
1109-
Cargo.toml
1110-
src/main.rs
1111-
",
1112-
)
1113-
.run();
1114-
}
1115-
1116-
#[test]
1117-
fn no_lock_file_with_library() {
1118-
let p = project()
1119-
.file(
1120-
"Cargo.toml",
1121-
r#"
1122-
cargo-features = ["publish-lockfile"]
1123-
1124-
[project]
1125-
name = "foo"
1126-
version = "0.0.1"
1127-
authors = []
1128-
license = "MIT"
1129-
description = "foo"
1130-
publish-lockfile = true
1131-
"#,
1132-
)
1133-
.file("src/lib.rs", "")
1134-
.build();
1135-
1136-
p.cargo("package").masquerade_as_nightly_cargo().run();
1137-
1138-
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
1139-
validate_crate_contents(
1140-
f,
1141-
"foo-0.0.1.crate",
1142-
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
1143-
&[],
1144-
);
1145-
}
1146-
1147-
#[test]
1148-
fn lock_file_and_workspace() {
1149-
let p = project()
1150-
.file(
1151-
"Cargo.toml",
1152-
r#"
1153-
[workspace]
1154-
members = ["foo"]
1155-
"#,
1156-
)
1157-
.file(
1158-
"foo/Cargo.toml",
1159-
r#"
1160-
cargo-features = ["publish-lockfile"]
1161-
1162-
[package]
1163-
name = "foo"
1164-
version = "0.0.1"
1165-
authors = []
1166-
license = "MIT"
1167-
description = "foo"
1168-
publish-lockfile = true
1169-
"#,
1170-
)
1171-
.file("foo/src/main.rs", "fn main() {}")
1172-
.build();
1173-
1174-
p.cargo("package")
1175-
.cwd("foo")
1176-
.masquerade_as_nightly_cargo()
1177-
.run();
1178-
1179-
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
1180-
validate_crate_contents(
1181-
f,
1182-
"foo-0.0.1.crate",
1183-
&["Cargo.toml", "Cargo.toml.orig", "src/main.rs", "Cargo.lock"],
1184-
&[],
1185-
);
1186-
}
1187-
11881021
#[test]
11891022
fn do_not_package_if_src_was_modified() {
11901023
let p = project()

tests/testsuite/publish_lockfile.rs

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
use std;
2+
use std::fs::File;
3+
4+
use crate::support::{git, paths, project, publish::validate_crate_contents};
5+
6+
#[test]
7+
fn package_lockfile() {
8+
let p = project()
9+
.file(
10+
"Cargo.toml",
11+
r#"
12+
cargo-features = ["publish-lockfile"]
13+
14+
[project]
15+
name = "foo"
16+
version = "0.0.1"
17+
authors = []
18+
license = "MIT"
19+
description = "foo"
20+
publish-lockfile = true
21+
"#,
22+
)
23+
.file("src/main.rs", "fn main() {}")
24+
.build();
25+
26+
p.cargo("package")
27+
.masquerade_as_nightly_cargo()
28+
.with_stderr(
29+
"\
30+
[WARNING] manifest has no documentation[..]
31+
See [..]
32+
[PACKAGING] foo v0.0.1 ([CWD])
33+
[VERIFYING] foo v0.0.1 ([CWD])
34+
[COMPILING] foo v0.0.1 ([CWD][..])
35+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
36+
",
37+
)
38+
.run();
39+
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
40+
p.cargo("package -l")
41+
.masquerade_as_nightly_cargo()
42+
.with_stdout(
43+
"\
44+
Cargo.lock
45+
Cargo.toml
46+
src/main.rs
47+
",
48+
)
49+
.run();
50+
p.cargo("package")
51+
.masquerade_as_nightly_cargo()
52+
.with_stdout("")
53+
.run();
54+
55+
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
56+
validate_crate_contents(
57+
f,
58+
"foo-0.0.1.crate",
59+
&["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"],
60+
&[],
61+
);
62+
}
63+
64+
#[test]
65+
fn package_lockfile_git_repo() {
66+
let p = project().build();
67+
68+
// Create a Git repository containing a minimal Rust project.
69+
let _ = git::repo(&paths::root().join("foo"))
70+
.file(
71+
"Cargo.toml",
72+
r#"
73+
cargo-features = ["publish-lockfile"]
74+
75+
[project]
76+
name = "foo"
77+
version = "0.0.1"
78+
license = "MIT"
79+
description = "foo"
80+
documentation = "foo"
81+
homepage = "foo"
82+
repository = "foo"
83+
publish-lockfile = true
84+
"#,
85+
)
86+
.file("src/main.rs", "fn main() {}")
87+
.build();
88+
p.cargo("package -l")
89+
.masquerade_as_nightly_cargo()
90+
.with_stdout(
91+
"\
92+
.cargo_vcs_info.json
93+
Cargo.lock
94+
Cargo.toml
95+
src/main.rs
96+
",
97+
)
98+
.run();
99+
}
100+
101+
#[test]
102+
fn no_lock_file_with_library() {
103+
let p = project()
104+
.file(
105+
"Cargo.toml",
106+
r#"
107+
cargo-features = ["publish-lockfile"]
108+
109+
[project]
110+
name = "foo"
111+
version = "0.0.1"
112+
authors = []
113+
license = "MIT"
114+
description = "foo"
115+
publish-lockfile = true
116+
"#,
117+
)
118+
.file("src/lib.rs", "")
119+
.build();
120+
121+
p.cargo("package").masquerade_as_nightly_cargo().run();
122+
123+
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
124+
validate_crate_contents(
125+
f,
126+
"foo-0.0.1.crate",
127+
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
128+
&[],
129+
);
130+
}
131+
132+
#[test]
133+
fn lock_file_and_workspace() {
134+
let p = project()
135+
.file(
136+
"Cargo.toml",
137+
r#"
138+
[workspace]
139+
members = ["foo"]
140+
"#,
141+
)
142+
.file(
143+
"foo/Cargo.toml",
144+
r#"
145+
cargo-features = ["publish-lockfile"]
146+
147+
[package]
148+
name = "foo"
149+
version = "0.0.1"
150+
authors = []
151+
license = "MIT"
152+
description = "foo"
153+
publish-lockfile = true
154+
"#,
155+
)
156+
.file("foo/src/main.rs", "fn main() {}")
157+
.build();
158+
159+
p.cargo("package")
160+
.cwd("foo")
161+
.masquerade_as_nightly_cargo()
162+
.run();
163+
164+
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
165+
validate_crate_contents(
166+
f,
167+
"foo-0.0.1.crate",
168+
&["Cargo.toml", "Cargo.toml.orig", "src/main.rs", "Cargo.lock"],
169+
&[],
170+
);
171+
}

0 commit comments

Comments
 (0)