]> git.proxmox.com Git - cargo.git/blob - tests/testsuite/rustdocflags.rs
Add RegistryBuilder to help initializing test registries.
[cargo.git] / tests / testsuite / rustdocflags.rs
1 //! Tests for setting custom rustdoc flags.
2
3 use cargo_test_support::project;
4
5 #[cargo_test]
6 fn parses_env() {
7 let p = project().file("src/lib.rs", "").build();
8
9 p.cargo("doc -v")
10 .env("RUSTDOCFLAGS", "--cfg=foo")
11 .with_stderr_contains("[RUNNING] `rustdoc [..] --cfg=foo[..]`")
12 .run();
13 }
14
15 #[cargo_test]
16 fn parses_config() {
17 let p = project()
18 .file("src/lib.rs", "")
19 .file(
20 ".cargo/config",
21 r#"
22 [build]
23 rustdocflags = ["--cfg", "foo"]
24 "#,
25 )
26 .build();
27
28 p.cargo("doc -v")
29 .with_stderr_contains("[RUNNING] `rustdoc [..] --cfg foo[..]`")
30 .run();
31 }
32
33 #[cargo_test]
34 fn bad_flags() {
35 let p = project().file("src/lib.rs", "").build();
36
37 p.cargo("doc")
38 .env("RUSTDOCFLAGS", "--bogus")
39 .with_status(101)
40 .with_stderr_contains("[..]bogus[..]")
41 .run();
42 }
43
44 #[cargo_test]
45 fn rerun() {
46 let p = project().file("src/lib.rs", "").build();
47
48 p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo").run();
49 p.cargo("doc")
50 .env("RUSTDOCFLAGS", "--cfg=foo")
51 .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
52 .run();
53 p.cargo("doc")
54 .env("RUSTDOCFLAGS", "--cfg=bar")
55 .with_stderr(
56 "\
57 [DOCUMENTING] foo v0.0.1 ([..])
58 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
59 ",
60 )
61 .run();
62 }
63
64 #[cargo_test]
65 fn rustdocflags_passed_to_rustdoc_through_cargo_test() {
66 let p = project()
67 .file(
68 "src/lib.rs",
69 r#"
70 //! ```
71 //! assert!(cfg!(do_not_choke));
72 //! ```
73 "#,
74 )
75 .build();
76
77 p.cargo("test --doc")
78 .env("RUSTDOCFLAGS", "--cfg do_not_choke")
79 .run();
80 }
81
82 #[cargo_test]
83 fn rustdocflags_passed_to_rustdoc_through_cargo_test_only_once() {
84 let p = project().file("src/lib.rs", "").build();
85
86 p.cargo("test --doc")
87 .env("RUSTDOCFLAGS", "--markdown-no-toc")
88 .run();
89 }
90
91 #[cargo_test]
92 fn rustdocflags_misspelled() {
93 let p = project().file("src/main.rs", "fn main() { }").build();
94
95 p.cargo("doc")
96 .env("RUSTDOC_FLAGS", "foo")
97 .with_stderr_contains("[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?")
98 .run();
99 }
100
101 #[cargo_test]
102 fn whitespace() {
103 // Checks behavior of different whitespace characters.
104 let p = project().file("src/lib.rs", "").build();
105
106 // "too many operands"
107 p.cargo("doc")
108 .env("RUSTDOCFLAGS", "--crate-version this has spaces")
109 .with_stderr_contains("[ERROR] could not document `foo`")
110 .with_status(101)
111 .run();
112
113 const SPACED_VERSION: &str = "a\nb\tc\u{00a0}d";
114 p.cargo("doc")
115 .env(
116 "RUSTDOCFLAGS",
117 format!("--crate-version {}", SPACED_VERSION),
118 )
119 .run();
120
121 let contents = p.read_file("target/doc/foo/index.html");
122 assert!(contents.contains(SPACED_VERSION));
123 }