-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[rustdoc] Correctly handle output options with --show-coverage #159411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
74e9e5a
4d5cd55
1010137
7cdcfc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pub struct Bar; | ||
|
|
||
| impl Bar { | ||
| pub fn foo() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // This test ensures that `-o` option works as expected with `--show-coverage`. | ||
| // Regression test for <https://github.com/rust-lang/rust/issues/158929>. | ||
|
|
||
| //@ needs-target-std | ||
|
|
||
| use run_make_support::rfs::{read_to_string, remove_file}; | ||
| use run_make_support::{path, rustdoc}; | ||
|
|
||
| fn run_rustdoc(extra_args: &[&str]) -> String { | ||
| rustdoc() | ||
| .input("foo.rs") | ||
| .arg("-Zunstable-options") | ||
| .arg("--show-coverage") | ||
| .args(extra_args) | ||
| .run() | ||
| .stdout_utf8() | ||
| } | ||
|
|
||
| fn check_print_stdout(extra_args: &[&str], stdout_check: &str) { | ||
| let out = run_rustdoc(extra_args); | ||
|
|
||
| // By default, it shouldn't have created a `doc` folder. | ||
| assert!(!path("doc").exists(), "`doc` folder created with {extra_args:?}"); | ||
| // It should have display its output on stdout. | ||
| assert!(out.starts_with(stdout_check), "{out:?} doesn't start with {stdout_check:?}"); | ||
| } | ||
|
|
||
| fn check_generate_file(ext: &str, extra_args: &[&str], file_check: &str) { | ||
| let mut args = extra_args.to_vec(); | ||
| args.push("-o"); | ||
| args.push("doc"); | ||
| let out = run_rustdoc(&args); | ||
|
|
||
| // By default, it shouldn't have created a `doc` folder. | ||
| assert!(path("doc").exists(), "`doc` folder not created with {args:?}"); | ||
| let file = format!("doc/foo.{ext}"); | ||
| assert!(path(&file).exists()); | ||
|
|
||
| let expected = format!("Generated output into {file:?}\n"); | ||
| assert_eq!(out, expected, "Expected {expected:?}, got {out:?}"); | ||
|
|
||
| let content = read_to_string(&file); | ||
| assert!(content.starts_with(file_check), "{content:?} doesn't start with {file_check:?}"); | ||
| remove_file(file); | ||
| } | ||
|
|
||
| fn main() { | ||
| check_print_stdout(&[], "+-"); | ||
| check_print_stdout(&["-o", "-"], "+-"); | ||
| check_print_stdout(&["--output-format=json"], "{"); | ||
| check_print_stdout(&["--output-format=json", "-o", "-"], "{"); | ||
|
|
||
| // Now we check that it works with "-o something". | ||
| check_generate_file("txt", &[], "+-"); | ||
| check_generate_file("json", &["--output-format=json"], "{"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...i/coverage/allow_missing_docs.rs | 5 | 71.4% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 5 | 71.4% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/allow_missing_docs.txt" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes all the coverage tests not actually check that the output numbers are correct.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I completely missed it. Gonna add |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...sts/rustdoc-ui/coverage/basic.rs | 7 | 50.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 7 | 50.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/basic.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":1,"with_examples":1}} | ||
| Generated output into "$TEST_BUILD_DIR/doc_examples_json.json" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...tdoc-ui/coverage/doc-examples.rs | 4 | 100.0% | 1 | 33.3% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 4 | 100.0% | 1 | 33.3% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/doc_examples.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...sts/rustdoc-ui/coverage/empty.rs | 0 | 0.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 0 | 0.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/empty.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...overage/enum-tuple-documented.rs | 9 | 100.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 9 | 100.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/enum_tuple_documented.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...ustdoc-ui/coverage/enum-tuple.rs | 6 | 100.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 6 | 100.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/enum_tuple.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...sts/rustdoc-ui/coverage/enums.rs | 6 | 75.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 6 | 75.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/enums.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...ts/rustdoc-ui/coverage/exotic.rs | 3 | 100.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 3 | 100.0% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/exotic.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":13,"with_examples":6}} | ||
| Generated output into "$TEST_BUILD_DIR/json.json" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...s/rustdoc-ui/coverage/private.rs | 4 | 57.1% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 4 | 57.1% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/private.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | File | Documented | Percentage | Examples | Percentage | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | ...oc-ui/coverage/statics-consts.rs | 6 | 85.7% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| | Total | 6 | 85.7% | 0 | 0.0% | | ||
| +-------------------------------------+------------+------------+------------+------------+ | ||
| Generated output into "$TEST_BUILD_DIR/statics_consts.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?