Skip to content

Use doc_comment for README doctests #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ keywords = ["ansi", "escape", "terminal"]

[dependencies]
vte = "0.10"

[dev-dependencies]
doc-comment = "0.3"
38 changes: 6 additions & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,42 +151,16 @@ where
}
}

#[cfg(doctest)]
extern crate doc_comment;

#[cfg(doctest)]
doc_comment::doctest!("../README.md", readme);

#[cfg(test)]
mod tests {
use super::*;

use std::env;
use std::env::consts::EXE_EXTENSION;
use std::path::Path;
use std::process::Command;

#[test]
fn readme_test() {
let rustdoc = Path::new("rustdoc").with_extension(EXE_EXTENSION);
let readme = Path::new(file!())
.parent()
.unwrap()
.parent()
.unwrap()
.join("README.md");
let exe = env::current_exe().unwrap();
let outdir = exe.parent().unwrap();
let mut cmd = Command::new(rustdoc);
cmd.args(&["--verbose", "--test", "-L"])
.arg(&outdir)
.arg(&readme);
println!("{:?}", cmd);
let result = cmd
.spawn()
.expect("Failed to spawn process")
.wait()
.expect("Failed to run process");
assert!(
result.success(),
"Failed to run rustdoc tests on README.md!"
);
}

fn assert_parsed(input: &[u8], expected: &[u8]) {
let bytes = strip(input).expect("Failed to strip escapes");
assert_eq!(bytes, expected);
Expand Down