|
| 1 | +// Check that valid binaries are persisted by running them, regardless of whether the |
| 2 | +// --run or --no-run option is used. |
| 3 | + |
| 4 | +use run_make_support::{run, rustc, rustdoc, tmp_dir}; |
| 5 | +use std::fs::{create_dir, remove_dir_all}; |
| 6 | +use std::path::Path; |
| 7 | + |
| 8 | +fn setup_test_env<F: FnOnce(&Path, &Path)>(callback: F) { |
| 9 | + let out_dir = tmp_dir().join("doctests"); |
| 10 | + create_dir(&out_dir).expect("failed to create doctests folder"); |
| 11 | + rustc().input("t.rs").crate_type("rlib").run(); |
| 12 | + callback(&out_dir, &tmp_dir().join("libt.rlib")); |
| 13 | + remove_dir_all(out_dir); |
| 14 | +} |
| 15 | + |
| 16 | +fn check_generated_binaries() { |
| 17 | + run("doctests/t_rs_2_0/rust_out"); |
| 18 | + run("doctests/t_rs_8_0/rust_out"); |
| 19 | +} |
| 20 | + |
| 21 | +fn main() { |
| 22 | + setup_test_env(|out_dir, extern_path| { |
| 23 | + rustdoc() |
| 24 | + .input("t.rs") |
| 25 | + .arg("-Zunstable-options") |
| 26 | + .arg("--test") |
| 27 | + .arg("--persist-doctests") |
| 28 | + .arg(out_dir) |
| 29 | + .arg("--extern") |
| 30 | + .arg(format!("t={}", extern_path.display())) |
| 31 | + .run(); |
| 32 | + check_generated_binaries(); |
| 33 | + }); |
| 34 | + setup_test_env(|out_dir, extern_path| { |
| 35 | + rustdoc() |
| 36 | + .input("t.rs") |
| 37 | + .arg("-Zunstable-options") |
| 38 | + .arg("--test") |
| 39 | + .arg("--persist-doctests") |
| 40 | + .arg(out_dir) |
| 41 | + .arg("--extern") |
| 42 | + .arg(format!("t={}", extern_path.display())) |
| 43 | + .arg("--no-run") |
| 44 | + .run(); |
| 45 | + check_generated_binaries(); |
| 46 | + }); |
| 47 | + // Behavior with --test-run-directory with relative paths. |
| 48 | + setup_test_env(|_out_dir, extern_path| { |
| 49 | + let run_dir = "rundir"; |
| 50 | + let run_dir_path = tmp_dir().join("rundir"); |
| 51 | + create_dir(&run_dir_path).expect("failed to create rundir folder"); |
| 52 | + |
| 53 | + rustdoc() |
| 54 | + .current_dir(tmp_dir()) |
| 55 | + .input(std::env::current_dir().unwrap().join("t.rs")) |
| 56 | + .arg("-Zunstable-options") |
| 57 | + .arg("--test") |
| 58 | + .arg("--persist-doctests") |
| 59 | + .arg("doctests") |
| 60 | + .arg("--test-run-directory") |
| 61 | + .arg(run_dir) |
| 62 | + .arg("--extern") |
| 63 | + .arg("t=libt.rlib") |
| 64 | + .run(); |
| 65 | + |
| 66 | + remove_dir_all(run_dir_path); |
| 67 | + }); |
| 68 | +} |
0 commit comments