Skip to content

Commit 33c9dc2

Browse files
committed
Add a bunch tests for [doc-dependencies]
1 parent 65c0264 commit 33c9dc2

12 files changed

+805
-1
lines changed

tests/testsuite/build.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,60 @@ fn cargo_platform_specific_dependency() {
28412841
p.cargo("test").run();
28422842
}
28432843

2844+
#[cargo_test]
2845+
fn cargo_platform_specific_dependency_with_doc() {
2846+
let host = rustc_host();
2847+
let p = project()
2848+
.file(
2849+
"Cargo.toml",
2850+
&format!(
2851+
r#"
2852+
cargo-features = ["doc-dependencies"]
2853+
2854+
[project]
2855+
name = "foo"
2856+
version = "0.5.0"
2857+
authors = ["[email protected]"]
2858+
build = "build.rs"
2859+
2860+
[target.{host}.dependencies]
2861+
dep = {{ path = "dep" }}
2862+
[target.{host}.build-dependencies]
2863+
build = {{ path = "build" }}
2864+
[target.{host}.dev-dependencies]
2865+
dev = {{ path = "dev" }}
2866+
[target.{host}.doc-dependencies]
2867+
doc = {{ path = "doc" }}
2868+
"#,
2869+
host = host
2870+
),
2871+
)
2872+
.file("src/main.rs", "extern crate dep; fn main() { dep::dep() }")
2873+
.file(
2874+
"tests/foo.rs",
2875+
"extern crate dev; #[test] fn foo() { dev::dev() }",
2876+
)
2877+
.file(
2878+
"build.rs",
2879+
"extern crate build; fn main() { build::build(); }",
2880+
)
2881+
.file("dep/Cargo.toml", &basic_manifest("dep", "0.5.0"))
2882+
.file("dep/src/lib.rs", "pub fn dep() {}")
2883+
.file("build/Cargo.toml", &basic_manifest("build", "0.5.0"))
2884+
.file("build/src/lib.rs", "pub fn build() {}")
2885+
.file("dev/Cargo.toml", &basic_manifest("dev", "0.5.0"))
2886+
.file("dev/src/lib.rs", "pub fn dev() {}")
2887+
.file("doc/Cargo.toml", &basic_manifest("doc", "0.5.0"))
2888+
.file("doc/src/lib.rs", "pub fn doc() {}")
2889+
.build();
2890+
2891+
p.cargo("build").masquerade_as_nightly_cargo().run();
2892+
2893+
assert!(p.bin("foo").is_file());
2894+
p.cargo("test").masquerade_as_nightly_cargo().run();
2895+
p.cargo("doc").masquerade_as_nightly_cargo().run();
2896+
}
2897+
28442898
#[cargo_test]
28452899
fn bad_platform_specific_dependency() {
28462900
let p = project()
@@ -5106,6 +5160,45 @@ required by package `bar v0.1.0 ([..]/foo)`
51065160
.run();
51075161
}
51085162

5163+
#[cargo_test]
5164+
fn avoid_doc_deps() {
5165+
Package::new("foo", "1.0.0").publish();
5166+
let p = project()
5167+
.file(
5168+
"Cargo.toml",
5169+
r#"
5170+
cargo-features = ["doc-dependencies"]
5171+
5172+
[package]
5173+
name = "bar"
5174+
version = "0.1.0"
5175+
authors = []
5176+
5177+
[doc-dependencies]
5178+
baz = "1.0.0"
5179+
"#,
5180+
)
5181+
.file("src/main.rs", "fn main() {}")
5182+
.build();
5183+
5184+
p.cargo("doc")
5185+
.masquerade_as_nightly_cargo()
5186+
.with_status(101)
5187+
.with_stderr(
5188+
"\
5189+
[UPDATING] [..]
5190+
[ERROR] no matching package named `baz` found
5191+
location searched: registry `crates-io`
5192+
required by package `bar v0.1.0 ([..]/foo)`
5193+
",
5194+
)
5195+
.run();
5196+
// FIXME: Should be something like -Zavoid-doc-deps
5197+
p.cargo("build -Zavoid-dev-deps")
5198+
.masquerade_as_nightly_cargo()
5199+
.run();
5200+
}
5201+
51095202
#[cargo_test]
51105203
fn default_cargo_config_jobs() {
51115204
let p = project()

tests/testsuite/build_script.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,41 @@ fn test_dev_dep_build_script() {
21662166
p.cargo("test").run();
21672167
}
21682168

2169+
#[cargo_test]
2170+
fn test_doc_dep_build_script() {
2171+
let p = project()
2172+
.file(
2173+
"Cargo.toml",
2174+
r#"
2175+
cargo-features = ["doc-dependencies"]
2176+
2177+
[project]
2178+
name = "foo"
2179+
version = "0.5.0"
2180+
authors = []
2181+
2182+
[doc-dependencies.a]
2183+
path = "a"
2184+
"#,
2185+
)
2186+
.file("src/lib.rs", "")
2187+
.file(
2188+
"a/Cargo.toml",
2189+
r#"
2190+
[project]
2191+
name = "a"
2192+
version = "0.5.0"
2193+
authors = []
2194+
build = "build.rs"
2195+
"#,
2196+
)
2197+
.file("a/build.rs", "fn main() {}")
2198+
.file("a/src/lib.rs", "")
2199+
.build();
2200+
2201+
p.cargo("doc").masquerade_as_nightly_cargo().run();
2202+
}
2203+
21692204
#[cargo_test]
21702205
fn build_script_with_dynamic_native_dependency() {
21712206
let build = project()
@@ -4655,6 +4690,47 @@ fn dev_dep_with_links() {
46554690
p.cargo("check --tests").run()
46564691
}
46574692

4693+
#[ignore] // FIXME: overflow it's stack
4694+
#[cargo_test]
4695+
fn doc_dep_with_links() {
4696+
let p = project()
4697+
.file(
4698+
"Cargo.toml",
4699+
r#"
4700+
cargo-features = ["doc-dependencies"]
4701+
4702+
[package]
4703+
name = "foo"
4704+
version = "0.1.0"
4705+
authors = []
4706+
links = "x"
4707+
4708+
[doc-dependencies]
4709+
bar = { path = "./bar" }
4710+
"#,
4711+
)
4712+
.file("build.rs", "fn main() {}")
4713+
.file("src/lib.rs", "")
4714+
.file(
4715+
"bar/Cargo.toml",
4716+
r#"
4717+
[package]
4718+
name = "bar"
4719+
version = "0.1.0"
4720+
authors = []
4721+
links = "y"
4722+
4723+
[dependencies]
4724+
foo = { path = ".." }
4725+
"#,
4726+
)
4727+
.file("bar/build.rs", "fn main() {}")
4728+
.file("bar/src/lib.rs", "")
4729+
.build();
4730+
4731+
p.cargo("doc").masquerade_as_nightly_cargo().run()
4732+
}
4733+
46584734
#[cargo_test]
46594735
fn rerun_if_directory() {
46604736
if !symlink_supported() {

tests/testsuite/doc.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,47 @@ fn simple() {
3838
assert!(p.root().join("target/doc/foo/index.html").is_file());
3939
}
4040

41+
#[cargo_test]
42+
fn simple_with_doc_deps() {
43+
let p = project()
44+
.file(
45+
"Cargo.toml",
46+
r#"
47+
cargo-features = ["doc-dependencies"]
48+
49+
[package]
50+
name = "foo"
51+
version = "0.0.1"
52+
authors = []
53+
build = "build.rs"
54+
55+
[doc-dependencies]
56+
bar = { path = "bar/" }
57+
"#,
58+
)
59+
.file("build.rs", "fn main() {}")
60+
.file("src/lib.rs", "pub fn foo() {}")
61+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
62+
.file("bar/src/lib.rs", "pub fn bar() {}")
63+
.build();
64+
65+
p.cargo("doc")
66+
.masquerade_as_nightly_cargo()
67+
.with_stderr(
68+
"\
69+
[..] foo v0.0.1 ([CWD])
70+
[..] bar v0.0.1 ([CWD]/bar)
71+
[..] bar v0.0.1 ([CWD]/bar)
72+
[..] foo v0.0.1 ([CWD])
73+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
74+
",
75+
)
76+
.run();
77+
assert!(p.root().join("target/doc").is_dir());
78+
assert!(p.root().join("target/doc/foo/index.html").is_file());
79+
assert!(p.root().join("target/doc/bar/index.html").is_file());
80+
}
81+
4182
#[cargo_test]
4283
fn doc_no_libs() {
4384
let p = project()

tests/testsuite/features.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,41 @@ Caused by:
194194
.run();
195195
}
196196

197+
#[cargo_test]
198+
fn invalid5_alt() {
199+
let p = project()
200+
.file(
201+
"Cargo.toml",
202+
r#"
203+
cargo-features = ["doc-dependencies"]
204+
205+
[project]
206+
name = "foo"
207+
version = "0.0.1"
208+
authors = []
209+
210+
[doc-dependencies.bar]
211+
path = "bar"
212+
optional = true
213+
"#,
214+
)
215+
.file("src/main.rs", "")
216+
.build();
217+
218+
p.cargo("build")
219+
.masquerade_as_nightly_cargo()
220+
.with_status(101)
221+
.with_stderr(
222+
"\
223+
[ERROR] failed to parse manifest at `[..]`
224+
225+
Caused by:
226+
doc-dependencies are not allowed to be optional: `bar`
227+
",
228+
)
229+
.run();
230+
}
231+
197232
#[cargo_test]
198233
fn invalid6() {
199234
let p = project()
@@ -1098,6 +1133,41 @@ fn optional_and_dev_dep() {
10981133
.run();
10991134
}
11001135

1136+
#[cargo_test]
1137+
fn optional_and_doc_dep() {
1138+
let p = project()
1139+
.file(
1140+
"Cargo.toml",
1141+
r#"
1142+
cargo-features = ["doc-dependencies"]
1143+
1144+
[package]
1145+
name = "test"
1146+
version = "0.1.0"
1147+
authors = []
1148+
1149+
[dependencies]
1150+
foo = { path = "foo", optional = true }
1151+
[doc-dependencies]
1152+
foo = { path = "foo" }
1153+
"#,
1154+
)
1155+
.file("src/lib.rs", "")
1156+
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
1157+
.file("foo/src/lib.rs", "")
1158+
.build();
1159+
1160+
p.cargo("build")
1161+
.masquerade_as_nightly_cargo()
1162+
.with_stderr(
1163+
"\
1164+
[COMPILING] test v0.1.0 ([..])
1165+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1166+
",
1167+
)
1168+
.run();
1169+
}
1170+
11011171
#[cargo_test]
11021172
fn activating_feature_activates_dep() {
11031173
let p = project()
@@ -1411,6 +1481,37 @@ fn only_dep_is_optional() {
14111481
p.cargo("build").run();
14121482
}
14131483

1484+
#[cargo_test]
1485+
fn only_dep_is_optional_alt() {
1486+
Package::new("bar", "0.1.0").publish();
1487+
1488+
let p = project()
1489+
.file(
1490+
"Cargo.toml",
1491+
r#"
1492+
cargo-features = ["doc-dependencies"]
1493+
1494+
[project]
1495+
name = "foo"
1496+
version = "0.0.1"
1497+
authors = []
1498+
1499+
[features]
1500+
foo = ['bar']
1501+
1502+
[dependencies]
1503+
bar = { version = "0.1", optional = true }
1504+
1505+
[doc-dependencies]
1506+
bar = "0.1"
1507+
"#,
1508+
)
1509+
.file("src/main.rs", "fn main() {}")
1510+
.build();
1511+
1512+
p.cargo("build").masquerade_as_nightly_cargo().run();
1513+
}
1514+
14141515
#[cargo_test]
14151516
fn all_features_all_crates() {
14161517
Package::new("bar", "0.1.0").publish();

0 commit comments

Comments
 (0)