mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Reduce merged doctest source code size
This commit is contained in:
parent
d512438435
commit
1e1743a379
@ -250,3 +250,37 @@ pub struct TestDescAndFn {
|
||||
pub desc: TestDesc,
|
||||
pub testfn: TestFn,
|
||||
}
|
||||
|
||||
impl TestDescAndFn {
|
||||
pub const fn new_doctest(
|
||||
test_name: &'static str,
|
||||
ignore: bool,
|
||||
source_file: &'static str,
|
||||
start_line: usize,
|
||||
no_run: bool,
|
||||
should_panic: bool,
|
||||
testfn: TestFn,
|
||||
) -> Self {
|
||||
Self {
|
||||
desc: TestDesc {
|
||||
name: StaticTestName(test_name),
|
||||
ignore,
|
||||
ignore_message: None,
|
||||
source_file,
|
||||
start_line,
|
||||
start_col: 0,
|
||||
end_line: 0,
|
||||
end_col: 0,
|
||||
compile_fail: false,
|
||||
no_run,
|
||||
should_panic: if should_panic {
|
||||
options::ShouldPanic::Yes
|
||||
} else {
|
||||
options::ShouldPanic::No
|
||||
},
|
||||
test_type: TestType::DocTest,
|
||||
},
|
||||
testfn,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,36 +235,18 @@ fn main() {returns_result} {{
|
||||
output,
|
||||
"
|
||||
#[rustc_test_marker = {test_name:?}]
|
||||
pub const TEST: test::TestDescAndFn = test::TestDescAndFn {{
|
||||
desc: test::TestDesc {{
|
||||
name: test::StaticTestName({test_name:?}),
|
||||
ignore: {ignore},
|
||||
ignore_message: None,
|
||||
source_file: {file:?},
|
||||
start_line: {line},
|
||||
start_col: 0,
|
||||
end_line: 0,
|
||||
end_col: 0,
|
||||
compile_fail: false,
|
||||
no_run: {no_run},
|
||||
should_panic: test::ShouldPanic::{should_panic},
|
||||
test_type: test::TestType::DocTest,
|
||||
}},
|
||||
testfn: test::StaticTestFn(
|
||||
#[coverage(off)]
|
||||
|| {{{runner}}},
|
||||
)
|
||||
}};
|
||||
pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
|
||||
{test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic},
|
||||
test::StaticTestFn(
|
||||
#[coverage(off)]
|
||||
|| {{{runner}}},
|
||||
));
|
||||
}}",
|
||||
test_name = scraped_test.name,
|
||||
file = scraped_test.path(),
|
||||
line = scraped_test.line,
|
||||
no_run = scraped_test.langstr.no_run,
|
||||
should_panic = if !scraped_test.langstr.no_run && scraped_test.langstr.should_panic {
|
||||
"Yes"
|
||||
} else {
|
||||
"No"
|
||||
},
|
||||
should_panic = !scraped_test.langstr.no_run && scraped_test.langstr.should_panic,
|
||||
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
|
||||
// don't give it the function to run.
|
||||
runner = if not_running {
|
||||
|
Loading…
Reference in New Issue
Block a user