diff options
Diffstat (limited to 'tests/misc.rs')
-rw-r--r-- | tests/misc.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/misc.rs b/tests/misc.rs index 416e506..0db0606 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -1,3 +1,9 @@ +use std::{ + fs::File, + io::{BufRead, BufReader}, + process::Command, +}; + use similar_asserts::assert_eq; use walkdir::{DirEntry, WalkDir}; @@ -45,3 +51,31 @@ fn is_source_file(entry: &DirEntry) -> bool { !filename.starts_with('.') // .git, etc. } + +#[test] +fn example_output_in_readme() { + let output = Command::new("cargo") + .args(["run", "--example", "spans"]) + .output() + .unwrap() + .stdout; + + let expected = std::str::from_utf8(&output) + .unwrap() + .trim_end() + .lines() + .map(|s| s.trim_end().to_string()) + .collect::<Vec<_>>() + .join("\n"); + + let actual = BufReader::new(File::open("README.md").unwrap()) + .lines() + .flatten() + .skip_while(|l| l != "```output id=spans") + .skip(1) + .take_while(|l| l != "```") + .collect::<Vec<_>>() + .join("\n"); + + assert_eq!(actual, expected); +} |