about summary refs log tree commit diff
path: root/tests/run-make/doctests-compilation-time-info/rmake.rs
blob: 2bcf664923f2a4faf18499abf217ab6fdf5c579b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//@ ignore-cross-compile (needs to run doctests)

use run_make_support::rfs::write;
use run_make_support::{cwd, rustdoc};

fn assert_presence_of_compilation_time_report(
    content: &str,
    success: bool,
    should_contain_compile_time: bool,
) {
    let mut cmd = rustdoc();
    let file = cwd().join("foo.rs");

    write(&file, content);
    cmd.input(&file).arg("--test").edition("2024").env("RUST_BACKTRACE", "0");
    let output = if success { cmd.run() } else { cmd.run_fail() };

    assert_eq!(
        output
            .stdout_utf8()
            .split("all doctests ran in ")
            .last()
            .is_some_and(|s| s.contains("; merged doctests compilation took")),
        should_contain_compile_time,
    );
}

fn main() {
    // Checking with only successful merged doctests.
    assert_presence_of_compilation_time_report(
        "\
//! ```
//! let x = 12;
//! ```",
        true,
        true,
    );
    // Checking with only failing merged doctests.
    assert_presence_of_compilation_time_report(
        "\
//! ```
//! panic!();
//! ```",
        false,
        true,
    );
    // Checking with mix of successful doctests.
    assert_presence_of_compilation_time_report(
        "\
//! ```
//! let x = 12;
//! ```
//!
//! ```compile_fail
//! let x
//! ```",
        true,
        true,
    );
    // Checking with mix of failing doctests.
    assert_presence_of_compilation_time_report(
        "\
//! ```
//! panic!();
//! ```
//!
//! ```compile_fail
//! let x
//! ```",
        false,
        true,
    );
    // Checking with mix of failing doctests (v2).
    assert_presence_of_compilation_time_report(
        "\
//! ```
//! let x = 12;
//! ```
//!
//! ```compile_fail
//! let x = 12;
//! ```",
        false,
        true,
    );
    // Checking with mix of failing doctests (v3).
    assert_presence_of_compilation_time_report(
        "\
//! ```
//! panic!();
//! ```
//!
//! ```compile_fail
//! let x = 12;
//! ```",
        false,
        true,
    );
    // Checking with successful non-merged doctests.
    assert_presence_of_compilation_time_report(
        "\
//! ```compile_fail
//! let x
//! ```",
        true,
        // If there is no merged doctests, then we should not display compilation time.
        false,
    );
    // Checking with failing non-merged doctests.
    assert_presence_of_compilation_time_report(
        "\
//! ```compile_fail
//! let x = 12;
//! ```",
        false,
        // If there is no merged doctests, then we should not display compilation time.
        false,
    );
}