Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 13acb1d

Browse files
Reduce merged doctest source code size
1 parent 91505a4 commit 13acb1d

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

library/test/src/types.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,37 @@ pub struct TestDescAndFn {
250250
pub desc: TestDesc,
251251
pub testfn: TestFn,
252252
}
253+
254+
impl TestDescAndFn {
255+
pub const fn new_doctest(
256+
test_name: &'static str,
257+
ignore: bool,
258+
source_file: &'static str,
259+
start_line: usize,
260+
no_run: bool,
261+
should_panic: bool,
262+
testfn: TestFn,
263+
) -> Self {
264+
Self {
265+
desc: TestDesc {
266+
name: StaticTestName(test_name),
267+
ignore,
268+
ignore_message: None,
269+
source_file,
270+
start_line,
271+
start_col: 0,
272+
end_line: 0,
273+
end_col: 0,
274+
compile_fail: false,
275+
no_run,
276+
should_panic: if should_panic {
277+
options::ShouldPanic::Yes
278+
} else {
279+
options::ShouldPanic::No
280+
},
281+
test_type: TestType::DocTest,
282+
},
283+
testfn,
284+
}
285+
}
286+
}

src/librustdoc/doctest/runner.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,36 +235,18 @@ fn main() {returns_result} {{
235235
output,
236236
"
237237
#[rustc_test_marker = {test_name:?}]
238-
pub const TEST: test::TestDescAndFn = test::TestDescAndFn {{
239-
desc: test::TestDesc {{
240-
name: test::StaticTestName({test_name:?}),
241-
ignore: {ignore},
242-
ignore_message: None,
243-
source_file: {file:?},
244-
start_line: {line},
245-
start_col: 0,
246-
end_line: 0,
247-
end_col: 0,
248-
compile_fail: false,
249-
no_run: {no_run},
250-
should_panic: test::ShouldPanic::{should_panic},
251-
test_type: test::TestType::DocTest,
252-
}},
253-
testfn: test::StaticTestFn(
254-
#[coverage(off)]
255-
|| {{{runner}}},
256-
)
257-
}};
238+
pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
239+
{test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic},
240+
test::StaticTestFn(
241+
#[coverage(off)]
242+
|| {{{runner}}},
243+
));
258244
}}",
259245
test_name = scraped_test.name,
260246
file = scraped_test.path(),
261247
line = scraped_test.line,
262248
no_run = scraped_test.langstr.no_run,
263-
should_panic = if !scraped_test.langstr.no_run && scraped_test.langstr.should_panic {
264-
"Yes"
265-
} else {
266-
"No"
267-
},
249+
should_panic = !scraped_test.langstr.no_run && scraped_test.langstr.should_panic,
268250
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
269251
// don't give it the function to run.
270252
runner = if not_running {

0 commit comments

Comments
 (0)