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.
5 4| |//! Just some random code:
8 7| |//! // this is executed!
9 8| 1|//! assert_eq!(1, 1);
11 10| |//! // this is not!
12 11| |//! assert_eq!(1, 2);
16 15| |//! doctest testing external code:
18 17| 1|//! extern crate doctest_crate;
19 18| 1|//! doctest_crate::fn_run_in_doctests(1);
22 21| |//! doctest returning a result:
24 23| 1|//! #[derive(Debug)]
25 24| 1|//! struct SomeError;
26 25| 1|//! let mut res = Err(SomeError);
27 26| 1|//! if res.is_ok() {
30 29| 1|//! res = Ok(0);
32 31| |//! // need to be explicit because rustdoc cant infer the return type
33 32| 1|//! Ok::<(), SomeError>(())
36 35| |//! doctest with custom main:
38 37| |//! #[derive(Debug)]
39 38| |//! struct SomeError;
41 40| |//! extern crate doctest_crate;
43 42| 1|//! fn doctest_main() -> Result<(), SomeError> {
44 43| 1|//! doctest_crate::fn_run_in_doctests(2);
48 47| |//! // this `main` is not shown as covered, as it clashes with all the other
49 48| |//! // `main` functions that were automatically generated for doctests
50 49| |//! fn main() -> Result<(), SomeError> {
51 50| |//! doctest_main()
55 54| |/// doctest attached to fn testing external code:
57 56| 1|/// extern crate doctest_crate;
58 57| 1|/// doctest_crate::fn_run_in_doctests(3);
63 62| 1| assert_eq!(1, 1);
65 64| | assert_eq!(1, 2);
69 ../coverage/lib/doctest_crate.rs:
70 1| |/// A function run only from within doctests
71 2| 3|pub fn fn_run_in_doctests(conditional: usize) {
72 3| 3| match conditional {
73 4| 1| 1 => assert_eq!(1, 1), // this is run,
74 5| 1| 2 => assert_eq!(1, 1), // this,
75 6| 1| 3 => assert_eq!(1, 1), // and this too
76 7| 0| _ => assert_eq!(1, 2), // however this is not