Skip to content

Commit 9ba555f

Browse files
committed
test(doc): show scenarios cargo doc not rebuild
1 parent 3530a26 commit 9ba555f

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

tests/testsuite/doc.rs

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,3 +2914,224 @@ See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more inform
29142914
"#]])
29152915
.run();
29162916
}
2917+
2918+
#[cargo_test(nightly, reason = "`rustdoc --emit` is unstable")]
2919+
fn rebuild_tracks_include_str() {
2920+
let p = cargo_test_support::project_in("parent")
2921+
.file("Cargo.toml", &basic_lib_manifest("foo"))
2922+
.file("src/lib.rs", r#"#![doc = include_str!("../../README")]"#)
2923+
.file("../README", "# depinfo-before")
2924+
.build();
2925+
2926+
p.cargo("doc -Zrustdoc-depinfo")
2927+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
2928+
.with_stderr_data(str![[r#"
2929+
[DOCUMENTING] foo v0.5.0 ([ROOT]/parent/foo)
2930+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2931+
[GENERATED] [ROOT]/parent/foo/target/doc/foo/index.html
2932+
2933+
"#]])
2934+
.run();
2935+
2936+
let doc_html = p.read_file("target/doc/foo/index.html");
2937+
assert!(doc_html.contains("depinfo-before"));
2938+
2939+
p.change_file("../README", "# depinfo-after");
2940+
2941+
p.cargo("doc --verbose -Zrustdoc-depinfo")
2942+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
2943+
.with_stderr_data(str![[r#"
2944+
[FRESH] foo v0.5.0 ([ROOT]/parent/foo)
2945+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2946+
[GENERATED] [ROOT]/parent/foo/target/doc/foo/index.html
2947+
2948+
"#]])
2949+
.run();
2950+
2951+
let doc_html = p.read_file("target/doc/foo/index.html");
2952+
assert!(!doc_html.contains("depinfo-after"));
2953+
}
2954+
2955+
#[cargo_test(nightly, reason = "`rustdoc --emit` is unstable")]
2956+
fn rebuild_tracks_path_attr() {
2957+
let p = cargo_test_support::project_in("parent")
2958+
.file("Cargo.toml", &basic_lib_manifest("foo"))
2959+
.file("src/lib.rs", r#"#[path = "../../bar.rs"] pub mod bar;"#)
2960+
.file("../bar.rs", "//! # depinfo-before")
2961+
.build();
2962+
2963+
p.cargo("doc -Zrustdoc-depinfo")
2964+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
2965+
.with_stderr_data(str![[r#"
2966+
[DOCUMENTING] foo v0.5.0 ([ROOT]/parent/foo)
2967+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2968+
[GENERATED] [ROOT]/parent/foo/target/doc/foo/index.html
2969+
2970+
"#]])
2971+
.run();
2972+
2973+
let doc_html = p.read_file("target/doc/foo/index.html");
2974+
assert!(doc_html.contains("depinfo-before"));
2975+
2976+
p.change_file("../bar.rs", "//! # depinfo-after");
2977+
2978+
p.cargo("doc --verbose -Zrustdoc-depinfo")
2979+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
2980+
.with_stderr_data(str![[r#"
2981+
[FRESH] foo v0.5.0 ([ROOT]/parent/foo)
2982+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2983+
[GENERATED] [ROOT]/parent/foo/target/doc/foo/index.html
2984+
2985+
"#]])
2986+
.run();
2987+
2988+
let doc_html = p.read_file("target/doc/foo/index.html");
2989+
assert!(!doc_html.contains("depinfo-after"));
2990+
}
2991+
2992+
#[cargo_test(nightly, reason = "`rustdoc --emit` is unstable")]
2993+
fn rebuild_tracks_env() {
2994+
let env = "__RUSTDOC_INJECTED";
2995+
let p = project()
2996+
.file("Cargo.toml", &basic_lib_manifest("foo"))
2997+
.file("src/lib.rs", &format!(r#"#![doc = env!("{env}")]"#))
2998+
.build();
2999+
3000+
p.cargo("doc -Zrustdoc-depinfo")
3001+
.env(env, "# depinfo-before")
3002+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
3003+
.with_stderr_data(str![[r#"
3004+
[DOCUMENTING] foo v0.5.0 ([ROOT]/foo)
3005+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3006+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
3007+
3008+
"#]])
3009+
.run();
3010+
3011+
let doc_html = p.read_file("target/doc/foo/index.html");
3012+
assert!(doc_html.contains("depinfo-before"));
3013+
3014+
p.cargo("doc --verbose -Zrustdoc-depinfo")
3015+
.env(env, "# depinfo-after")
3016+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
3017+
.with_stderr_data(str![[r#"
3018+
[FRESH] foo v0.5.0 ([ROOT]/foo)
3019+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3020+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
3021+
3022+
"#]])
3023+
.run();
3024+
3025+
let doc_html = p.read_file("target/doc/foo/index.html");
3026+
assert!(!doc_html.contains("depinfo-after"));
3027+
}
3028+
3029+
#[cargo_test(nightly, reason = "`rustdoc --emit` is unstable")]
3030+
fn rebuild_tracks_env_in_dep() {
3031+
let env = "__RUSTDOC_INJECTED";
3032+
Package::new("bar", "0.1.0")
3033+
.file("src/lib.rs", &format!(r#"#![doc = env!("{env}")]"#))
3034+
.publish();
3035+
3036+
let env = "__RUSTDOC_INJECTED";
3037+
let p = project()
3038+
.file(
3039+
"Cargo.toml",
3040+
r#"
3041+
[package]
3042+
name = "foo"
3043+
edition = "2015"
3044+
[dependencies]
3045+
bar = "0.1.0"
3046+
"#,
3047+
)
3048+
.file("src/lib.rs", "")
3049+
.build();
3050+
3051+
p.cargo("doc -Zrustdoc-depinfo")
3052+
.env(env, "# depinfo-before")
3053+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
3054+
.with_stderr_data(
3055+
str![[r#"
3056+
[UPDATING] `dummy-registry` index
3057+
[LOCKING] 1 package to latest compatible version
3058+
[DOWNLOADING] crates ...
3059+
[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`)
3060+
[CHECKING] bar v0.1.0
3061+
[DOCUMENTING] bar v0.1.0
3062+
[DOCUMENTING] foo v0.0.0 ([ROOT]/foo)
3063+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3064+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
3065+
3066+
"#]]
3067+
.unordered(),
3068+
)
3069+
.run();
3070+
3071+
let doc_html = p.read_file("target/doc/bar/index.html");
3072+
assert!(doc_html.contains("depinfo-before"));
3073+
3074+
p.cargo("doc --verbose -Zrustdoc-depinfo")
3075+
.env(env, "# depinfo-after")
3076+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
3077+
.with_stderr_data(str![[r#"
3078+
[DIRTY] bar v0.1.0: the environment variable __RUSTDOC_INJECTED changed
3079+
[CHECKING] bar v0.1.0
3080+
[RUNNING] `rustc --crate-name bar [..]`
3081+
[DIRTY] foo v0.0.0 ([ROOT]/foo): the dependency bar was rebuilt
3082+
[DOCUMENTING] foo v0.0.0 ([ROOT]/foo)
3083+
[RUNNING] `rustdoc [..]--crate-name foo [..]`
3084+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3085+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
3086+
3087+
"#]]
3088+
)
3089+
.run();
3090+
3091+
let doc_html = p.read_file("target/doc/bar/index.html");
3092+
assert!(!doc_html.contains("depinfo-after"));
3093+
}
3094+
3095+
#[cargo_test(
3096+
nightly,
3097+
reason = "`rustdoc --emit` is unstable; requires -Zchecksum-hash-algorithm"
3098+
)]
3099+
fn rebuild_tracks_checksum() {
3100+
let p = cargo_test_support::project_in("parent")
3101+
.file("Cargo.toml", &basic_lib_manifest("foo"))
3102+
.file("src/lib.rs", r#"#![doc = include_str!("../../README")]"#)
3103+
.file("../README", "# depinfo-before")
3104+
.build();
3105+
3106+
p.cargo("doc -Zrustdoc-depinfo -Zchecksum-freshness")
3107+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo", "checksum-freshness"])
3108+
.with_stderr_data(str![[r#"
3109+
[DOCUMENTING] foo v0.5.0 ([ROOT]/parent/foo)
3110+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3111+
[GENERATED] [ROOT]/parent/foo/target/doc/foo/index.html
3112+
3113+
"#]])
3114+
.run();
3115+
3116+
let doc_html = p.read_file("target/doc/foo/index.html");
3117+
assert!(doc_html.contains("depinfo-before"));
3118+
3119+
p.change_file("../README", "# depinfo-after");
3120+
// Change mtime into the future
3121+
p.root().move_into_the_future();
3122+
3123+
p.cargo("doc --verbose -Zrustdoc-depinfo -Zchecksum-freshness")
3124+
.masquerade_as_nightly_cargo(&["rustdoc-depinfo"])
3125+
.with_stderr_data(str![[r#"
3126+
[DIRTY] foo v0.5.0 ([ROOT]/parent/foo): the precalculated components changed
3127+
[DOCUMENTING] foo v0.5.0 ([ROOT]/parent/foo)
3128+
[RUNNING] `rustdoc [..]`
3129+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3130+
[GENERATED] [ROOT]/parent/foo/target/doc/foo/index.html
3131+
3132+
"#]])
3133+
.run();
3134+
3135+
let doc_html = p.read_file("target/doc/foo/index.html");
3136+
assert!(doc_html.contains("depinfo-after"));
3137+
}

0 commit comments

Comments
 (0)