Sfoglia il codice sorgente

src/lib.rs: Make "cargo test" run on examples from README.md

We have several code snippets in the README.md file, some ignored
(because it's irrelevant to compile and run them), some not. They are
currently not tested by "cargo test". Let's include the file as part as
the documentation for the library, so that these examples are
automatically tested.

Note that the file name and lines indicated in the output for the tests
are not relevant to the README.md file.

Reference:
https://github.com/rust-lang/rust/blob/5f4e0677190b/src/doc/rustdoc/src/write-documentation/documentation-tests.md#include-items-only-when-collecting-doctests

Note that there's a related issue in cargo to add native support for
tests on README's examples:
https://github.com/rust-lang/cargo/issues/383

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Quentin Monnet 2 anni fa
parent
commit
7f73a1c88d
1 ha cambiato i file con 3 aggiunte e 0 eliminazioni
  1. 3 0
      src/lib.rs

+ 3 - 0
src/lib.rs

@@ -9,6 +9,9 @@
 #![doc(html_logo_url = "https://raw.githubusercontent.com/qmonnet/rbpf/master/misc/rbpf.png",
        html_favicon_url = "https://raw.githubusercontent.com/qmonnet/rbpf/master/misc/rbpf.ico")]
 
+// Test examples from README.md as part as doc tests.
+#![doc = include_str!("../README.md")]
+
 #![warn(missing_docs)]
 // There are unused mut warnings due to unsafe code.
 #![allow(unused_mut)]