Skip to content

Commit 3668171

Browse files
nlopesclaude
andcommitted
test(cli): fix flaky stdin and Windows line-wrap failures
json_output only pipes stdin when the input is `-`, so the child can't exit before the write and fail with a broken pipe. The missing-input test compares errors after joining miette's wrapped lines, which wrap the longer Windows OS error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y3gNNefj3Dtn8WRLNzapGr
1 parent 36b7542 commit 3668171

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎acdc-cli/tests/cli.rs‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ fn output_text(bytes: &[u8]) -> String {
6868
String::from_utf8_lossy(bytes).into_owned()
6969
}
7070

71+
/// Undoes miette's line wrapping: it wraps reports at 80 columns and continues
72+
/// them behind a `│` gutter, so long OS messages (such as Windows ones) span
73+
/// several lines.
74+
fn unwrapped(text: &str) -> String {
75+
text.split_whitespace()
76+
.filter(|word| *word != "│")
77+
.collect::<Vec<_>>()
78+
.join(" ")
79+
}
80+
81+
#[test]
82+
fn unwrapped_joins_miette_continuation_lines() {
83+
// Captured from a Windows runner, where the OS message pushes the line
84+
// past miette's 80 columns.
85+
let stderr = " × Parsing error: I/O error: The system cannot find the file specified. (os\r\n │ error 2)\r\n";
86+
assert!(unwrapped(stderr).contains("The system cannot find the file specified. (os error 2)"));
87+
}
88+
7189
#[cfg(any(
7290
feature = "html",
7391
feature = "lint",
@@ -343,9 +361,12 @@ fn missing_input_file_returns_a_failure() -> Result<(), Box<dyn Error>> {
343361
let output = run_acdc(&["convert", missing], None)?;
344362
let stderr = output_text(&output.stderr);
345363

346-
assert_eq!(output.status.code(), Some(1));
347-
assert!(stderr.contains(missing));
348-
assert!(stderr.contains(&read_error.to_string()));
364+
assert_eq!(output.status.code(), Some(1), "{stderr}");
365+
assert!(stderr.contains(missing), "{stderr}");
366+
assert!(
367+
unwrapped(&stderr).contains(&unwrapped(&read_error.to_string())),
368+
"expected {read_error:?} in:\n{stderr}"
369+
);
349370
Ok(())
350371
}
351372

‎acdc-cli/tests/json_output.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ fn native_json_is_available_in_every_build() -> Result<(), Box<dyn Error>> {
5050

5151
#[test]
5252
fn file_and_stdin_use_the_selected_language_mode() -> Result<(), Box<dyn Error>> {
53+
let source = "[title=\"*Title*\"]\nText.";
5354
let directory = tempfile::tempdir()?;
5455
let path = directory.path().join("input.adoc");
55-
fs::write(&path, "[title=\"*Title*\"]\nText.")?;
56+
fs::write(&path, source)?;
5657
for (mode, name, text) in [
5758
("asciidoctor", "span", "Title"),
5859
("draft", "raw", "*Title*"),
5960
] {
6061
for input in ["-", path.to_str().ok_or("path")?] {
61-
let output = run(
62-
&["parse", "--compatibility-mode", mode, input],
63-
"[title=\"*Title*\"]\nText.",
64-
)?;
62+
// A file input never reads stdin, so the process can exit before
63+
// anything is written to it. Only pipe the source for `-`.
64+
let stdin = if input == "-" { source } else { "" };
65+
let output = run(&["parse", "--compatibility-mode", mode, input], stdin)?;
6566
assert!(
6667
output.status.success(),
6768
"{}",

0 commit comments

Comments
 (0)