Skip to content

Commit ecc8d9b

Browse files
author
Joe Grund
committed
Fix bugs
Signed-off-by: Joe Grund <[email protected]>
1 parent b156f60 commit ecc8d9b

File tree

6 files changed

+91
-9
lines changed

6 files changed

+91
-9
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.x86_64-unknown-linux-musl]
2+
linker = "rust-lld"

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ serde = { version = "1", features = ["derive"] }
2626
serde_json = "1"
2727
tempfile = "3"
2828
tokio = "1"
29+
insta = "1"
2930

3031
[workspace.lints.rust]
3132
unreachable_pub = "deny"

commandeer-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ commandeer-macros = { path = "../commandeer-macros" }
2626

2727
[dev-dependencies]
2828
serial_test.workspace = true
29+
insta.workspace = true

commandeer-test/src/lib.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ impl Commandeer {
176176

177177
let fixture = dir.join("testcmds").join(test_name);
178178

179+
if fixture.exists() && mode == Mode::Record {
180+
std::fs::remove_file(&fixture).expect("Failed to remove existing fixture file");
181+
}
182+
179183
let mock_runner = CargoBuild::new()
180184
.manifest_path(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("Cargo.toml"))
181185
.package("commandeer-cli")
@@ -205,16 +209,11 @@ impl Commandeer {
205209

206210
let wrapper = format!(
207211
r#"#!/usr/bin/env bash
208-
exec env PATH="{}" {} {}{}--file {} --command {command_name} "$@"
212+
exec env PATH="{}" {} {} --file {} --command {command_name} "$@"
209213
"#,
210214
self.original_path,
211215
self.mock_runner.path().display(),
212216
self.mode,
213-
if self.mode == Mode::Record {
214-
" --truncate "
215-
} else {
216-
" "
217-
},
218217
self.fixture.display(),
219218
);
220219

@@ -274,10 +273,20 @@ mod tests {
274273
async fn async_replay() {
275274
let output = std::process::Command::new("date").output().unwrap();
276275

277-
assert!(output.status.success());
276+
insta::assert_debug_snapshot!(output, @r#"
277+
Output {
278+
status: ExitStatus(
279+
unix_wait_status(
280+
0,
281+
),
282+
),
283+
stdout: "Wed Aug 20 12:46:19 EDT 2025\n",
284+
stderr: "",
285+
}
286+
"#);
278287
}
279288

280-
#[commandeer(Record, "git")]
289+
#[commandeer(Replay, "git", "date")]
281290
#[test]
282291
#[serial_test::serial]
283292
fn test_flag_args() {
@@ -286,6 +295,30 @@ mod tests {
286295
.output()
287296
.unwrap();
288297

289-
assert!(output.status.success());
298+
insta::assert_debug_snapshot!(output, @r#"
299+
Output {
300+
status: ExitStatus(
301+
unix_wait_status(
302+
0,
303+
),
304+
),
305+
stdout: "git version 2.51.0\n",
306+
stderr: "",
307+
}
308+
"#);
309+
310+
let output = std::process::Command::new("date").output().unwrap();
311+
312+
insta::assert_debug_snapshot!(output, @r#"
313+
Output {
314+
status: ExitStatus(
315+
unix_wait_status(
316+
0,
317+
),
318+
),
319+
stdout: "Thu Aug 21 14:54:45 EDT 2025\n",
320+
stderr: "",
321+
}
322+
"#);
290323
}
291324
}

commandeer-test/testcmds/cmds_test_flag_args.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"commands": {
3+
"date:": [
4+
{
5+
"binary_name": "date",
6+
"args": [],
7+
"stdout": "Thu Aug 21 14:54:45 EDT 2025\n",
8+
"stderr": "",
9+
"exit_code": 0
10+
}
11+
],
312
"git:--version": [
413
{
514
"binary_name": "git",

0 commit comments

Comments
 (0)