Skip to content

Commit 00b21c8

Browse files
Add tests for documenting private items by default in binary crates
1 parent e7ee237 commit 00b21c8

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

tests/testsuite/doc.rs

+105
Original file line numberDiff line numberDiff line change
@@ -1401,3 +1401,108 @@ fn doc_example() {
14011401
.join("fn.x.html")
14021402
.exists());
14031403
}
1404+
1405+
#[cargo_test]
1406+
fn bin_private_items() {
1407+
let p = project()
1408+
.file(
1409+
"Cargo.toml",
1410+
r#"
1411+
[package]
1412+
name = "foo"
1413+
version = "0.0.1"
1414+
authors = []
1415+
"#,
1416+
)
1417+
.file(
1418+
"src/main.rs",
1419+
"
1420+
pub fn foo_pub() {}
1421+
fn foo_priv() {}
1422+
struct FooStruct;
1423+
enum FooEnum {}
1424+
trait FooTrait {}
1425+
type FooType = u32;
1426+
mod foo_mod {}
1427+
1428+
",
1429+
)
1430+
.build();
1431+
1432+
p.cargo("doc")
1433+
.with_stderr(
1434+
"\
1435+
[DOCUMENTING] foo v0.0.1 ([CWD])
1436+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1437+
",
1438+
)
1439+
.run();
1440+
1441+
assert!(p.root().join("target/doc/foo/index.html").is_file());
1442+
assert!(p.root().join("target/doc/foo/fn.foo_pub.html").is_file());
1443+
assert!(p.root().join("target/doc/foo/fn.foo_priv.html").is_file());
1444+
assert!(p
1445+
.root()
1446+
.join("target/doc/foo/struct.FooStruct.html")
1447+
.is_file());
1448+
assert!(p.root().join("target/doc/foo/enum.FooEnum.html").is_file());
1449+
assert!(p
1450+
.root()
1451+
.join("target/doc/foo/trait.FooTrait.html")
1452+
.is_file());
1453+
assert!(p.root().join("target/doc/foo/type.FooType.html").is_file());
1454+
assert!(p.root().join("target/doc/foo/foo_mod/index.html").is_file());
1455+
}
1456+
1457+
#[cargo_test]
1458+
fn bin_private_items_deps() {
1459+
let p = project()
1460+
.file(
1461+
"Cargo.toml",
1462+
r#"
1463+
[package]
1464+
name = "foo"
1465+
version = "0.0.1"
1466+
authors = []
1467+
1468+
[dependencies.bar]
1469+
path = "bar"
1470+
"#,
1471+
)
1472+
.file(
1473+
"src/main.rs",
1474+
"
1475+
fn foo_priv() {}
1476+
pub fn foo_pub() {}
1477+
",
1478+
)
1479+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
1480+
.file(
1481+
"bar/src/lib.rs",
1482+
"
1483+
#[allow(dead_code)]
1484+
fn bar_priv() {}
1485+
pub fn bar_pub() {}
1486+
",
1487+
)
1488+
.build();
1489+
1490+
p.cargo("doc")
1491+
.with_stderr_unordered(
1492+
"\
1493+
[DOCUMENTING] bar v0.0.1 ([..])
1494+
[CHECKING] bar v0.0.1 ([..])
1495+
[DOCUMENTING] foo v0.0.1 ([CWD])
1496+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1497+
",
1498+
)
1499+
.run();
1500+
1501+
assert!(p.root().join("target/doc/foo/index.html").is_file());
1502+
assert!(p.root().join("target/doc/foo/fn.foo_pub.html").is_file());
1503+
assert!(p.root().join("target/doc/foo/fn.foo_priv.html").is_file());
1504+
1505+
assert!(p.root().join("target/doc/bar/index.html").is_file());
1506+
assert!(p.root().join("target/doc/bar/fn.bar_pub.html").is_file());
1507+
assert!(!p.root().join("target/doc/bar/fn.bar_priv.html").exists());
1508+
}

0 commit comments

Comments
 (0)