├── .clog.toml ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── appveyor.yml ├── src └── lib.rs └── tests └── test_readme.rs /.clog.toml: -------------------------------------------------------------------------------- 1 | [clog] 2 | repository = "https://github.com/assert-rs/docmatic" 3 | changelog = "CHANGELOG.md" 4 | from-latest-tag = true 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | I tried this code: 8 | 9 | 10 | 11 | I expected to see this happen: 12 | 13 | Instead this happened: 14 | 15 | ## Meta 16 | 17 | predicates-rs version: 18 | `rustc --version --verbose`: 19 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | Cargo.lock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: rust 3 | rust: 4 | - 1.24.0 # oldest supported version 5 | - stable 6 | - beta 7 | - nightly 8 | 9 | matrix: 10 | include: 11 | - env: RUSTFMT 12 | rust: 1.27.0 # `stable`: Locking down for consistent behavior 13 | install: 14 | - rustup component add rustfmt-preview 15 | script: 16 | - cargo fmt -- --write-mode=diff 17 | - env: RUSTFLAGS="-D warnings" 18 | rust: 1.27.0 # `stable`: Locking down for consistent behavior 19 | script: 20 | - cargo check --tests 21 | - env: CLIPPY 22 | rust: nightly-2018-07-17 23 | install: 24 | - rustup component add clippy-preview 25 | script: 26 | - cargo clippy --all-features -- -D clippy 27 | 28 | install: 29 | - rustc -Vv 30 | - cargo -V 31 | 32 | script: 33 | - rm -rf target/debug/deps/*docmatic* # Avoid link problems with cached versions 34 | - cargo test --verbose 35 | - cargo doc --no-deps 36 | 37 | cache: 38 | cargo: true 39 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## 0.1.2 (2018-04-25) 3 | 4 | 5 | #### Bug Fixes 6 | 7 | * Remove assert_file_impl from public API ([4fa6ac1f](https://github.com/assert-rs/docmatic/commit/4fa6ac1fc6b648cc699eca9f1b098177050bf568)) 8 | * **CI:** Bump minimum Rust version ([d5598851](https://github.com/assert-rs/docmatic/commit/d5598851752292344ef09a2e759936ef08991df3)) 9 | * **crate:** Remove unnecessary `glob` dependency ([59bffb4b](https://github.com/assert-rs/docmatic/commit/59bffb4bbc5529bf3a7d9168ff6eb74da87735e8)) 10 | 11 | #### Features 12 | 13 | * Add `docmatic::Assert` type and methods ([2ee9c763](https://github.com/assert-rs/docmatic/commit/2ee9c763f200ce1ce6f2a891f6d7ccf23d53e667)) 14 | 15 | 16 | 17 | 18 | ## 0.1.1 (2018-04-17) 19 | 20 | 21 | #### Bug Fixes 22 | 23 | * **crate:** Add metadata ([8cc81d0b](https://github.com/assert-rs/docmatic/commit/8cc81d0ba675a651360dccb33cd5056bc05b1c53), closes [#1](https://github.com/assert-rs/docmatic/issues/1)) 24 | 25 | 26 | 27 | 28 | ## 0.1.0 (2018-04-17) 29 | 30 | * Initial implementation ([0b0b5985](https://github.com/assert-rs/docmatic/commit/0b0b59857ee320a03a7721d131217a5f077b0954)) 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to docmatic 2 | 3 | Thanks for wanting to contribute! There are many ways to contribute and we 4 | appreciate any level you're willing to do. 5 | 6 | ## Feature Requests 7 | 8 | Need some new functionality to help? You can let us know by opening an 9 | [issue][new issue]. It's helpful to look through [all issues][all issues] in 10 | case its already being talked about. 11 | 12 | ## Bug Reports 13 | 14 | Please let us know about what problems you run into, whether in behavior or 15 | ergonomics of API. You can do this by opening an [issue][new issue]. It's 16 | helpful to look through [all issues][all issues] in case its already being 17 | talked about. 18 | 19 | ## Pull Requests 20 | 21 | Looking for an idea? Check our [issues][issues]. If it's look more open ended, 22 | it is probably best to post on the issue how you are thinking of resolving the 23 | issue so you can get feedback early in the process. We want you to be 24 | successful and it can be discouraging to find out a lot of re-work is needed. 25 | 26 | Already have an idea? It might be good to first [create an issue][new issue] 27 | to propose it so we can make sure we are aligned and lower the risk of having 28 | to re-work some of it and the discouragement that goes along with that. 29 | 30 | ### Process 31 | 32 | When you first post a PR, we request that the the commit history get cleaned 33 | up. We recommend avoiding this during the PR to make it easier to review how 34 | feedback was handled. Once the commit is ready, we'll ask you to clean up the 35 | commit history. Once you let us know this is done, we can move forward with 36 | merging! If you are uncomfortable with these parts of git, let us know and we 37 | can help. 38 | 39 | We ask that all new files have the copyright header. Please update the 40 | copyright year for files you are modifying. 41 | 42 | As a heads up, we'll be running your PR through the following gauntlet: 43 | - warnings turned to compile errors 44 | - `cargo test` 45 | - `rustfmt` 46 | - `clippy` 47 | - `rustdoc` 48 | 49 | Check out our [CI][travis] for more information. 50 | 51 | ## Releasing 52 | 53 | When we're ready to release, a project owner should do the following 54 | - Determine what the next version is, according to semver 55 | - Bump version in a commit 56 | - Update CHANGELOG.md 57 | - Update the version in `Cargo.toml` 58 | - Update the dependency version in `src/lib.rs` 59 | - Update the dependency version in `README.md` 60 | - Tag the commit via `git tag -am "v.." v..` 61 | - `git push upstream master --tag v..` 62 | - Run `cargo publish` (run `cargo login` first if needed) 63 | 64 | [issues]: https://github.com/assert-rs/docmatic/issues 65 | [new issue]: https://github.com/assert-rs/docmatic/issues/new 66 | [all issues]: https://github.com/assert-rs/docmatic/issues?utf8=%E2%9C%93&q=is%3Aissue 67 | [travis]: https://github.com/assert-rs/docmatic/blob/master/.travis.yml 68 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "docmatic" 3 | version = "0.1.2" 4 | authors = ["Ed Page ", "Martin Larralde "] 5 | description = "Test Rust examples in your documentation." 6 | repository = "https://github.com/assert-rs/docmatic" 7 | documentation = "https://docs.rs/docmatic" 8 | readme = "README.md" 9 | categories = ["development-tools", "development-tools::testing"] 10 | keywords = ["markdown", "documentation", "testing"] 11 | license = "MIT" 12 | 13 | [badges] 14 | travis-ci = { repository = "assert-rs/docmatic" } 15 | appveyor = { repository = "epage/docmatic" } 16 | 17 | [dependencies] 18 | which = "2.0" 19 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Nick Stevens 4 | 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docmatic 2 | 3 | > Be dogmatic about working documentation. 4 | 5 | [![Build Status](https://travis-ci.org/assert-rs/docmatic.svg?branch=master)](https://travis-ci.org/assert-rs/docmatic) 6 | [![Build status](https://ci.appveyor.com/api/projects/status/bte7gyfxylva10ax?svg=true)](https://ci.appveyor.com/project/epage/docmatic) 7 | [![Documentation](https://img.shields.io/badge/docs-master-blue.svg)](https://docs.rs/docmatic) 8 | ![License](https://img.shields.io/crates/l/docmatic.svg) 9 | [![Crates.io](https://img.shields.io/crates/v/docmatic.svg?maxAge=2592000)](https://crates.io/crates/docmatic) 10 | 11 | 12 | ## Usage 13 | 14 | First, add this to your `Cargo.toml`: 15 | 16 | ```toml 17 | [dev-dependencies] 18 | docmatic = "0.1" 19 | ``` 20 | 21 | Next, in your test file: 22 | 23 | ```rust 24 | extern crate docmatic; 25 | 26 | fn test_readme() { 27 | docmatic::assert_file("README.md"); 28 | } 29 | ``` 30 | 31 | For more information on using docmatic, look at the 32 | [documentation](https://docs.rs/docmatic) 33 | 34 | ## Why Docmatic? 35 | 36 | Compared to doing nothing: 37 | - When you have stale documentation, it gives a sour taste to those considering your crate 38 | 39 | Compared to [`#![doc(include = "../README.md")]`](https://github.com/yoshuawuyts/human-panic/tree/ed11055e0602c3c8d223ed8354058fefb9ac47ec) 40 | - Allows your README to focus on potential contributors and your API docs on potential users 41 | - Doesn't require nightly 42 | 43 | Compared to `rustdoc -L target/debug/deps/ --test README.md` 44 | - Docmatic pros: 45 | - Easier for contributors to know how to run 46 | - `rustdoc` pros: 47 | - Simple 48 | - No dependencies to muck with 49 | 50 | Compared to [skeptic](https://github.com/budziq/rust-skeptic): 51 | - Docmatic pros: 52 | - Fewer dependencies for faster build 53 | - Doesn't require exposing those dependencies to your users via a `[build-dependencies]` 54 | - Runs in the expected working directory 55 | - Skeptic pros: 56 | - Skeptic templates 57 | - Better integration with `cargo test` (each block is a distinct test) 58 | 59 | See [doc-comment](https://github.com/GuillaumeGomez/doc-comment) for another aproach. 60 | 61 | ## License 62 | 63 | `docmatic` is distributed under the terms of both the MIT license and the 64 | Apache License (Version 2.0). 65 | 66 | See LICENSE-APACHE, and LICENSE-MIT for details. 67 | 68 | 69 | ## Credits 70 | 71 | We're grateful for all of the work done on 72 | [skeptic](https://github.com/budziq/rust-skeptic), the spiritual predecessor to 73 | docmatic and the work of [people iterating on a lighter weight 74 | solution](https://github.com/budziq/rust-skeptic/issues/60). 75 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | global: 3 | TARGET: x86_64-pc-windows-msvc 4 | CHANNEL: stable 5 | matrix: 6 | - CHANNEL: 1.24.0 # oldest supported version 7 | - CHANNEL: stable 8 | - CHANNEL: beta 9 | - CHANNEL: nightly 10 | 11 | install: 12 | - ps: >- 13 | $Env:PATH += ';C:\msys64\usr\bin' 14 | - curl -sSf -o rustup-init.exe https://win.rustup.rs/ 15 | - rustup-init.exe -y --default-host %TARGET% --default-toolchain %CHANNEL% 16 | - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin 17 | - rustc -Vv 18 | - cargo -V 19 | 20 | test_script: 21 | - del /S/Q target\\debug\\deps\\*docmatic* || echo Not present # Avoid link problems with cached versions 22 | - cargo test --verbose 23 | 24 | cache: 25 | - C:\Users\appveyor\.cargo\registry 26 | - target 27 | 28 | notifications: 29 | - provider: Email 30 | on_build_success: false 31 | 32 | # Building is done in the test phase, so we disable Appveyor's build phase. 33 | build: false 34 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! docmatic: 2 | //! 3 | //! `docmatic` runs `rustdoc` on your documentation files. 4 | //! 5 | //! ## Writing code blocks 6 | //! 7 | //! See ["Documentation tests"](https://doc.rust-lang.org/beta/rustdoc/documentation-tests.html) 8 | //! for how to customize your code blocks being run as tests. 9 | //! 10 | //! ## Example 11 | //! 12 | //! First, add this to your `Cargo.toml`: 13 | //! 14 | //! ```toml 15 | //! [dev-dependencies] 16 | //! docmatic = "0.1" 17 | //! ``` 18 | //! 19 | //! Next, in your test file: 20 | //! 21 | //! ```rust 22 | //! extern crate docmatic; 23 | //! 24 | //! #[test] 25 | //! fn test_readme() { 26 | //! docmatic::assert_file("README.md"); 27 | //! } 28 | //! ``` 29 | 30 | extern crate which; 31 | 32 | use std::path; 33 | use std::ffi::OsStr; 34 | 35 | /// A specialized process builder managing a `rustdoc` test session. 36 | /// 37 | /// # Example 38 | /// 39 | /// The following code will test the crate README with the `docmatic` 40 | /// configuration set and a default library path: 41 | /// 42 | /// ```rust 43 | /// extern crate docmatic; 44 | /// 45 | /// use std::default::Default; 46 | /// 47 | /// fn test_readme() { 48 | /// docmatic::Assert::default() 49 | /// .cfg("docmatic") 50 | /// .test_file("README.md") 51 | /// } 52 | /// ``` 53 | pub struct Assert(std::process::Command); 54 | 55 | impl Assert { 56 | /// Construct a new `Assert` with no flags set. 57 | /// 58 | /// Will likely fail if you don't provide at least one library path 59 | /// containing the tested crate. Instead, you should probably use 60 | /// [`Assert::default`] 61 | /// 62 | /// [`Assert::default`]: #tymethod.default 63 | pub fn new() -> Self { 64 | let executable = which::which("rustdoc").expect("rustdoc not found"); 65 | Assert(std::process::Command::new(executable)) 66 | } 67 | 68 | /// Add a path to the library paths passed to `rustdoc`. 69 | pub fn library_path(&mut self, path: S) -> &mut Self 70 | where 71 | S: AsRef, 72 | { 73 | self.0.arg("--library-path").arg(path); 74 | self 75 | } 76 | 77 | /// Add a *cfg* to the configuration passed to `rustdoc`. 78 | pub fn cfg(&mut self, cfg: S) -> &mut Self 79 | where 80 | S: AsRef, 81 | { 82 | self.0.arg("--cfg").arg(cfg); 83 | self 84 | } 85 | 86 | /// Test the given file, and panics on failure. 87 | pub fn test_file

(&mut self, path: P) 88 | where 89 | P: AsRef, 90 | { 91 | let process = self.0.arg("--test").arg(path.as_ref()).spawn(); 92 | 93 | let result = process 94 | .expect("rustdoc is runnable") 95 | .wait() 96 | .expect("rustdoc can run"); 97 | 98 | assert!( 99 | result.success(), 100 | format!("Failed to run rustdoc tests on '{:?}'", path.as_ref()) 101 | ); 102 | } 103 | } 104 | 105 | impl Default for Assert { 106 | /// Create an `Assert` instance with the following default parameters: 107 | /// 108 | /// * `--library-path` set to the current *deps* directory (`target/debug/deps` or 109 | /// `target/release/deps` depending on the test compilation mode). 110 | /// 111 | fn default() -> Self { 112 | let mut assert = Self::new(); 113 | let current_exe = std::env::current_exe() 114 | .and_then(|p| p.canonicalize()) 115 | .expect("could not get path to test executable"); 116 | assert.library_path(current_exe.parent().expect("parent exists")); 117 | assert 118 | } 119 | } 120 | 121 | /// Test a single file with default parameters. 122 | pub fn assert_file

(documentation: P) 123 | where 124 | P: AsRef, 125 | { 126 | Assert::default().test_file(documentation); 127 | } 128 | -------------------------------------------------------------------------------- /tests/test_readme.rs: -------------------------------------------------------------------------------- 1 | extern crate docmatic; 2 | 3 | #[test] 4 | fn test_readme() { 5 | docmatic::assert_file("README.md"); 6 | } 7 | --------------------------------------------------------------------------------