From 4bfc8a41851b1f8be7eae85e0f2abd9ea360ee16 Mon Sep 17 00:00:00 2001
From: Brian Gianforcaro <bgianf@microsoft.com>
Date: Mon, 2 Dec 2019 01:11:00 -0800
Subject: [PATCH] Tests: Fix doc-tests for README.md

cfg(test) is no longer set during doctests
See: rust-lang/rust#45599
---
 Cargo.toml    |  3 ++-
 README.md     | 61 +++++++++++++++++++++++++--------------------------
 src/lib.rs    |  5 +++++
 tests/docs.rs |  9 --------
 4 files changed, 37 insertions(+), 41 deletions(-)
 delete mode 100644 tests/docs.rs

diff --git a/Cargo.toml b/Cargo.toml
index 7770660..da388a9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,8 +18,9 @@ travis-ci = { repository = "bgianfo/rust-run-down", branch = "master" }
 bitflags = "1.2.1"
 lazy-init = "0.3.0"
 rsevents = "0.2.0"
+# See: https://github.com/rust-lang/rust/issues/45599
+doc-comment = "0.3.1"
 
 [dev-dependencies]
 assert-impl = "0.1.3"
 pretty_assertions = "0.6"
-doc-comment = "0.3.1"
diff --git a/README.md b/README.md
index 3b3f335..f7e34ca 100644
--- a/README.md
+++ b/README.md
@@ -10,48 +10,47 @@ and the ability to wait for all outstanding usages to drain so you can safely pe
 
 This crate was inspired by the [run-down protection primitive available in the NT Kernel][nt-run-down-docs]. 
 
+
 ## Usage example
 
-````rust
-use run_down::{RundownGuard, RundownRef};
+```rust
+use run_down::{
+    RundownGuard,
+    RundownRef
+};
 use std::sync::Arc;
 use std::thread;
 use std::time::Duration;
 
-fn example() {
+let rundown = Arc::new(RundownRef::new());
+
+for i in 1..25 {
 
-    let rundown = Arc::new(RundownRef::new());
+    let rundown_clone = Arc::clone(&rundown);
 
-    for _ in 0..50 {
+    thread::spawn(move || {
     
-        let rundown_clone = Arc::clone(&rundown);
-
-        thread::spawn(move || {
-        
-            // Attempt to acquire rundown protection, while the main
-            // thread could be running down the object as we execute.
-            // 
-            match rundown_clone.try_acquire() {
-                Ok(_) => {
-                    println!("{}: Run-down protection acquired.", thread::current().id());
-                    
-                    // Stall the thread while holding rundown protection.
-                    thread::sleep(Duration::from_millis(10)); 
-                }
-                Err(m) => {
-                    println!("{}: Failed to acquire run-down protection - {}",
-                        thread::current().id(),
-                        m);
-                },
+        // Attempt to acquire rundown protection, while the main
+        // thread could be running down the object as we execute.
+        // 
+        match rundown_clone.try_acquire() {
+            Ok(_) => {
+                println!("{}: Run-down protection acquired.", i);
+
+                // Stall the thread while holding rundown protection.
+                thread::sleep(Duration::from_millis(10));
             }
-        });
-    }
-
-    println!("{}: Waiting for rundown to complete", thread::current().id());
-    rundown.wait_for_rundown();
-    println!("{}: Rundown complete", thread::current().id());
+            Err(m) => {
+                println!("{}: Failed to acquire run-down protection - {:?}", i, m);
+            },
+        }
+    });
 }
-````
+
+println!("0: Waiting for rundown to complete");
+rundown.wait_for_rundown();
+println!("0: Rundown complete");
+```
 
 ## TODO
 
diff --git a/src/lib.rs b/src/lib.rs
index e6f6053..a144502 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -41,3 +41,8 @@ mod rundown_ref;
 pub use guard::RundownGuard;
 pub use rundown_ref::RundownError;
 pub use rundown_ref::RundownRef;
+
+extern crate doc_comment;
+
+// Test examples in the README file.
+doc_comment::doctest!("../README.md", readme_examples);
diff --git a/tests/docs.rs b/tests/docs.rs
deleted file mode 100644
index bd65dca..0000000
--- a/tests/docs.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2019 Brian Gianforcaro
-
-#[cfg(test)]
-#[macro_use]
-extern crate doc_comment;
-
-// Test examples in the README file.
-#[cfg(test)]
-doctest!("../README.md");