Skip to main content

compiletest/
rustdoc_gui_test.rs

1//! This module isolates the compiletest APIs used by the rustdoc-gui-test tool.
2//!
3//! Thanks to this isolation layer, changes to compiletest directive parsing
4//! might require changes to the items in this module, but shouldn't require
5//! changes to rustdoc-gui-test itself.
6//!
7//! The current relationship between compiletest and rustdoc-gui-test is
8//! awkward. Ideally, rustdoc-gui-test should either split off its own
9//! directive parser and become fully independent, or be incorporated into
10//! compiletest as another test mode.
11//!
12//! See <https://github.com/rust-lang/rust/issues/143827> for more context.
13
14use std::path::Path;
15
16use camino::{Utf8Path, Utf8PathBuf};
17
18use crate::common::{CodegenBackend, Config, TestMode, TestSuite};
19use crate::directives::TestProps;
20
21/// Subset of compiletest directive values that are actually used by
22/// rustdoc-gui-test.
23#[derive(Debug)]
24pub struct RustdocGuiTestProps {
25    pub compile_flags: Vec<String>,
26    pub run_flags: Vec<String>,
27}
28
29impl RustdocGuiTestProps {
30    pub fn from_file(test_file_path: &Path) -> Self {
31        let test_file_path = Utf8Path::from_path(test_file_path).unwrap();
32        let config = incomplete_config_for_rustdoc_gui_test();
33
34        let props = TestProps::from_file(test_file_path, None, &config);
35
36        let TestProps { compile_flags, run_flags, .. } = props;
37        Self { compile_flags, run_flags }
38    }
39}
40
41/// Incomplete config intended for `src/tools/rustdoc-gui-test` **only** as
42/// `src/tools/rustdoc-gui-test` wants to reuse `compiletest`'s directive -> test property
43/// handling for `//@ {compile,run}-flags`, do not use for any other purpose.
44///
45/// FIXME(#143827): this setup feels very hacky. It so happens that `tests/rustdoc-gui/`
46/// **only** uses `//@ {compile,run}-flags` for now and not any directives that actually rely on
47/// info that is assumed available in a fully populated [`Config`].
48fn incomplete_config_for_rustdoc_gui_test() -> Config {
49    // FIXME(#143827): spelling this out intentionally, because this is questionable.
50    //
51    // For instance, `//@ ignore-stage1` will not work at all.
52    Config {
53        mode: TestMode::RustdocHtml,
54        // E.g. this has no sensible default tbh.
55        suite: TestSuite::Ui,
56
57        // Dummy values.
58        edition: Default::default(),
59        bless: Default::default(),
60        fail_fast: Default::default(),
61        host_compile_lib_path: Utf8PathBuf::default(),
62        target_run_lib_path: Utf8PathBuf::default(),
63        rustc_path: Utf8PathBuf::default(),
64        cargo_path: Default::default(),
65        stage0_rustc_path: Default::default(),
66        run_make_support_rlib: Default::default(),
67        run_make_support_rmeta: Default::default(),
68        query_rustc_path: Default::default(),
69        rustdoc_path: Default::default(),
70        coverage_dump_path: Default::default(),
71        python: Default::default(),
72        jsondocck_path: Default::default(),
73        jsondoclint_path: Default::default(),
74        llvm_filecheck: Default::default(),
75        llvm_bin_dir: Default::default(),
76        run_clang_based_tests_with: Default::default(),
77        src_root: Utf8PathBuf::default(),
78        src_test_suite_root: Utf8PathBuf::default(),
79        build_root: Utf8PathBuf::default(),
80        build_test_suite_root: Utf8PathBuf::default(),
81        sysroot_base: Utf8PathBuf::default(),
82        stage: Default::default(),
83        stage_id: String::default(),
84        run_ignored: Default::default(),
85        with_rustc_debug_assertions: Default::default(),
86        with_std_debug_assertions: Default::default(),
87        with_std_remap_debuginfo: Default::default(),
88        filters: Default::default(),
89        skip: Default::default(),
90        filter_exact: Default::default(),
91        force_pass_mode: Default::default(),
92        run: Default::default(),
93        runner: Default::default(),
94        host_rustcflags: Default::default(),
95        target_rustcflags: Default::default(),
96        rust_randomized_layout: Default::default(),
97        optimize_tests: Default::default(),
98        target: Default::default(),
99        host: Default::default(),
100        cdb: Default::default(),
101        cdb_version: Default::default(),
102        gdb: Default::default(),
103        gdb_version: Default::default(),
104        lldb: Default::default(),
105        lldb_version: Default::default(),
106        llvm_version: Default::default(),
107        system_llvm: Default::default(),
108        android_cross_path: Default::default(),
109        adb_path: Default::default(),
110        adb_test_dir: Default::default(),
111        adb_device_status: Default::default(),
112        verbose: Default::default(),
113        verbose_run_make_subprocess_output: Default::default(),
114        remote_test_client: Default::default(),
115        compare_mode: Default::default(),
116        rustfix_coverage: Default::default(),
117        has_enzyme: Default::default(),
118        has_offload: Default::default(),
119        channel: Default::default(),
120        git_hash: Default::default(),
121        cc: Default::default(),
122        cxx: Default::default(),
123        cflags: Default::default(),
124        cxxflags: Default::default(),
125        ar: Default::default(),
126        target_linker: Default::default(),
127        host_linker: Default::default(),
128        llvm_components: Default::default(),
129        nodejs: Default::default(),
130        force_rerun: Default::default(),
131        only_modified: Default::default(),
132        target_cfgs: Default::default(),
133        builtin_cfg_names: Default::default(),
134        supported_crate_types: Default::default(),
135        capture: Default::default(),
136        nightly_branch: Default::default(),
137        git_merge_commit_email: Default::default(),
138        profiler_runtime: Default::default(),
139        diff_command: Default::default(),
140        minicore_path: Default::default(),
141        default_codegen_backend: CodegenBackend::Llvm,
142        override_codegen_backend: None,
143        bypass_ignore_backends: Default::default(),
144        gcc_supported_target_tuples: vec![],
145        jobs: Default::default(),
146        parallel_frontend_threads: Config::DEFAULT_PARALLEL_FRONTEND_THREADS,
147        iteration_count: Config::DEFAULT_ITERATION_COUNT,
148        wasm_proc_macros: false,
149    }
150}