|
17 | 17 | use std::path::PathBuf; |
18 | 18 | use std::time::{Duration, Instant}; |
19 | 19 |
|
20 | | -/// Strip ANSI escape codes (e.g. colors) from a string, for readable failure |
21 | | -/// messages. Not required for the assertions below to pass — the driver's |
22 | | -/// own tracing output carries ANSI codes even when captured non-interactively, |
23 | | -/// but they never fragment the substrings these tests check for — this is |
24 | | -/// purely so a failed assertion's `{clean}` output is readable. |
25 | | -fn strip_ansi(s: &str) -> String { |
26 | | - let mut out = String::with_capacity(s.len()); |
27 | | - let mut chars = s.chars().peekable(); |
28 | | - |
29 | | - while let Some(c) = chars.next() { |
30 | | - if c == '\x1b' { |
31 | | - if chars.peek() == Some(&'[') { |
32 | | - chars.next(); |
33 | | - for c in chars.by_ref() { |
34 | | - if c.is_ascii_alphabetic() { |
35 | | - break; |
36 | | - } |
37 | | - } |
38 | | - } |
39 | | - } else { |
40 | | - out.push(c); |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - out |
45 | | -} |
46 | | - |
47 | 20 | /// Run `openshell-driver-podman` pointed at a Podman socket that does not |
48 | 21 | /// exist, and wait for it to exit. |
49 | 22 | /// |
50 | 23 | /// The driver retries a handful of times before giving up (to tolerate the |
51 | 24 | /// socket briefly re-activating), so this can take several seconds. |
52 | 25 | async fn run_with_unreachable_podman_socket() -> (String, i32, Duration, PathBuf) { |
53 | 26 | let tmpdir = tempfile::tempdir().expect("create isolated socket dir"); |
54 | | - let missing_socket = tmpdir |
55 | | - .path() |
56 | | - .join("openshell-driver-podman-nonexistent.sock"); |
| 27 | + // Use a short relative path so miette cannot insert a line-wrap gutter |
| 28 | + // inside it on platforms with long temporary-directory paths. |
| 29 | + let missing_socket = PathBuf::from("missing-podman.sock"); |
57 | 30 |
|
58 | 31 | let start = Instant::now(); |
59 | 32 | let mut cmd = tokio::process::Command::new(env!("CARGO_BIN_EXE_openshell-driver-podman")); |
60 | 33 | cmd.arg("--podman-socket") |
61 | 34 | .arg(&missing_socket) |
| 35 | + .current_dir(tmpdir.path()) |
62 | 36 | .kill_on_drop(true) |
63 | 37 | .stdout(std::process::Stdio::piped()) |
64 | 38 | .stderr(std::process::Stdio::piped()); |
@@ -102,15 +76,14 @@ async fn driver_error_names_unreachable_socket() { |
102 | 76 | let (output, code, _, missing_socket) = run_with_unreachable_podman_socket().await; |
103 | 77 |
|
104 | 78 | assert_ne!(code, 0); |
105 | | - let clean = strip_ansi(&output); |
106 | 79 |
|
107 | 80 | assert!( |
108 | | - clean.contains("connection error"), |
109 | | - "driver error should describe a connection failure:\n{clean}" |
| 81 | + output.contains("connection error"), |
| 82 | + "driver error should describe a connection failure:\n{output}" |
110 | 83 | ); |
111 | 84 | assert!( |
112 | | - clean.contains(missing_socket.to_str().expect("socket path is utf-8")), |
113 | | - "driver error should name the unreachable socket path {}:\n{clean}", |
| 85 | + output.contains(missing_socket.to_str().expect("socket path is utf-8")), |
| 86 | + "driver error should name the unreachable socket path {}:\n{output}", |
114 | 87 | missing_socket.display() |
115 | 88 | ); |
116 | 89 | } |
0 commit comments