|
3 | 3 | // ignore-windows - this is a unix-specific test
|
4 | 4 | // ignore-emscripten no processes
|
5 | 5 | // ignore-sgx no processes
|
| 6 | +// ignore-tidy-linelength |
6 | 7 | use std::os::unix::process::CommandExt;
|
7 | 8 | use std::process::Command;
|
8 | 9 |
|
| 10 | +// `argv` attribute changes each time the test is made so needs to be retrieved dynamically |
| 11 | +// There is no public API to access it so we need to parse the debug output |
| 12 | +// Example of returned String: "[0x600010bb8000, 0x600010bb80a0]" |
| 13 | +fn get_argv(cmd: &Command) -> String { |
| 14 | + format!("{cmd:?}").split_once("Argv(").and_then(|(_, after)| after.split_once(")")).unwrap().0.to_string() |
| 15 | +} |
| 16 | + |
9 | 17 | fn main() {
|
10 | 18 | let mut command = Command::new("some-boring-name");
|
11 | 19 |
|
12 |
| - assert_eq!(format!("{:?}", command), r#""some-boring-name""#); |
| 20 | + assert_eq!(format!("{command:?}"), format!(r#"Command {{ program: "some-boring-name", args: ["some-boring-name"], argv: Argv({}), env: CommandEnv {{ clear: false, saw_path: false, vars: {{}} }}, cwd: None, uid: None, gid: None, saw_nul: false, groups: None, stdin: None, stdout: None, stderr: None, pgroup: None }}"#, get_argv(&command))); |
13 | 21 |
|
14 | 22 | command.args(&["1", "2", "3"]);
|
15 | 23 |
|
16 |
| - assert_eq!(format!("{:?}", command), r#""some-boring-name" "1" "2" "3""#); |
| 24 | + assert_eq!(format!("{command:?}"), format!(r#"Command {{ program: "some-boring-name", args: ["some-boring-name", "1", "2", "3"], argv: Argv({}), env: CommandEnv {{ clear: false, saw_path: false, vars: {{}} }}, cwd: None, uid: None, gid: None, saw_nul: false, groups: None, stdin: None, stdout: None, stderr: None, pgroup: None }}"#, get_argv(&command))); |
17 | 25 |
|
18 | 26 | command.arg0("exciting-name");
|
19 | 27 |
|
20 |
| - assert_eq!(format!("{:?}", command), r#"["some-boring-name"] "exciting-name" "1" "2" "3""#); |
| 28 | + assert_eq!(format!("{command:?}"), format!(r#"Command {{ program: "some-boring-name", args: ["exciting-name", "1", "2", "3"], argv: Argv({}), env: CommandEnv {{ clear: false, saw_path: false, vars: {{}} }}, cwd: None, uid: None, gid: None, saw_nul: false, groups: None, stdin: None, stdout: None, stderr: None, pgroup: None }}"#, get_argv(&command))); |
21 | 29 | }
|
0 commit comments