Skip to content

Commit ab3d90e

Browse files
Unify naming of DocTest
1 parent 4b1db07 commit ab3d90e

File tree

6 files changed

+46
-42
lines changed

6 files changed

+46
-42
lines changed

src/librustdoc/doctest.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, options: RustdocOptions) -> Result<()
163163
let args_path = temp_dir.path().join("rustdoc-cfgs");
164164
crate::wrap_return(dcx, generate_args_file(&args_path, &options))?;
165165

166-
let CreateRunnableDoctests {
166+
let CreateRunnableDocTests {
167167
standalone_tests,
168168
mergeable_tests,
169169
rustdoc_options,
@@ -179,7 +179,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, options: RustdocOptions) -> Result<()
179179
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
180180
let enable_per_target_ignores = options.enable_per_target_ignores;
181181

182-
let mut collector = CreateRunnableDoctests::new(options, opts);
182+
let mut collector = CreateRunnableDocTests::new(options, opts);
183183
let hir_collector = HirCollector::new(
184184
&compiler.sess,
185185
tcx.hir(),
@@ -250,7 +250,7 @@ pub(crate) fn run_tests(
250250
rustdoc_options: &Arc<RustdocOptions>,
251251
unused_extern_reports: &Arc<Mutex<Vec<UnusedExterns>>>,
252252
mut standalone_tests: Vec<test::TestDescAndFn>,
253-
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDoctest)>>,
253+
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
254254
) {
255255
let mut test_args = Vec::with_capacity(rustdoc_options.test_args.len() + 1);
256256
test_args.insert(0, "rustdoctest".to_string());
@@ -432,8 +432,13 @@ fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Com
432432
command
433433
}
434434

435-
/// This struct contains information needed for running a doctest.
436-
struct RunnableDoctest {
435+
/// Information needed for running a bundle of doctests.
436+
///
437+
/// This data structure contains the "full" test code, including the wrappers
438+
/// (if multiple doctests are merged), `main` function,
439+
/// and everything needed to calculate the compiler's command-line arguments.
440+
/// The `# ` prefix on boring lines has also been stripped.
441+
struct RunnableDocTest {
437442
full_test_code: String,
438443
full_test_line_offset: usize,
439444
test_opts: IndividualTestOptions,
@@ -444,14 +449,14 @@ struct RunnableDoctest {
444449
no_run: bool,
445450
}
446451

447-
impl RunnableDoctest {
452+
impl RunnableDocTest {
448453
fn path_for_merged_doctest(&self) -> PathBuf {
449454
self.test_opts.outdir.path().join(&format!("doctest_{}.rs", self.edition))
450455
}
451456
}
452457

453458
fn run_test(
454-
doctest: RunnableDoctest,
459+
doctest: RunnableDocTest,
455460
rustdoc_options: &RustdocOptions,
456461
supports_color: bool,
457462
is_multiple_tests: bool,
@@ -700,15 +705,15 @@ impl IndividualTestOptions {
700705
}
701706

702707
/// A doctest scraped from the code, ready to be turned into a runnable test.
703-
pub(crate) struct ScrapedDoctest {
708+
pub(crate) struct ScrapedDocTest {
704709
filename: FileName,
705710
line: usize,
706711
langstr: LangString,
707712
text: String,
708713
name: String,
709714
}
710715

711-
impl ScrapedDoctest {
716+
impl ScrapedDocTest {
712717
fn new(
713718
filename: FileName,
714719
line: usize,
@@ -748,14 +753,14 @@ impl ScrapedDoctest {
748753
}
749754
}
750755

751-
pub(crate) trait DoctestVisitor {
756+
pub(crate) trait DocTestVisitor {
752757
fn visit_test(&mut self, test: String, config: LangString, rel_line: MdRelLine);
753758
fn visit_header(&mut self, _name: &str, _level: u32) {}
754759
}
755760

756-
struct CreateRunnableDoctests {
761+
struct CreateRunnableDocTests {
757762
standalone_tests: Vec<test::TestDescAndFn>,
758-
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDoctest)>>,
763+
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
759764

760765
rustdoc_options: Arc<RustdocOptions>,
761766
opts: GlobalTestOptions,
@@ -765,10 +770,10 @@ struct CreateRunnableDoctests {
765770
can_merge_doctests: bool,
766771
}
767772

768-
impl CreateRunnableDoctests {
769-
fn new(rustdoc_options: RustdocOptions, opts: GlobalTestOptions) -> CreateRunnableDoctests {
773+
impl CreateRunnableDocTests {
774+
fn new(rustdoc_options: RustdocOptions, opts: GlobalTestOptions) -> CreateRunnableDocTests {
770775
let can_merge_doctests = rustdoc_options.edition >= Edition::Edition2024;
771-
CreateRunnableDoctests {
776+
CreateRunnableDocTests {
772777
standalone_tests: Vec::new(),
773778
mergeable_tests: FxHashMap::default(),
774779
rustdoc_options: Arc::new(rustdoc_options),
@@ -780,7 +785,7 @@ impl CreateRunnableDoctests {
780785
}
781786
}
782787

783-
fn add_test(&mut self, scraped_test: ScrapedDoctest) {
788+
fn add_test(&mut self, scraped_test: ScrapedDocTest) {
784789
// For example `module/file.rs` would become `module_file_rs`
785790
let file = scraped_test
786791
.filename
@@ -829,7 +834,7 @@ impl CreateRunnableDoctests {
829834
fn generate_test_desc_and_fn(
830835
&mut self,
831836
test: DocTestBuilder,
832-
scraped_test: ScrapedDoctest,
837+
scraped_test: ScrapedDocTest,
833838
) -> test::TestDescAndFn {
834839
if !scraped_test.langstr.compile_fail {
835840
self.compiling_test_count.fetch_add(1, Ordering::SeqCst);
@@ -847,7 +852,7 @@ impl CreateRunnableDoctests {
847852

848853
fn generate_test_desc_and_fn(
849854
test: DocTestBuilder,
850-
scraped_test: ScrapedDoctest,
855+
scraped_test: ScrapedDocTest,
851856
opts: GlobalTestOptions,
852857
rustdoc_options: Arc<RustdocOptions>,
853858
unused_externs: Arc<Mutex<Vec<UnusedExterns>>>,
@@ -894,7 +899,7 @@ fn doctest_run_fn(
894899
test_opts: IndividualTestOptions,
895900
global_opts: GlobalTestOptions,
896901
doctest: DocTestBuilder,
897-
scraped_test: ScrapedDoctest,
902+
scraped_test: ScrapedDocTest,
898903
rustdoc_options: Arc<RustdocOptions>,
899904
unused_externs: Arc<Mutex<Vec<UnusedExterns>>>,
900905
) -> Result<(), String> {
@@ -907,7 +912,7 @@ fn doctest_run_fn(
907912
&global_opts,
908913
Some(&global_opts.crate_name),
909914
);
910-
let runnable_test = RunnableDoctest {
915+
let runnable_test = RunnableDocTest {
911916
full_test_code,
912917
full_test_line_offset,
913918
test_opts,
@@ -980,7 +985,7 @@ fn doctest_run_fn(
980985
}
981986

982987
#[cfg(test)] // used in tests
983-
impl DoctestVisitor for Vec<usize> {
988+
impl DocTestVisitor for Vec<usize> {
984989
fn visit_test(&mut self, _test: String, _config: LangString, rel_line: MdRelLine) {
985990
self.push(1 + rel_line.offset());
986991
}

src/librustdoc/doctest/markdown.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ use rustc_span::FileName;
77
use tempfile::tempdir;
88

99
use super::{
10-
generate_args_file, CreateRunnableDoctests, DoctestVisitor, GlobalTestOptions, ScrapedDoctest,
10+
generate_args_file, CreateRunnableDocTests, DocTestVisitor, GlobalTestOptions, ScrapedDocTest,
1111
};
1212
use crate::config::Options;
1313
use crate::html::markdown::{find_testable_code, ErrorCodes, LangString, MdRelLine};
1414

1515
struct MdCollector {
16-
tests: Vec<ScrapedDoctest>,
16+
tests: Vec<ScrapedDocTest>,
1717
cur_path: Vec<String>,
1818
filename: FileName,
1919
}
2020

21-
impl DoctestVisitor for MdCollector {
21+
impl DocTestVisitor for MdCollector {
2222
fn visit_test(&mut self, test: String, config: LangString, rel_line: MdRelLine) {
2323
let filename = self.filename.clone();
2424
// First line of Markdown is line 1.
2525
let line = 1 + rel_line.offset();
26-
self.tests.push(ScrapedDoctest::new(filename, line, self.cur_path.clone(), config, test));
26+
self.tests.push(ScrapedDocTest::new(filename, line, self.cur_path.clone(), config, test));
2727
}
2828

2929
fn visit_header(&mut self, name: &str, level: u32) {
@@ -113,9 +113,9 @@ pub(crate) fn test(options: Options) -> Result<(), String> {
113113
None,
114114
);
115115

116-
let mut collector = CreateRunnableDoctests::new(options.clone(), opts);
116+
let mut collector = CreateRunnableDocTests::new(options.clone(), opts);
117117
md_collector.tests.into_iter().for_each(|t| collector.add_test(t));
118-
let CreateRunnableDoctests { opts, rustdoc_options, standalone_tests, mergeable_tests, .. } =
118+
let CreateRunnableDocTests { opts, rustdoc_options, standalone_tests, mergeable_tests, .. } =
119119
collector;
120120
crate::doctest::run_tests(
121121
opts,

src/librustdoc/doctest/runner.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use rustc_span::edition::Edition;
44
use std::fmt::Write;
55

66
use crate::doctest::{
7-
run_test, DocTestBuilder, GlobalTestOptions, IndividualTestOptions, RunnableDoctest,
8-
RustdocOptions, ScrapedDoctest, TestFailure, UnusedExterns,
7+
run_test, DocTestBuilder, GlobalTestOptions, IndividualTestOptions, RunnableDocTest,
8+
RustdocOptions, ScrapedDocTest, TestFailure, UnusedExterns,
99
};
1010
use crate::html::markdown::{Ignore, LangString};
1111

@@ -32,7 +32,7 @@ impl DocTestRunner {
3232
pub(crate) fn add_test(
3333
&mut self,
3434
doctest: &DocTestBuilder,
35-
scraped_test: &ScrapedDoctest,
35+
scraped_test: &ScrapedDocTest,
3636
target_str: &str,
3737
) {
3838
let ignore = match scraped_test.langstr.ignore {
@@ -175,7 +175,7 @@ std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), N
175175
ids = self.ids,
176176
)
177177
.expect("failed to generate test code");
178-
let runnable_test = RunnableDoctest {
178+
let runnable_test = RunnableDocTest {
179179
full_test_code: code,
180180
full_test_line_offset: 0,
181181
test_opts: test_options,
@@ -199,7 +199,7 @@ std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), N
199199
/// Push new doctest content into `output`. Returns the test ID for this doctest.
200200
fn generate_mergeable_doctest(
201201
doctest: &DocTestBuilder,
202-
scraped_test: &ScrapedDoctest,
202+
scraped_test: &ScrapedDocTest,
203203
ignore: bool,
204204
id: usize,
205205
output: &mut String,

src/librustdoc/doctest/rust.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ use rustc_session::Session;
1414
use rustc_span::source_map::SourceMap;
1515
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
1616

17-
use super::{DoctestVisitor, ScrapedDoctest};
18-
use crate::clean::types::AttributesExt;
19-
use crate::clean::Attributes;
17+
use super::{DocTestVisitor, ScrapedDocTest};
18+
use crate::clean::{types::AttributesExt, Attributes};
2019
use crate::html::markdown::{self, ErrorCodes, LangString, MdRelLine};
2120

2221
struct RustCollector {
2322
source_map: Lrc<SourceMap>,
24-
tests: Vec<ScrapedDoctest>,
23+
tests: Vec<ScrapedDocTest>,
2524
cur_path: Vec<String>,
2625
position: Span,
2726
}
@@ -48,10 +47,10 @@ impl RustCollector {
4847
}
4948
}
5049

51-
impl DoctestVisitor for RustCollector {
50+
impl DocTestVisitor for RustCollector {
5251
fn visit_test(&mut self, test: String, config: LangString, rel_line: MdRelLine) {
5352
let line = self.get_base_line() + rel_line.offset();
54-
self.tests.push(ScrapedDoctest::new(
53+
self.tests.push(ScrapedDocTest::new(
5554
self.get_filename(),
5655
line,
5756
self.cur_path.clone(),
@@ -89,7 +88,7 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> {
8988
Self { sess, map, codes, enable_per_target_ignores, tcx, collector }
9089
}
9190

92-
pub fn collect_crate(mut self) -> Vec<ScrapedDoctest> {
91+
pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> {
9392
let tcx = self.tcx;
9493
self.visit_testable("".to_string(), CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID), |this| {
9594
tcx.hir().walk_toplevel_module(this)

src/librustdoc/html/markdown.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl MdRelLine {
738738
}
739739
}
740740

741-
pub(crate) fn find_testable_code<T: doctest::DoctestVisitor>(
741+
pub(crate) fn find_testable_code<T: doctest::DocTestVisitor>(
742742
doc: &str,
743743
tests: &mut T,
744744
error_codes: ErrorCodes,
@@ -748,7 +748,7 @@ pub(crate) fn find_testable_code<T: doctest::DoctestVisitor>(
748748
find_codes(doc, tests, error_codes, enable_per_target_ignores, extra_info, false)
749749
}
750750

751-
pub(crate) fn find_codes<T: doctest::DoctestVisitor>(
751+
pub(crate) fn find_codes<T: doctest::DocTestVisitor>(
752752
doc: &str,
753753
tests: &mut T,
754754
error_codes: ErrorCodes,

src/librustdoc/passes/check_doc_test_visibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) struct Tests {
4545
pub(crate) found_tests: usize,
4646
}
4747

48-
impl crate::doctest::DoctestVisitor for Tests {
48+
impl crate::doctest::DocTestVisitor for Tests {
4949
fn visit_test(&mut self, _: String, config: LangString, _: MdRelLine) {
5050
if config.rust && config.ignore == Ignore::None {
5151
self.found_tests += 1;

0 commit comments

Comments
 (0)