Skip to content

Commit

Permalink
tests: Use doc::sync_command_output_to_markdown from test-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 31, 2025
1 parent 1dce71a commit 4b5c50f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build-context = "0.1"
easy-ext = "1"
fs-err = "3"
tempfile = { version = "3", default-features = false }
test-helper = { features = ["cli", "git"], git = "https://github.com/taiki-e/test-helper.git", rev = "295ad29" }
test-helper = { features = ["cli", "doc", "git"], git = "https://github.com/taiki-e/test-helper.git", rev = "20a3e10" }

[lints]
workspace = true
Expand Down
38 changes: 4 additions & 34 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
sync::Mutex,
};

use fs_err as fs;
use test_helper::git::assert_diff;

use self::auxiliary::*;
Expand Down Expand Up @@ -2027,37 +2026,8 @@ fn version() {

#[test]
fn update_readme() {
let new = &*test_helper::cli::CommandExt::assert_success(&mut cargo_hack(["--help"])).stdout;
let path = &Path::new(env!("CARGO_MANIFEST_DIR")).join("README.md");
let base = fs::read_to_string(path).unwrap();
let mut out = String::with_capacity(base.capacity());
let mut lines = base.lines();
let mut start = false;
let mut end = false;
while let Some(line) = lines.next() {
out.push_str(line);
out.push('\n');
if line == "<!-- readme-long-help:start -->" {
start = true;
out.push_str("```console\n");
out.push_str("$ cargo hack --help\n");
out.push_str(new);
for line in &mut lines {
if line == "<!-- readme-long-help:end -->" {
out.push_str("```\n");
out.push_str(line);
out.push('\n');
end = true;
break;
}
}
}
}
if start && end {
assert_diff(path, out);
} else if start {
panic!("missing `<!-- readme-long-help:end -->` comment in README.md");
} else {
panic!("missing `<!-- readme-long-help:start -->` comment in README.md");
}
let new = test_helper::cli::CommandExt::assert_success(&mut cargo_hack(["--help"])).stdout;
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("README.md");
let command = "cargo hack --help";
test_helper::doc::sync_command_output_to_markdown(path, "readme-long-help", command, new);
}

0 comments on commit 4b5c50f

Please sign in to comment.