|
|
@ -48,6 +48,10 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { |
|
|
|
run::<SocketRunner>(tests); |
|
|
|
run::<SocketRunner>(tests); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use a neat little trick with cfg(doctest) to make code fences appear in
|
|
|
|
|
|
|
|
// rustdoc output, but still compile normally when doctesting. This raises warnings
|
|
|
|
|
|
|
|
// for invalid code though, so we also silence that lint here.
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), allow(rustdoc::invalid_rust_codeblocks))] |
|
|
|
/// Helper macro for writing doctests using this runner. Wrap this macro around
|
|
|
|
/// Helper macro for writing doctests using this runner. Wrap this macro around
|
|
|
|
/// your normal doctest to enable running it with the test runners in this crate.
|
|
|
|
/// your normal doctest to enable running it with the test runners in this crate.
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -59,22 +63,27 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ## Custom runner
|
|
|
|
/// ## Custom runner
|
|
|
|
///
|
|
|
|
///
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
/// ```no_run
|
|
|
|
/// ```no_run
|
|
|
|
/// test_runner::doctest! { SocketRunner,
|
|
|
|
/// test_runner::doctest! { SocketRunner,
|
|
|
|
/// assert_eq!(2 + 2, 4);
|
|
|
|
/// assert_eq!(2 + 2, 4);
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ## `should_panic`
|
|
|
|
/// ## `should_panic`
|
|
|
|
///
|
|
|
|
///
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
/// ```should_panic
|
|
|
|
/// ```should_panic
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// assert_eq!(2 + 2, 5);
|
|
|
|
/// assert_eq!(2 + 2, 5);
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ## Custom `fn main`
|
|
|
|
/// ## Custom `fn main`
|
|
|
|
///
|
|
|
|
///
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// fn main() {
|
|
|
|
/// fn main() {
|
|
|
@ -82,7 +91,9 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { |
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
///
|
|
|
|
///
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
@ -91,18 +102,21 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { |
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ## Implicit return type
|
|
|
|
/// ## Implicit return type
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Note that for the rustdoc preprocessor to understand the return type, the
|
|
|
|
/// Note that for the rustdoc preprocessor to understand the return type, the
|
|
|
|
/// `Ok(())` expression must be written _outside_ the `doctest!` invocation.
|
|
|
|
/// `Ok(())` expression must be written _outside_ the `doctest!` invocation.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// test_runner::doctest! {
|
|
|
|
/// assert_eq!(2 + 2, 4);
|
|
|
|
/// assert_eq!(2 + 2, 4);
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// Ok::<(), std::io::Error>(())
|
|
|
|
/// Ok::<(), std::io::Error>(())
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
#[cfg_attr(not(doctest), doc = "````")] |
|
|
|
#[macro_export] |
|
|
|
#[macro_export] |
|
|
|
macro_rules! doctest { |
|
|
|
macro_rules! doctest { |
|
|
|
($runner:ident, fn main() $(-> $ret:ty)? { $($body:tt)* } ) => { |
|
|
|
($runner:ident, fn main() $(-> $ret:ty)? { $($body:tt)* } ) => { |
|
|
@ -228,9 +242,6 @@ mod link_fix { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(doctest)] |
|
|
|
|
|
|
|
struct Dummy; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
#[cfg(test)] |
|
|
|
mod tests { |
|
|
|
mod tests { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|