|
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}; |
@@ -44,7 +46,25 @@ fn rustdoc_simple_json() { |
44 | 46 | .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
45 | 47 | .with_stderr_data(str![[r#" |
46 | 48 | [DOCUMENTING] foo v0.0.1 ([ROOT]/foo) |
47 | | -[RUNNING] `rustdoc [..] --crate-name foo [..]-o [ROOT]/foo/target/doc [..] --output-format=json[..] |
| 49 | +[RUNNING] `rustdoc [..] --crate-name foo [..]-o [ROOT]/foo/target/debug/build/foo-[HASH]/out [..] --output-format=json[..] |
| 50 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 51 | +[GENERATED] [ROOT]/foo/target/doc/foo.json |
| 52 | +
|
| 53 | +"#]]) |
| 54 | + .run(); |
| 55 | + assert!(p.root().join("target/doc/foo.json").is_file()); |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +#[cargo_test(nightly, reason = "--output-format is unstable")] |
| 60 | +fn rustdoc_json_with_new_layout() { |
| 61 | + let p = project().file("src/lib.rs", "").build(); |
| 62 | + |
| 63 | + p.cargo("rustdoc -Z unstable-options -Z build-dir-new-layout --output-format json -v") |
| 64 | + .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
| 65 | + .with_stderr_data(str![[r#" |
| 66 | +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) |
| 67 | +[RUNNING] `rustdoc [..] --crate-name foo [..]-o [ROOT]/foo/target/debug/build/foo/[HASH]/out [..] --output-format=json[..] |
48 | 68 | [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
49 | 69 | [GENERATED] [ROOT]/foo/target/doc/foo.json |
50 | 70 |
|
@@ -322,3 +342,99 @@ fn fail_with_glob() { |
322 | 342 | "#]]) |
323 | 343 | .run(); |
324 | 344 | } |
| 345 | + |
| 346 | +#[cargo_test(nightly, reason = "--output-format is unstable")] |
| 347 | +fn rustdoc_json_same_crate_different_version() { |
| 348 | + let entry = project() |
| 349 | + .file( |
| 350 | + "Cargo.toml", |
| 351 | + r#" |
| 352 | + [package] |
| 353 | + name = "entry" |
| 354 | + version = "0.1.0" |
| 355 | + edition = "2021" |
| 356 | +
|
| 357 | + [dependencies] |
| 358 | + dep_v1 = { path = "../dep_v1", package = "dep" } |
| 359 | + dep_v2 = { path = "../dep_v2", package = "dep" } |
| 360 | + "#, |
| 361 | + ) |
| 362 | + .file("src/lib.rs", "pub fn entry() {}") |
| 363 | + .build(); |
| 364 | + |
| 365 | + let _dep_v1 = project() |
| 366 | + .at("dep_v1") |
| 367 | + .file( |
| 368 | + "Cargo.toml", |
| 369 | + r#" |
| 370 | + [package] |
| 371 | + name = "dep" |
| 372 | + version = "1.0.0" |
| 373 | + edition = "2021" |
| 374 | + "#, |
| 375 | + ) |
| 376 | + .file("src/lib.rs", "pub fn dep_v1_fn() {}") |
| 377 | + .build(); |
| 378 | + |
| 379 | + let _dep_v2 = project() |
| 380 | + .at("dep_v2") |
| 381 | + .file( |
| 382 | + "Cargo.toml", |
| 383 | + r#" |
| 384 | + [package] |
| 385 | + name = "dep" |
| 386 | + version = "2.0.0" |
| 387 | + edition = "2021" |
| 388 | + "#, |
| 389 | + ) |
| 390 | + .file("src/lib.rs", "pub fn dep_v2_fn() {}") |
| 391 | + .build(); |
| 392 | + |
| 393 | + entry |
| 394 | + .cargo("rustdoc -v -Z unstable-options --output-format json -p dep@1.0.0") |
| 395 | + .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
| 396 | + .with_stderr_data(str![[r#" |
| 397 | +[LOCKING] 2 packages to latest compatible versions |
| 398 | +[DOCUMENTING] dep v1.0.0 ([ROOT]/dep_v1) |
| 399 | +[RUNNING] `rustdoc [..] --crate-name dep [ROOT]/dep_v1/src/lib.rs [..] --output-format=json[..]` |
| 400 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 401 | +[GENERATED] [ROOT]/foo/target/doc/dep.json |
| 402 | +
|
| 403 | +"#]]) |
| 404 | + .run(); |
| 405 | + |
| 406 | + let dep_json = fs::read_to_string(entry.root().join("target/doc/dep.json")).unwrap(); |
| 407 | + assert!(dep_json.contains("dep_v1_fn")); |
| 408 | + assert!(!dep_json.contains("dep_v2_fn")); |
| 409 | + |
| 410 | + entry |
| 411 | + .cargo("rustdoc -v -Z unstable-options --output-format json -p dep@2.0.0") |
| 412 | + .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
| 413 | + .with_stderr_data(str![[r#" |
| 414 | +[DOCUMENTING] dep v2.0.0 ([ROOT]/dep_v2) |
| 415 | +[RUNNING] `rustdoc [..] --crate-name dep [ROOT]/dep_v2/src/lib.rs [..] --output-format=json[..]` |
| 416 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 417 | +[GENERATED] [ROOT]/foo/target/doc/dep.json |
| 418 | +
|
| 419 | +"#]]) |
| 420 | + .run(); |
| 421 | + |
| 422 | + let dep_json = fs::read_to_string(entry.root().join("target/doc/dep.json")).unwrap(); |
| 423 | + assert!(!dep_json.contains("dep_v1_fn")); |
| 424 | + assert!(dep_json.contains("dep_v2_fn")); |
| 425 | + |
| 426 | + entry |
| 427 | + .cargo("rustdoc -v -Z unstable-options --output-format json -p dep@1.0.0") |
| 428 | + .masquerade_as_nightly_cargo(&["rustdoc-output-format"]) |
| 429 | + .with_stderr_data(str![[r#" |
| 430 | +[FRESH] dep v1.0.0 ([ROOT]/dep_v1) |
| 431 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 432 | +[GENERATED] [ROOT]/foo/target/doc/dep.json |
| 433 | +
|
| 434 | +"#]]) |
| 435 | + .run(); |
| 436 | + |
| 437 | + let dep_json = fs::read_to_string(entry.root().join("target/doc/dep.json")).unwrap(); |
| 438 | + assert!(dep_json.contains("dep_v1_fn")); |
| 439 | + assert!(!dep_json.contains("dep_v2_fn")); |
| 440 | +} |
0 commit comments