|
| 1 | +// This test checks the functionality of one of rustdoc's unstable options, |
| 2 | +// the ability to specify emit restrictions with `--emit`. |
| 3 | +// `invocation-only` should only emit crate-specific files. |
| 4 | +// `toolchain-only` should only emit toolchain-specific files. |
| 5 | +// `all-shared` should only emit files that can be shared between crates. |
| 6 | +// See https://github.com/rust-lang/rust/pull/83478 |
| 7 | + |
| 8 | +use run_make_support::{has_extension, has_prefix, rustdoc, shallow_find_files}; |
| 9 | +use std::path::Path; |
| 10 | + |
| 11 | +fn main() { |
| 12 | + rustdoc() |
| 13 | + .arg("-Zunstable-options") |
| 14 | + .arg("--emit=invocation-specific") |
| 15 | + .output("invocation-only") |
| 16 | + .arg("--resource-suffix=-xxx") |
| 17 | + .args(&["--theme", "y.css"]) |
| 18 | + .args(&["--extend-css", "z.css"]) |
| 19 | + .input("x.rs") |
| 20 | + .run(); |
| 21 | + assert!(Path::new("invocation-only/search-index-xxx.js").exists()); |
| 22 | + assert!(Path::new("invocation-only/settings.html").exists()); |
| 23 | + assert!(Path::new("invocation-only/x/all.html").exists()); |
| 24 | + assert!(Path::new("invocation-only/x/index.html").exists()); |
| 25 | + assert!(Path::new("invocation-only/theme-xxx.css").exists()); // generated from z.css |
| 26 | + assert!(!Path::new("invocation-only/storage-xxx.js").exists()); |
| 27 | + assert!(!Path::new("invocation-only/SourceSerif4-It.ttf.woff2").exists()); |
| 28 | + // FIXME: this probably shouldn't have a suffix |
| 29 | + assert!(Path::new("invocation-only/y-xxx.css").exists()); |
| 30 | + // FIXME: this is technically incorrect (see `write_shared`) |
| 31 | + assert!(!Path::new("invocation-only/main-xxx.js").exists()); |
| 32 | + |
| 33 | + rustdoc() |
| 34 | + .arg("-Zunstable-options") |
| 35 | + .arg("--emit=toolchain-shared-resources") |
| 36 | + .output("toolchain-only") |
| 37 | + .arg("--resource-suffix=-xxx") |
| 38 | + .args(&["--extend-css", "z.css"]) |
| 39 | + .input("x.rs") |
| 40 | + .run(); |
| 41 | + assert_eq!( |
| 42 | + shallow_find_files("toolchain-only/static.files", |path| { |
| 43 | + has_prefix(path, "storage-") && has_extension(path, "js") |
| 44 | + }) |
| 45 | + .len(), |
| 46 | + 1 |
| 47 | + ); |
| 48 | + assert_eq!( |
| 49 | + shallow_find_files("toolchain-only/static.files", |path| { |
| 50 | + has_prefix(path, "SourceSerif4-It-") && has_extension(path, "woff2") |
| 51 | + }) |
| 52 | + .len(), |
| 53 | + 1 |
| 54 | + ); |
| 55 | + assert_eq!( |
| 56 | + shallow_find_files("toolchain-only/static.files", |path| { |
| 57 | + has_prefix(path, "main-") && has_extension(path, "js") |
| 58 | + }) |
| 59 | + .len(), |
| 60 | + 1 |
| 61 | + ); |
| 62 | + assert!(!Path::new("toolchain-only/search-index-xxx.js").exists()); |
| 63 | + assert!(!Path::new("toolchain-only/x/index.html").exists()); |
| 64 | + assert!(!Path::new("toolchain-only/theme.css").exists()); |
| 65 | + assert!(!Path::new("toolchain-only/y-xxx.css").exists()); |
| 66 | + |
| 67 | + rustdoc() |
| 68 | + .arg("-Zunstable-options") |
| 69 | + .arg("--emit=toolchain-shared-resources,unversioned-shared-resources") |
| 70 | + .output("all-shared") |
| 71 | + .arg("--resource-suffix=-xxx") |
| 72 | + .args(&["--extend-css", "z.css"]) |
| 73 | + .input("x.rs") |
| 74 | + .run(); |
| 75 | + assert_eq!( |
| 76 | + shallow_find_files("all-shared/static.files", |path| { |
| 77 | + has_prefix(path, "storage-") && has_extension(path, "js") |
| 78 | + }) |
| 79 | + .len(), |
| 80 | + 1 |
| 81 | + ); |
| 82 | + assert_eq!( |
| 83 | + shallow_find_files("all-shared/static.files", |path| { |
| 84 | + has_prefix(path, "SourceSerif4-It-") && has_extension(path, "woff2") |
| 85 | + }) |
| 86 | + .len(), |
| 87 | + 1 |
| 88 | + ); |
| 89 | + assert!(!Path::new("all-shared/search-index-xxx.js").exists()); |
| 90 | + assert!(!Path::new("all-shared/settings.html").exists()); |
| 91 | + assert!(!Path::new("all-shared/x").exists()); |
| 92 | + assert!(!Path::new("all-shared/src").exists()); |
| 93 | + assert!(!Path::new("all-shared/theme.css").exists()); |
| 94 | + assert_eq!( |
| 95 | + shallow_find_files("all-shared/static.files", |path| { |
| 96 | + has_prefix(path, "main-") && has_extension(path, "js") |
| 97 | + }) |
| 98 | + .len(), |
| 99 | + 1 |
| 100 | + ); |
| 101 | + assert!(!Path::new("all-shared/y-xxx.css").exists()); |
| 102 | +} |
0 commit comments