Skip to content

Commit 10359de

Browse files
committed
compiletest: Add support for running rustdoc tests
Add a new test directory called 'rustdoc' where all files inside are documented and run against the `htmldocck` script to have assertions about the output.
1 parent d9146bf commit 10359de

File tree

5 files changed

+115
-46
lines changed

5 files changed

+115
-46
lines changed

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ do
11081108
make_dir $h/test/debuginfo-gdb
11091109
make_dir $h/test/debuginfo-lldb
11101110
make_dir $h/test/codegen
1111+
make_dir $h/test/rustdoc
11111112
done
11121113

11131114
# Configure submodules

mk/tests.mk

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
304304
check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
305305
check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
306306
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
307+
check-stage$(1)-T-$(2)-H-$(3)-rustdocck-exec \
307308
check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
308309
check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
309310
check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
@@ -471,6 +472,7 @@ DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
471472
DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
472473
CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
473474
CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
475+
RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdocck/*.rs)
474476

475477
# perf tests are the same as bench tests only they run under
476478
# a performance monitor.
@@ -489,6 +491,7 @@ PRETTY_TESTS := $(PRETTY_RS)
489491
DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
490492
DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
491493
CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
494+
RUSTDOCCK_TESTS := $(RUSTDOCCK_RS)
492495

493496
CTEST_SRC_BASE_rpass = run-pass
494497
CTEST_BUILD_BASE_rpass = run-pass
@@ -550,6 +553,11 @@ CTEST_BUILD_BASE_codegen = codegen
550553
CTEST_MODE_codegen = codegen
551554
CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
552555

556+
CTEST_SRC_BASE_rustdocck = rustdoc
557+
CTEST_BUILD_BASE_rustdocck = rustdoc
558+
CTEST_MODE_rustdocck = rustdoc
559+
CTEST_RUNTOOL_rustdocck = $(CTEST_RUNTOOL)
560+
553561
# CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
554562
# disabled and the associated message to be printed as a warning
555563
# during attempts to run those tests.
@@ -618,12 +626,14 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
618626
--compile-lib-path $$(HLIB$(1)_H_$(3)) \
619627
--run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
620628
--rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
629+
--rustdoc-path $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
621630
--clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
622631
--llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
623632
--aux-base $$(S)src/test/auxiliary/ \
624633
--stage-id stage$(1)-$(2) \
625634
--target $(2) \
626635
--host $(3) \
636+
--python $$(CFG_PYTHON) \
627637
--gdb-version="$(CFG_GDB_VERSION)" \
628638
--lldb-version="$(CFG_LLDB_VERSION)" \
629639
--android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
@@ -660,6 +670,9 @@ CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
660670
$(S)src/etc/lldb_batchmode.py \
661671
$(S)src/etc/lldb_rust_formatters.py
662672
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
673+
CTEST_DEPS_rustdocck_$(1)-T-$(2)-H-$(3) = $$(RUSTDOCCK_TESTS) \
674+
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
675+
$(S)src/etc/htmldocck.py
663676

664677
endef
665678

@@ -722,7 +735,8 @@ endif
722735

723736
endef
724737

725-
CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail pfail bench perf debuginfo-gdb debuginfo-lldb codegen
738+
CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail pfail \
739+
bench perf debuginfo-gdb debuginfo-lldb codegen rustdocck
726740

727741
$(foreach host,$(CFG_HOST), \
728742
$(eval $(foreach target,$(CFG_TARGET), \
@@ -890,6 +904,7 @@ TEST_GROUPS = \
890904
bench \
891905
perf \
892906
rmake \
907+
rustdocck \
893908
debuginfo-gdb \
894909
debuginfo-lldb \
895910
codegen \

src/compiletest/common.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ pub enum Mode {
2323
Pretty,
2424
DebugInfoGdb,
2525
DebugInfoLldb,
26-
Codegen
26+
Codegen,
27+
Rustdoc,
2728
}
2829

2930
impl FromStr for Mode {
@@ -39,6 +40,7 @@ impl FromStr for Mode {
3940
"debuginfo-lldb" => Ok(DebugInfoLldb),
4041
"debuginfo-gdb" => Ok(DebugInfoGdb),
4142
"codegen" => Ok(Codegen),
43+
"rustdoc" => Ok(Rustdoc),
4244
_ => Err(()),
4345
}
4446
}
@@ -56,6 +58,7 @@ impl fmt::Display for Mode {
5658
DebugInfoGdb => "debuginfo-gdb",
5759
DebugInfoLldb => "debuginfo-lldb",
5860
Codegen => "codegen",
61+
Rustdoc => "rustdoc",
5962
}, f)
6063
}
6164
}
@@ -71,6 +74,12 @@ pub struct Config {
7174
// The rustc executable
7275
pub rustc_path: PathBuf,
7376

77+
// The rustdoc executable
78+
pub rustdoc_path: PathBuf,
79+
80+
// The python executable
81+
pub python: String,
82+
7483
// The clang executable
7584
pub clang_path: Option<PathBuf>,
7685

src/compiletest/compiletest.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub fn parse_config(args: Vec<String> ) -> Config {
6060
vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
6161
reqopt("", "run-lib-path", "path to target shared libraries", "PATH"),
6262
reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"),
63+
reqopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH"),
64+
reqopt("", "python", "path to python to use for doc tests", "PATH"),
6365
optopt("", "clang-path", "path to executable for codegen tests", "PATH"),
6466
optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM"),
6567
optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind"),
@@ -128,6 +130,8 @@ pub fn parse_config(args: Vec<String> ) -> Config {
128130
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
129131
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
130132
rustc_path: opt_path(matches, "rustc-path"),
133+
rustdoc_path: opt_path(matches, "rustdoc-path"),
134+
python: matches.opt_str("python").unwrap(),
131135
clang_path: matches.opt_str("clang-path").map(|s| PathBuf::from(&s)),
132136
valgrind_path: matches.opt_str("valgrind-path"),
133137
force_valgrind: matches.opt_present("force-valgrind"),
@@ -168,6 +172,7 @@ pub fn log_config(config: &Config) {
168172
logv(c, format!("compile_lib_path: {:?}", config.compile_lib_path));
169173
logv(c, format!("run_lib_path: {:?}", config.run_lib_path));
170174
logv(c, format!("rustc_path: {:?}", config.rustc_path.display()));
175+
logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path.display()));
171176
logv(c, format!("src_base: {:?}", config.src_base.display()));
172177
logv(c, format!("build_base: {:?}", config.build_base.display()));
173178
logv(c, format!("stage_id: {}", config.stage_id));

src/compiletest/runtest.rs

Lines changed: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use self::TargetLocation::*;
1212

1313
use common::Config;
1414
use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
15-
use common::{Codegen, DebugInfoLldb, DebugInfoGdb};
15+
use common::{Codegen, DebugInfoLldb, DebugInfoGdb, Rustdoc};
1616
use errors;
1717
use header::TestProps;
1818
use header;
@@ -57,15 +57,16 @@ pub fn run_metrics(config: Config, testfile: &Path, mm: &mut MetricMap) {
5757
let props = header::load_props(&testfile);
5858
debug!("loaded props");
5959
match config.mode {
60-
CompileFail => run_cfail_test(&config, &props, &testfile),
61-
ParseFail => run_cfail_test(&config, &props, &testfile),
62-
RunFail => run_rfail_test(&config, &props, &testfile),
63-
RunPass => run_rpass_test(&config, &props, &testfile),
64-
RunPassValgrind => run_valgrind_test(&config, &props, &testfile),
65-
Pretty => run_pretty_test(&config, &props, &testfile),
66-
DebugInfoGdb => run_debuginfo_gdb_test(&config, &props, &testfile),
67-
DebugInfoLldb => run_debuginfo_lldb_test(&config, &props, &testfile),
68-
Codegen => run_codegen_test(&config, &props, &testfile, mm),
60+
CompileFail => run_cfail_test(&config, &props, &testfile),
61+
ParseFail => run_cfail_test(&config, &props, &testfile),
62+
RunFail => run_rfail_test(&config, &props, &testfile),
63+
RunPass => run_rpass_test(&config, &props, &testfile),
64+
RunPassValgrind => run_valgrind_test(&config, &props, &testfile),
65+
Pretty => run_pretty_test(&config, &props, &testfile),
66+
DebugInfoGdb => run_debuginfo_gdb_test(&config, &props, &testfile),
67+
DebugInfoLldb => run_debuginfo_lldb_test(&config, &props, &testfile),
68+
Codegen => run_codegen_test(&config, &props, &testfile, mm),
69+
Rustdoc => run_rustdoc_test(&config, &props, &testfile),
6970
}
7071
}
7172

@@ -725,32 +726,37 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
725726
-> ProcRes {
726727
// Prepare the lldb_batchmode which executes the debugger script
727728
let lldb_script_path = rust_src_root.join("src/etc/lldb_batchmode.py");
729+
cmd2proces(config,
730+
test_executable,
731+
Command::new(&config.python)
732+
.arg(&lldb_script_path)
733+
.arg(test_executable)
734+
.arg(debugger_script)
735+
.env("PYTHONPATH",
736+
config.lldb_python_dir.as_ref().unwrap()))
737+
}
738+
}
728739

729-
let mut cmd = Command::new("python");
730-
cmd.arg(&lldb_script_path)
731-
.arg(test_executable)
732-
.arg(debugger_script)
733-
.env("PYTHONPATH", config.lldb_python_dir.as_ref().unwrap());
734-
735-
let (status, out, err) = match cmd.output() {
736-
Ok(Output { status, stdout, stderr }) => {
737-
(status,
738-
String::from_utf8(stdout).unwrap(),
739-
String::from_utf8(stderr).unwrap())
740-
},
741-
Err(e) => {
742-
fatal(&format!("Failed to setup Python process for \
743-
LLDB script: {}", e))
744-
}
745-
};
740+
fn cmd2proces(config: &Config, test_executable: &Path, cmd: &mut Command)
741+
-> ProcRes {
742+
let (status, out, err) = match cmd.output() {
743+
Ok(Output { status, stdout, stderr }) => {
744+
(status,
745+
String::from_utf8(stdout).unwrap(),
746+
String::from_utf8(stderr).unwrap())
747+
},
748+
Err(e) => {
749+
fatal(&format!("Failed to setup Python process for \
750+
LLDB script: {}", e))
751+
}
752+
};
746753

747-
dump_output(config, test_executable, &out, &err);
748-
return ProcRes {
749-
status: Status::Normal(status),
750-
stdout: out,
751-
stderr: err,
752-
cmdline: format!("{:?}", cmd)
753-
};
754+
dump_output(config, test_executable, &out, &err);
755+
ProcRes {
756+
status: Status::Normal(status),
757+
stdout: out,
758+
stderr: err,
759+
cmdline: format!("{:?}", cmd)
754760
}
755761
}
756762

@@ -1157,6 +1163,24 @@ fn compile_test_(config: &Config, props: &TestProps,
11571163
compose_and_run_compiler(config, props, testfile, args, None)
11581164
}
11591165

1166+
fn document(config: &Config, props: &TestProps,
1167+
testfile: &Path, extra_args: &[String]) -> (ProcRes, PathBuf) {
1168+
let aux_dir = aux_output_dir_name(config, testfile);
1169+
let out_dir = output_base_name(config, testfile);
1170+
ensure_dir(&out_dir);
1171+
let mut args = vec!["-L".to_string(),
1172+
aux_dir.to_str().unwrap().to_string(),
1173+
"-o".to_string(),
1174+
out_dir.to_str().unwrap().to_string(),
1175+
testfile.to_str().unwrap().to_string()];
1176+
args.extend(extra_args.iter().cloned());
1177+
let args = ProcArgs {
1178+
prog: config.rustdoc_path.to_str().unwrap().to_string(),
1179+
args: args,
1180+
};
1181+
(compose_and_run_compiler(config, props, testfile, args, None), out_dir)
1182+
}
1183+
11601184
fn exec_compiled_test(config: &Config, props: &TestProps,
11611185
testfile: &Path) -> ProcRes {
11621186

@@ -1181,20 +1205,17 @@ fn exec_compiled_test(config: &Config, props: &TestProps,
11811205
}
11821206
}
11831207

1184-
fn compose_and_run_compiler(
1185-
config: &Config,
1186-
props: &TestProps,
1187-
testfile: &Path,
1188-
args: ProcArgs,
1189-
input: Option<String>) -> ProcRes {
1190-
1208+
fn compose_and_run_compiler(config: &Config, props: &TestProps,
1209+
testfile: &Path, args: ProcArgs,
1210+
input: Option<String>) -> ProcRes {
11911211
if !props.aux_builds.is_empty() {
11921212
ensure_dir(&aux_output_dir_name(config, testfile));
11931213
}
11941214

11951215
let aux_dir = aux_output_dir_name(config, testfile);
11961216
// FIXME (#9639): This needs to handle non-utf8 paths
1197-
let extra_link_args = vec!("-L".to_string(), aux_dir.to_str().unwrap().to_string());
1217+
let extra_link_args = vec!["-L".to_string(),
1218+
aux_dir.to_str().unwrap().to_string()];
11981219

11991220
for rel_ab in &props.aux_builds {
12001221
let abs_ab = config.aux_base.join(rel_ab);
@@ -1330,8 +1351,8 @@ fn make_exe_name(config: &Config, testfile: &Path) -> PathBuf {
13301351
f
13311352
}
13321353

1333-
fn make_run_args(config: &Config, props: &TestProps, testfile: &Path) ->
1334-
ProcArgs {
1354+
fn make_run_args(config: &Config, props: &TestProps, testfile: &Path)
1355+
-> ProcArgs {
13351356
// If we've got another tool to run under (valgrind),
13361357
// then split apart its command
13371358
let mut args = split_maybe_args(&config.runtool);
@@ -1797,3 +1818,21 @@ fn charset() -> &'static str {
17971818
"UTF-8"
17981819
}
17991820
}
1821+
1822+
fn run_rustdoc_test(config: &Config, props: &TestProps, testfile: &Path) {
1823+
let (proc_res, out_dir) = document(config, props, testfile, &[]);
1824+
if !proc_res.status.success() {
1825+
fatal_proc_rec("rustdoc failed!", &proc_res);
1826+
}
1827+
let root = find_rust_src_root(config).unwrap();
1828+
1829+
let res = cmd2proces(config,
1830+
testfile,
1831+
Command::new(&config.python)
1832+
.arg(root.join("src/etc/htmldocck.py"))
1833+
.arg(out_dir)
1834+
.arg(testfile));
1835+
if !res.status.success() {
1836+
fatal_proc_rec("htmldocck failed!", &res);
1837+
}
1838+
}

0 commit comments

Comments
 (0)