Skip to main content

compiletest/runtest/
rustdoc_json.rs

1use std::process::Command;
2
3use super::{DocKind, TestCx, remove_and_create_dir_all};
4
5impl TestCx<'_> {
6    pub(super) fn run_rustdoc_json_test(&self) {
7        //FIXME: Add bless option.
8
9        assert!(self.revision.is_none(), "revisions not supported in this test suite");
10
11        let out_dir = self.output_base_dir();
12        remove_and_create_dir_all(&out_dir).unwrap_or_else(|e| {
13            panic!("failed to remove and recreate output directory `{out_dir}`: {e}")
14        });
15
16        let proc_res = self.document(&out_dir, DocKind::Json);
17
18        if !self.config.capture {
19            writeln!(self.stdout, "{}", proc_res.format_info());
20        }
21
22        if !proc_res.status.success() {
23            self.fatal_proc_rec("rustdoc failed!", &proc_res);
24        }
25
26        let res = self.run_command_to_procres(
27            Command::new(self.config.jsondocck_path.as_ref().unwrap())
28                .arg("--doc-dir")
29                .arg(&out_dir)
30                .arg("--template")
31                .arg(&self.testpaths.file),
32        );
33
34        if !res.status.success() {
35            self.fatal_proc_rec_general("jsondocck failed!", None, &res, || {
36                writeln!(self.stdout, "Rustdoc Output:");
37                writeln!(self.stdout, "{}", proc_res.format_info());
38            })
39        }
40
41        let mut json_out = out_dir.join(self.testpaths.file.file_stem().unwrap());
42        json_out.set_extension("json");
43
44        let res = self.run_command_to_procres(
45            Command::new(self.config.jsondoclint_path.as_ref().unwrap()).arg(&json_out),
46        );
47
48        if !res.status.success() {
49            self.fatal_proc_rec("jsondoclint failed!", &res);
50        }
51    }
52}