]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt
Auto merge of #84904 - ssomers:btree_drop_kv_in_place, r=Mark-Simulacrum
[rust.git] / src / test / run-make-fulldeps / coverage-reports / expected_show_coverage.doctest.txt
1 ../coverage/doctest.rs:
2     1|       |//! This test ensures that code from doctests is properly re-mapped.
3     2|       |//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
4     3|       |//!
5     4|       |//! Just some random code:
6     5|      1|//! ```
7     6|      1|//! if true {
8     7|       |//!     // this is executed!
9     8|      1|//!     assert_eq!(1, 1);
10     9|       |//! } else {
11    10|       |//!     // this is not!
12    11|      0|//!     assert_eq!(1, 2);
13    12|       |//! }
14    13|      1|//! ```
15    14|       |//!
16    15|       |//! doctest testing external code:
17    16|       |//! ```
18    17|      1|//! extern crate doctest_crate;
19    18|      1|//! doctest_crate::fn_run_in_doctests(1);
20    19|      1|//! ```
21    20|       |//!
22    21|       |//! doctest returning a result:
23    22|      1|//! ```
24    23|      2|//! #[derive(Debug, PartialEq)]
25                        ^1
26   ------------------
27   | Unexecuted instantiation: <rust_out::main::_doctest_main____coverage_doctest_rs_22_0::SomeError as core::cmp::PartialEq>::ne
28   ------------------
29   | <rust_out::main::_doctest_main____coverage_doctest_rs_22_0::SomeError as core::cmp::PartialEq>::eq:
30   |   23|      2|//! #[derive(Debug, PartialEq)]
31   ------------------
32    24|      1|//! struct SomeError {
33    25|      1|//!     msg: String,
34    26|      1|//! }
35    27|      1|//! let mut res = Err(SomeError { msg: String::from("a message") });
36    28|      1|//! if res.is_ok() {
37    29|      0|//!     res?;
38    30|       |//! } else {
39    31|      1|//!     if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() {
40    32|      1|//!         println!("{:?}", res);
41    33|      1|//!     }
42                    ^0
43    34|      1|//!     if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() {
44    35|      1|//!         res = Ok(1);
45    36|      1|//!     }
46                    ^0
47    37|      1|//!     res = Ok(0);
48    38|       |//! }
49    39|       |//! // need to be explicit because rustdoc cant infer the return type
50    40|      1|//! Ok::<(), SomeError>(())
51    41|      1|//! ```
52    42|       |//!
53    43|       |//! doctest with custom main:
54    44|       |//! ```
55    45|      1|//! fn some_func() {
56    46|      1|//!     println!("called some_func()");
57    47|      1|//! }
58    48|       |//!
59    49|      0|//! #[derive(Debug)]
60    50|       |//! struct SomeError;
61    51|       |//!
62    52|       |//! extern crate doctest_crate;
63    53|       |//!
64    54|      1|//! fn doctest_main() -> Result<(), SomeError> {
65    55|      1|//!     some_func();
66    56|      1|//!     doctest_crate::fn_run_in_doctests(2);
67    57|      1|//!     Ok(())
68    58|      1|//! }
69    59|       |//!
70    60|       |//! // this `main` is not shown as covered, as it clashes with all the other
71    61|       |//! // `main` functions that were automatically generated for doctests
72    62|       |//! fn main() -> Result<(), SomeError> {
73    63|       |//!     doctest_main()
74    64|       |//! }
75    65|       |//! ```
76    66|       |
77    67|       |/// doctest attached to fn testing external code:
78    68|       |/// ```
79    69|      1|/// extern crate doctest_crate;
80    70|      1|/// doctest_crate::fn_run_in_doctests(3);
81    71|      1|/// ```
82    72|       |///
83    73|      1|fn main() {
84    74|      1|    if true {
85    75|      1|        assert_eq!(1, 1);
86    76|       |    } else {
87    77|      0|        assert_eq!(1, 2);
88    78|       |    }
89    79|      1|}
90    80|       |
91    81|       |// FIXME(Swatinem): Fix known issue that coverage code region columns need to be offset by the
92    82|       |// doc comment line prefix (`///` or `//!`) and any additional indent (before or after the doc
93    83|       |// comment characters). This test produces `llvm-cov show` results demonstrating the problem.
94    84|       |//
95    85|       |// One of the above tests now includes: `derive(Debug, PartialEq)`, producing an `llvm-cov show`
96    86|       |// result with a distinct count for `Debug`, denoted by `^1`, but the caret points to the wrong
97    87|       |// column. Similarly, the `if` blocks without `else` blocks show `^0`, which should point at, or
98    88|       |// one character past, the `if` block's closing brace. In both cases, these are most likely off
99    89|       |// by the number of characters stripped from the beginning of each doc comment line: indent
100    90|       |// whitespace, if any, doc comment prefix (`//!` in this case) and (I assume) one space character
101    91|       |// (?). Note, when viewing `llvm-cov show` results in `--color` mode, the column offset errors are
102    92|       |// more pronounced, and show up in more places, with background color used to show some distinct
103    93|       |// code regions with different coverage counts.
104    94|       |//
105    95|       |// NOTE: Since the doc comment line prefix may vary, one possible solution is to replace each
106    96|       |// character stripped from the beginning of doc comment lines with a space. This will give coverage
107    97|       |// results the correct column offsets, and I think it should compile correctly, but I don't know
108    98|       |// what affect it might have on diagnostic messages from the compiler, and whether anyone would care
109    99|       |// if the indentation changed. I don't know if there is a more viable solution.
110
111 ../coverage/lib/doctest_crate.rs:
112     1|       |/// A function run only from within doctests
113     2|      3|pub fn fn_run_in_doctests(conditional: usize) {
114     3|      3|    match conditional {
115     4|      1|        1 => assert_eq!(1, 1), // this is run,
116     5|      1|        2 => assert_eq!(1, 1), // this,
117     6|      1|        3 => assert_eq!(1, 1), // and this too
118     7|      0|        _ => assert_eq!(1, 2), // however this is not
119     8|       |    }
120     9|      3|}
121