]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/coverage/doctest.rs
Auto merge of #77853 - ijackson:slice-strip-stab, r=Amanieu
[rust.git] / 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.
3 //!
4 //! Just some random code:
5 //! ```
6 //! if true {
7 //!     // this is executed!
8 //!     assert_eq!(1, 1);
9 //! } else {
10 //!     // this is not!
11 //!     assert_eq!(1, 2);
12 //! }
13 //! ```
14 //!
15 //! doctest testing external code:
16 //! ```
17 //! extern crate doctest_crate;
18 //! doctest_crate::fn_run_in_doctests(1);
19 //! ```
20 //!
21 //! doctest returning a result:
22 //! ```
23 //! #[derive(Debug)]
24 //! struct SomeError;
25 //! let mut res = Err(SomeError);
26 //! if res.is_ok() {
27 //!   res?;
28 //! } else {
29 //!   res = Ok(0);
30 //! }
31 //! // need to be explicit because rustdoc cant infer the return type
32 //! Ok::<(), SomeError>(())
33 //! ```
34 //!
35 //! doctest with custom main:
36 //! ```
37 //! #[derive(Debug)]
38 //! struct SomeError;
39 //!
40 //! extern crate doctest_crate;
41 //!
42 //! fn doctest_main() -> Result<(), SomeError> {
43 //!     doctest_crate::fn_run_in_doctests(2);
44 //!     Ok(())
45 //! }
46 //!
47 //! // this `main` is not shown as covered, as it clashes with all the other
48 //! // `main` functions that were automatically generated for doctests
49 //! fn main() -> Result<(), SomeError> {
50 //!     doctest_main()
51 //! }
52 //! ```
53
54 /// doctest attached to fn testing external code:
55 /// ```
56 /// extern crate doctest_crate;
57 /// doctest_crate::fn_run_in_doctests(3);
58 /// ```
59 ///
60 fn main() {
61     if true {
62         assert_eq!(1, 1);
63     } else {
64         assert_eq!(1, 2);
65     }
66 }