Skip to content

Commit aa47895

Browse files
committed
integration-tests: Migrate to xshell cmd! macro
Replace verbose std::process::Command usage with xshell's cmd! macro throughout the integration tests. This provides cleaner syntax with safe variable interpolation and reduces boilerplate significantly. Key patterns used: - cmd!(sh, "...").read()? for capturing stdout - cmd!(sh, "...").ignore_status().output()? for fallible commands - {var} interpolation and {args...} array expansion The run_bcvk() helper and VmCleanupGuard Drop impl intentionally retain std::process::Command for consistent CapturedOutput handling and because Shell::new() is fallible in Drop contexts. Assisted-by: Claude Code (Sonnet 4) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent dec2d7c commit aa47895

9 files changed

Lines changed: 968 additions & 1504 deletions

File tree

crates/integration-tests/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ pub static PARAMETERIZED_INTEGRATION_TESTS: [ParameterizedIntegrationTest];
6666
///
6767
/// ```ignore
6868
/// fn test_basic_functionality() -> Result<()> {
69-
/// let output = run_bcvk(&["some", "args"])?;
70-
/// output.assert_success("test");
69+
/// let sh = shell()?;
70+
/// let bck = get_bck_command()?;
71+
/// cmd!(sh, "{bck} some args").run()?;
7172
/// Ok(())
7273
/// }
7374
/// integration_test!(test_basic_functionality);
@@ -91,8 +92,9 @@ macro_rules! integration_test {
9192
///
9293
/// ```ignore
9394
/// fn test_with_image(image: &str) -> Result<()> {
94-
/// let output = run_bcvk(&["command", image])?;
95-
/// output.assert_success("test");
95+
/// let sh = shell()?;
96+
/// let bck = get_bck_command()?;
97+
/// cmd!(sh, "{bck} command {image}").run()?;
9698
/// Ok(())
9799
/// }
98100
/// parameterized_integration_test!(test_with_image);

crates/integration-tests/src/main.rs

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Integration tests for bcvk
22
3-
use camino::Utf8Path;
43
use std::process::Output;
54

5+
use camino::Utf8Path;
6+
67
use color_eyre::eyre::{eyre, Context};
78
use color_eyre::Result;
89
use libtest_mimic::{Arguments, Trial};
@@ -26,6 +27,11 @@ mod tests {
2627
pub mod to_disk;
2728
}
2829

30+
/// Create a new xshell Shell for running commands
31+
pub(crate) fn shell() -> Result<Shell> {
32+
Shell::new().map_err(|e| eyre!("Failed to create shell: {}", e))
33+
}
34+
2935
/// Get the path to the bcvk binary, checking BCVK_PATH env var first, then falling back to "bcvk"
3036
pub(crate) fn get_bck_command() -> Result<String> {
3137
if let Some(path) = std::env::var("BCVK_PATH").ok() {
@@ -97,16 +103,6 @@ impl CapturedOutput {
97103
}
98104
}
99105

100-
/// Assert that the command succeeded, printing debug info on failure
101-
pub fn assert_success(&self, context: &str) {
102-
assert!(
103-
self.output.status.success(),
104-
"{} failed: {}",
105-
context,
106-
self.stderr
107-
);
108-
}
109-
110106
/// Get the exit code
111107
pub fn exit_code(&self) -> Option<i32> {
112108
self.output.status.code()
@@ -118,47 +114,16 @@ impl CapturedOutput {
118114
}
119115
}
120116

121-
/// Run a command, capturing output
122-
pub(crate) fn run_command(program: &str, args: &[&str]) -> std::io::Result<CapturedOutput> {
123-
let output = std::process::Command::new(program).args(args).output()?;
124-
Ok(CapturedOutput::new(output))
125-
}
126-
127-
/// Run the bcvk command, capturing output
128-
pub(crate) fn run_bcvk(args: &[&str]) -> std::io::Result<CapturedOutput> {
129-
let bck = get_bck_command().expect("Failed to get bcvk command");
130-
run_command(&bck, args)
131-
}
132-
133-
/// Run the bcvk command with inherited stdout/stderr (no capture)
134-
/// Use this when you just need to verify the command succeeded without checking output
135-
pub(crate) fn run_bcvk_nocapture(args: &[&str]) -> std::io::Result<()> {
136-
let bck = get_bck_command().expect("Failed to get bcvk command");
137-
let status = std::process::Command::new(&bck).args(args).status()?;
138-
assert!(
139-
status.success(),
140-
"bcvk command failed with args: {:?}",
141-
args
142-
);
143-
Ok(())
144-
}
145-
146117
fn test_images_list() -> Result<()> {
147118
println!("Running test: bcvk images list --json");
148119

149-
let sh = Shell::new()?;
120+
let sh = shell()?;
150121
let bck = get_bck_command()?;
151122

152123
// Run the bcvk images list command with JSON output
153-
let output = cmd!(sh, "{bck} images list --json").output()?;
154-
155-
if !output.status.success() {
156-
let stderr = String::from_utf8_lossy(&output.stderr);
157-
return Err(eyre!("Failed to run 'bcvk images list --json': {}", stderr));
158-
}
124+
let stdout = cmd!(sh, "{bck} images list --json").read()?;
159125

160126
// Parse the JSON output
161-
let stdout = String::from_utf8(output.stdout)?;
162127
let images: Value = serde_json::from_str(&stdout).context("Failed to parse JSON output")?;
163128

164129
// Verify the structure and content of the JSON

0 commit comments

Comments
 (0)