|
1 | 1 | //! Tests for the `cargo rustdoc` command. |
2 | 2 |
|
| 3 | +use std::fs; |
| 4 | + |
3 | 5 | use crate::prelude::*; |
4 | 6 | use cargo_test_support::str; |
5 | 7 | use cargo_test_support::{basic_manifest, cross_compile, project}; |
@@ -322,3 +324,99 @@ fn fail_with_glob() { |
322 | 324 | "#]]) |
323 | 325 | .run(); |
324 | 326 | } |
| 327 | + |
| 328 | +#[cargo_test(nightly, reason = "--output-format is unstable")] |
| 329 | +fn rustdoc_json_same_crate_different_version() { |
| 330 | + let entry = project() |
| 331 | + .file( |
| 332 | + "Cargo.toml", |
| 333 | + r#" |
| 334 | + [package] |
| 335 | + name = "entry" |
| 336 | + version = "0.1.0" |
| 337 | + edition = "2021" |
| 338 | +
|
| 339 | + [dependencies] |
| 340 | + dep_v1 = { path = "../dep_v1", package = "dep" } |
| 341 | + dep_v2 = { path = "../dep_v2", package = "dep" } |
| 342 | + "#, |
| 343 | + ) |
| 344 | + .file("src/lib.rs", "pub fn entry() {}") |
| 345 | + .build(); |
| 346 | + |
| 347 | + let _dep_v1 = project() |
| 348 | + .at("dep_v1") |
| 349 | + .file( |
| 350 | + "Cargo.toml", |
| 351 | + r#" |
| 352 | + [package] |
| 353 | + name = "dep" |
| 354 | + version = "1.0.0" |
| 355 | + edition = "2021" |
| 356 | + "#, |
| 357 | + ) |
| 358 | + .file("src/lib.rs", "pub fn dep_v1_fn() {}") |
| 359 | + .build(); |
| 360 | + |
| 361 | + let _dep_v2 = project() |
| 362 | + .at("dep_v2") |
| 363 | + .file( |
| 364 | + "Cargo.toml", |
| 365 | + r#" |
| 366 | + [package] |
| 367 | + name = "dep" |
| 368 | + version = "2.0.0" |
| 369 | + edition = "2021" |
| 370 | + "#, |
| 371 | + ) |
| 372 | + .file("src/lib.rs", "pub fn dep_v2_fn() {}") |
| 373 | + .build(); |
| 374 | + |
| 375 | + entry |
| 376 | + .cargo("rustdoc -v -Z unstable-options --output-format json -p dep@1.0.0") |
| 377 | + .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
| 378 | + .with_stderr_data(str![[r#" |
| 379 | +[LOCKING] 2 packages to latest compatible versions |
| 380 | +[DOCUMENTING] dep v1.0.0 ([ROOT]/dep_v1) |
| 381 | +[RUNNING] `rustdoc [..] --crate-name dep [ROOT]/dep_v1/src/lib.rs [..] --output-format=json[..]` |
| 382 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 383 | +[GENERATED] [ROOT]/foo/target/doc/dep.json |
| 384 | +
|
| 385 | +"#]]) |
| 386 | + .run(); |
| 387 | + |
| 388 | + let dep_json = fs::read_to_string(entry.root().join("target/doc/dep.json")).unwrap(); |
| 389 | + assert!(dep_json.contains("dep_v1_fn")); |
| 390 | + assert!(!dep_json.contains("dep_v2_fn")); |
| 391 | + |
| 392 | + entry |
| 393 | + .cargo("rustdoc -v -Z unstable-options --output-format json -p dep@2.0.0") |
| 394 | + .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
| 395 | + .with_stderr_data(str![[r#" |
| 396 | +[DOCUMENTING] dep v2.0.0 ([ROOT]/dep_v2) |
| 397 | +[RUNNING] `rustdoc [..] --crate-name dep [ROOT]/dep_v2/src/lib.rs [..] --output-format=json[..]` |
| 398 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 399 | +[GENERATED] [ROOT]/foo/target/doc/dep.json |
| 400 | +
|
| 401 | +"#]]) |
| 402 | + .run(); |
| 403 | + |
| 404 | + let dep_json = fs::read_to_string(entry.root().join("target/doc/dep.json")).unwrap(); |
| 405 | + assert!(!dep_json.contains("dep_v1_fn")); |
| 406 | + assert!(dep_json.contains("dep_v2_fn")); |
| 407 | + |
| 408 | + entry |
| 409 | + .cargo("rustdoc -v -Z unstable-options --output-format json -p dep@1.0.0") |
| 410 | + .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
| 411 | + .with_stderr_data(str![[r#" |
| 412 | +[FRESH] dep v1.0.0 ([ROOT]/dep_v1) |
| 413 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 414 | +[GENERATED] [ROOT]/foo/target/doc/dep.json |
| 415 | +
|
| 416 | +"#]]) |
| 417 | + .run(); |
| 418 | + |
| 419 | + let dep_json = fs::read_to_string(entry.root().join("target/doc/dep.json")).unwrap(); |
| 420 | + assert!(dep_json.contains("dep_v1_fn")); |
| 421 | + assert!(!dep_json.contains("dep_v2_fn")); |
| 422 | +} |
0 commit comments