]>
git.proxmox.com Git - rustc.git/blob - src/test/run-make-fulldeps/coverage/doctest.rs
1 //! This test ensures that code from doctests is properly re-mapped.
2 //! See <https://github.com/rust-lang/rust/issues/79417> for more info.
4 //! Just some random code:
7 //! // this is executed!
15 //! doctest testing external code:
17 //! extern crate doctest_crate;
18 //! doctest_crate::fn_run_in_doctests(1);
21 //! doctest returning a result:
23 //! #[derive(Debug, PartialEq)]
24 //! struct SomeError {
27 //! let mut res = Err(SomeError { msg: String::from("a message") });
31 //! if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() {
32 //! println!("{:?}", res);
34 //! if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() {
39 //! // need to be explicit because rustdoc cant infer the return type
40 //! Ok::<(), SomeError>(())
43 //! doctest with custom main:
46 //! println!("called some_func()");
52 //! extern crate doctest_crate;
54 //! fn doctest_main() -> Result<(), SomeError> {
56 //! doctest_crate::fn_run_in_doctests(2);
60 //! // this `main` is not shown as covered, as it clashes with all the other
61 //! // `main` functions that were automatically generated for doctests
62 //! fn main() -> Result<(), SomeError> {
67 /// doctest attached to fn testing external code:
69 /// extern crate doctest_crate;
70 /// doctest_crate::fn_run_in_doctests(3);
81 // FIXME(Swatinem): Fix known issue that coverage code region columns need to be offset by the
82 // doc comment line prefix (`///` or `//!`) and any additional indent (before or after the doc
83 // comment characters). This test produces `llvm-cov show` results demonstrating the problem.
85 // One of the above tests now includes: `derive(Debug, PartialEq)`, producing an `llvm-cov show`
86 // result with a distinct count for `Debug`, denoted by `^1`, but the caret points to the wrong
87 // column. Similarly, the `if` blocks without `else` blocks show `^0`, which should point at, or
88 // one character past, the `if` block's closing brace. In both cases, these are most likely off
89 // by the number of characters stripped from the beginning of each doc comment line: indent
90 // whitespace, if any, doc comment prefix (`//!` in this case) and (I assume) one space character
91 // (?). Note, when viewing `llvm-cov show` results in `--color` mode, the column offset errors are
92 // more pronounced, and show up in more places, with background color used to show some distinct
93 // code regions with different coverage counts.
95 // NOTE: Since the doc comment line prefix may vary, one possible solution is to replace each
96 // character stripped from the beginning of doc comment lines with a space. This will give coverage
97 // results the correct column offsets, and I think it should compile correctly, but I don't know
98 // what affect it might have on diagnostic messages from the compiler, and whether anyone would care
99 // if the indentation changed. I don't know if there is a more viable solution.