From 56f808cddbdb8319d12db943e1b13365e3aa419a Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Mon, 20 May 2019 14:58:41 +0200 Subject: [PATCH] Use skeptic to verify examples in README.md --- .gitignore | 3 ++- Cargo.toml | 6 ++++++ README.md | 24 ++++++++++++++---------- build.rs | 6 ++++++ tests/skeptic.rs | 1 + 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 build.rs create mode 100644 tests/skeptic.rs diff --git a/.gitignore b/.gitignore index 2f88dba..9f9a923 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target **/*.rs.bk -Cargo.lock \ No newline at end of file +Cargo.lock +libtest.rmeta diff --git a/Cargo.toml b/Cargo.toml index 2846ff9..b505276 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,9 @@ travis-ci = { repository = "phw/rust-discid" } [dependencies] bitflags = "1.0.4" discid-sys = "0.2.0" + +[build-dependencies] +skeptic = "0.13" + +[dev-dependencies] +skeptic = "0.13" diff --git a/README.md b/README.md index b76f483..42a88ff 100644 --- a/README.md +++ b/README.md @@ -18,26 +18,30 @@ This library is currently in early development and the API may still change. ### Read only the TOC -```rust +```rust,no_run use discid::DiscId; -// Specifying the device is optional. If set to `None` a platform -// specific default will be used. -let device = Some("/dev/cdrom"); -let disc = DiscId::read(device).expect("Reading disc failed"); -println!("ID: {}", disc.id()); +fn main() { + // Specifying the device is optional. If set to `None` a platform + // specific default will be used. + let device = Some("/dev/cdrom"); + let disc = DiscId::read(device).expect("Reading disc failed"); + println!("ID: {}", disc.id()); +} ``` ### Read the TOC and ISRCs -```rust +```rust,no_run use discid::{DiscId, Features}; -let disc = DiscId::read_features(None, Features::ISRC).expect("Reading disc failed"); -println!("Disc ID: {}", disc.id()); +fn main() { + let disc = DiscId::read_features(None, Features::ISRC).expect("Reading disc failed"); + println!("Disc ID: {}", disc.id()); -for track in disc.tracks() { + for track in disc.tracks() { println!("Track #{} ISRC: {}", track.number, track.isrc); + } } ``` diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ec05710 --- /dev/null +++ b/build.rs @@ -0,0 +1,6 @@ +extern crate skeptic; + +fn main() { + // generates doc tests for `README.md`. + skeptic::generate_doc_tests(&["README.md"]); +} diff --git a/tests/skeptic.rs b/tests/skeptic.rs new file mode 100644 index 0000000..ff46c9c --- /dev/null +++ b/tests/skeptic.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs"));