Skip to content

Commit 3bc5caa

Browse files
authored
Merge pull request #1523 from kngwyu/refactor-doctest
Refactor doctest
2 parents d9fe4ec + 46de29b commit 3bc5caa

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

src/lib.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -398,55 +398,52 @@ macro_rules! py_run_impl {
398398
}
399399

400400
/// Test readme and user guide
401-
#[doc(hidden)]
401+
#[cfg(doctest)]
402402
pub mod doc_test {
403-
macro_rules! doc_comment {
404-
($x:expr, $module:item) => {
405-
#[doc = $x]
406-
$module
403+
macro_rules! doctest_impl {
404+
($doc:expr, $mod:ident) => {
405+
#[doc = $doc]
406+
mod $mod {}
407407
};
408408
}
409409

410410
macro_rules! doctest {
411-
($x:expr, $y:ident) => {
412-
doc_comment!(include_str!($x), mod $y {});
411+
($path:expr, $mod:ident) => {
412+
doctest_impl!(include_str!(concat!("../", $path)), $mod);
413413
};
414414
}
415415

416-
doctest!("../README.md", readme_md);
417-
doctest!("../guide/src/advanced.md", guide_advanced_md);
416+
doctest!("README.md", readme_md);
417+
doctest!("guide/src/advanced.md", guide_advanced_md);
418418
doctest!(
419-
"../guide/src/building_and_distribution.md",
419+
"guide/src/building_and_distribution.md",
420420
guide_building_and_distribution_md
421421
);
422422
doctest!(
423-
"../guide/src/building_and_distribution/pypy.md",
423+
"guide/src/building_and_distribution/pypy.md",
424424
guide_building_and_distribution_pypy_md
425425
);
426-
doctest!("../guide/src/class.md", guide_class_md);
427-
doctest!("../guide/src/class/protocols.md", guide_class_protocols_md);
428-
doctest!("../guide/src/conversions.md", guide_conversions_md);
426+
doctest!("guide/src/class.md", guide_class_md);
427+
doctest!("guide/src/class/protocols.md", guide_class_protocols_md);
428+
doctest!("guide/src/conversions.md", guide_conversions_md);
429429
doctest!(
430-
"../guide/src/conversions/tables.md",
430+
"guide/src/conversions/tables.md",
431431
guide_conversions_tables_md
432432
);
433433
doctest!(
434-
"../guide/src/conversions/traits.md",
434+
"guide/src/conversions/traits.md",
435435
guide_conversions_traits_md
436436
);
437-
doctest!("../guide/src/debugging.md", guide_debugging_md);
438-
doctest!("../guide/src/exception.md", guide_exception_md);
439-
doctest!("../guide/src/function.md", guide_function_md);
440-
doctest!("../guide/src/migration.md", guide_migration_md);
441-
doctest!("../guide/src/module.md", guide_module_md);
442-
doctest!("../guide/src/parallelism.md", guide_parallelism_md);
443-
doctest!(
444-
"../guide/src/python_from_rust.md",
445-
guide_python_from_rust_md
446-
);
447-
doctest!("../guide/src/rust_cpython.md", guide_rust_cpython_md);
448-
doctest!("../guide/src/trait_bounds.md", guide_trait_bounds_md);
449-
doctest!("../guide/src/types.md", guide_types_md);
437+
doctest!("guide/src/debugging.md", guide_debugging_md);
438+
doctest!("guide/src/exception.md", guide_exception_md);
439+
doctest!("guide/src/function.md", guide_function_md);
440+
doctest!("guide/src/migration.md", guide_migration_md);
441+
doctest!("guide/src/module.md", guide_module_md);
442+
doctest!("guide/src/parallelism.md", guide_parallelism_md);
443+
doctest!("guide/src/python_from_rust.md", guide_python_from_rust_md);
444+
doctest!("guide/src/rust_cpython.md", guide_rust_cpython_md);
445+
doctest!("guide/src/trait_bounds.md", guide_trait_bounds_md);
446+
doctest!("guide/src/types.md", guide_types_md);
450447
}
451448

452449
// interim helper until #[cfg(panic = ...)] is stable

0 commit comments

Comments
 (0)