summary refs log tree commit diff
path: root/tests/run-make/doctests-merge/rmake.rs
blob: a25da7403e24bb566cf9f51d19593c0487676055 (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
use std::path::Path;

use run_make_support::{cwd, diff, rustc, rustdoc};

fn test_and_compare(input_file: &str, stdout_file: &str, edition: &str, dep: &Path) {
    let mut cmd = rustdoc();

    let output = cmd
        .input(input_file)
        .arg("--test")
        .arg("-Zunstable-options")
        .edition(edition)
        .arg("--test-args=--test-threads=1")
        .extern_("foo", dep.display().to_string())
        .env("RUST_BACKTRACE", "short")
        .run();

    diff()
        .expected_file(stdout_file)
        .actual_text("output", output.stdout_utf8())
        .normalize(r#"finished in \d+\.\d+s"#, "finished in $$TIME")
        .run();
}

fn main() {
    let out_file = cwd().join("libfoo.rlib");

    rustc().input("doctest.rs").crate_type("rlib").output(&out_file).run();

    // First we ensure that running with the 2024 edition will not fail at runtime.
    test_and_compare("doctest.rs", "doctest-2024.stdout", "2024", &out_file);

    // Then we ensure that running with an edition < 2024 will not fail at runtime.
    test_and_compare("doctest.rs", "doctest-2021.stdout", "2021", &out_file);

    // Now we check with the standalone attribute which should succeed in all cases.
    test_and_compare("doctest-standalone.rs", "doctest-standalone.stdout", "2024", &out_file);
    test_and_compare("doctest-standalone.rs", "doctest-standalone.stdout", "2021", &out_file);
}