Rename DocTest into DocTestBuilder

This commit is contained in:
Guillaume Gomez 2024-06-23 14:33:13 +02:00
parent 1e1743a379
commit ffc18c5cfb
5 changed files with 22 additions and 17 deletions

View file

@ -11,7 +11,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::{panic, str};
pub(crate) use make::DocTest;
pub(crate) use make::DocTestBuilder;
pub(crate) use markdown::test as test_markdown;
use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@ -250,7 +250,7 @@ pub(crate) fn run_tests(
rustdoc_options: &Arc<RustdocOptions>,
unused_extern_reports: &Arc<Mutex<Vec<UnusedExterns>>>,
mut standalone_tests: Vec<test::TestDescAndFn>,
mergeable_tests: FxHashMap<Edition, Vec<(DocTest, ScrapedDoctest)>>,
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDoctest)>>,
) {
let mut test_args = Vec::with_capacity(rustdoc_options.test_args.len() + 1);
test_args.insert(0, "rustdoctest".to_string());
@ -754,7 +754,7 @@ pub(crate) trait DoctestVisitor {
struct CreateRunnableDoctests {
standalone_tests: Vec<test::TestDescAndFn>,
mergeable_tests: FxHashMap<Edition, Vec<(DocTest, ScrapedDoctest)>>,
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDoctest)>>,
rustdoc_options: Arc<RustdocOptions>,
opts: GlobalTestOptions,
@ -803,7 +803,7 @@ impl CreateRunnableDoctests {
);
let edition = scraped_test.edition(&self.rustdoc_options);
let doctest = DocTest::new(
let doctest = DocTestBuilder::new(
&scraped_test.text,
Some(&self.opts.crate_name),
edition,
@ -827,7 +827,7 @@ impl CreateRunnableDoctests {
fn generate_test_desc_and_fn(
&mut self,
test: DocTest,
test: DocTestBuilder,
scraped_test: ScrapedDoctest,
) -> test::TestDescAndFn {
if !scraped_test.langstr.compile_fail {
@ -845,7 +845,7 @@ impl CreateRunnableDoctests {
}
fn generate_test_desc_and_fn(
test: DocTest,
test: DocTestBuilder,
scraped_test: ScrapedDoctest,
opts: GlobalTestOptions,
rustdoc_options: Arc<RustdocOptions>,
@ -892,7 +892,7 @@ fn generate_test_desc_and_fn(
fn doctest_run_fn(
test_opts: IndividualTestOptions,
global_opts: GlobalTestOptions,
doctest: DocTest,
doctest: DocTestBuilder,
scraped_test: ScrapedDoctest,
rustdoc_options: Arc<RustdocOptions>,
unused_externs: Arc<Mutex<Vec<UnusedExterns>>>,

View file

@ -19,7 +19,7 @@ use super::GlobalTestOptions;
/// This struct contains information about the doctest itself which is then used to generate
/// doctest source code appropriately.
pub(crate) struct DocTest {
pub(crate) struct DocTestBuilder {
pub(crate) supports_color: bool,
pub(crate) already_has_extern_crate: bool,
pub(crate) has_main_fn: bool,
@ -34,7 +34,7 @@ pub(crate) struct DocTest {
pub(crate) can_be_merged: bool,
}
impl DocTest {
impl DocTestBuilder {
pub(crate) fn new(
source: &str,
crate_name: Option<&str>,

View file

@ -4,8 +4,8 @@ use rustc_span::edition::Edition;
use std::fmt::Write;
use crate::doctest::{
run_test, DocTest, GlobalTestOptions, IndividualTestOptions, RunnableDoctest, RustdocOptions,
ScrapedDoctest, TestFailure, UnusedExterns,
run_test, DocTestBuilder, GlobalTestOptions, IndividualTestOptions, RunnableDoctest,
RustdocOptions, ScrapedDoctest, TestFailure, UnusedExterns,
};
use crate::html::markdown::{Ignore, LangString};
@ -31,7 +31,7 @@ impl DocTestRunner {
pub(crate) fn add_test(
&mut self,
doctest: &DocTest,
doctest: &DocTestBuilder,
scraped_test: &ScrapedDoctest,
target_str: &str,
) {
@ -193,7 +193,7 @@ std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), N
/// Push new doctest content into `output`. Returns the test ID for this doctest.
fn generate_mergeable_doctest(
doctest: &DocTest,
doctest: &DocTestBuilder,
scraped_test: &ScrapedDoctest,
ignore: bool,
id: usize,

View file

@ -1,6 +1,6 @@
use std::path::PathBuf;
use super::{DocTest, GlobalTestOptions};
use super::{DocTestBuilder, GlobalTestOptions};
use rustc_span::edition::DEFAULT_EDITION;
fn make_test(
@ -10,8 +10,13 @@ fn make_test(
opts: &GlobalTestOptions,
test_id: Option<&str>,
) -> (String, usize) {
let doctest =
DocTest::new(test_code, crate_name, DEFAULT_EDITION, false, test_id.map(|s| s.to_string()));
let doctest = DocTestBuilder::new(
test_code,
crate_name,
DEFAULT_EDITION,
false,
test_id.map(|s| s.to_string()),
);
let (code, line_offset) =
doctest.generate_unique_doctest(test_code, dont_insert_main, opts, crate_name);
(code, line_offset)

View file

@ -297,7 +297,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
attrs: vec![],
args_file: PathBuf::new(),
};
let doctest = doctest::DocTest::new(&test, krate, edition, false, None);
let doctest = doctest::DocTestBuilder::new(&test, krate, edition, false, None);
let (test, _) = doctest.generate_unique_doctest(&test, false, &opts, krate);
let channel = if test.contains("#![feature(") { "&amp;version=nightly" } else { "" };