mirror of
https://github.com/imjasonh/testscript-rs
synced 2026-07-09 01:26:40 +00:00
Fix code formatting issues that caused CI failure
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
This commit is contained in:
parent
7e37906109
commit
d01b8865de
3 changed files with 33 additions and 15 deletions
|
|
@ -14,10 +14,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
// Example 2: Manual condition setting with environment variables
|
||||
println!("\n=== Example 2: Environment-based conditions ===");
|
||||
|
||||
|
||||
// Set a test environment variable
|
||||
std::env::set_var("CI", "true");
|
||||
|
||||
|
||||
testscript::run("testdata")
|
||||
.condition("net", check_network_available())
|
||||
.condition("docker", command_exists("docker"))
|
||||
|
|
@ -52,4 +52,4 @@ fn command_exists(program: &str) -> bool {
|
|||
.output()
|
||||
.map(|output| output.status.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,8 @@ impl RunParams {
|
|||
|
||||
/// Automatically detect network availability and set the 'net' condition
|
||||
pub fn auto_detect_network(mut self) -> Self {
|
||||
self.conditions.insert("net".to_string(), Self::check_network_available());
|
||||
self.conditions
|
||||
.insert("net".to_string(), Self::check_network_available());
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +97,8 @@ impl RunParams {
|
|||
pub fn auto_detect_programs(mut self, programs: &[&str]) -> Self {
|
||||
for program in programs {
|
||||
let condition_name = format!("exec:{}", program);
|
||||
self.conditions.insert(condition_name, Self::program_exists(program));
|
||||
self.conditions
|
||||
.insert(condition_name, Self::program_exists(program));
|
||||
}
|
||||
self
|
||||
}
|
||||
|
|
@ -120,7 +122,7 @@ impl RunParams {
|
|||
fn check_network_available() -> bool {
|
||||
// Try multiple reliable hosts to increase reliability
|
||||
let test_hosts = ["1.1.1.1", "8.8.8.8", "9.9.9.9"];
|
||||
|
||||
|
||||
for host in &test_hosts {
|
||||
let output = std::process::Command::new("ping")
|
||||
.args(if cfg!(windows) {
|
||||
|
|
@ -129,7 +131,7 @@ impl RunParams {
|
|||
vec!["-c", "1", "-W", "1", host]
|
||||
})
|
||||
.output();
|
||||
|
||||
|
||||
if let Ok(result) = output {
|
||||
if result.status.success() {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ stdout "negated env condition works"
|
|||
fs::write(testdata_dir.join("env_test.txt"), test_content).unwrap();
|
||||
|
||||
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
|
||||
assert!(result.is_ok(), "Environment condition test failed: {:?}", result);
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Environment condition test failed: {:?}",
|
||||
result
|
||||
);
|
||||
|
||||
// Clean up
|
||||
std::env::remove_var("TEST_CONDITION");
|
||||
|
|
@ -52,7 +56,11 @@ stdout "test completed"
|
|||
let result = testscript::run(testdata_dir.to_string_lossy())
|
||||
.auto_detect_network()
|
||||
.execute();
|
||||
assert!(result.is_ok(), "Network condition test failed: {:?}", result);
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Network condition test failed: {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -74,7 +82,11 @@ stdout "nonexistent program not found"
|
|||
let result = testscript::run(testdata_dir.to_string_lossy())
|
||||
.auto_detect_programs(&["echo", "nonexistent_program_xyz"])
|
||||
.execute();
|
||||
assert!(result.is_ok(), "Program detection test failed: {:?}", result);
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Program detection test failed: {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -92,14 +104,14 @@ fn test_runparams_condition_helpers() {
|
|||
#[test]
|
||||
fn test_manual_condition_files() {
|
||||
// Test our new testdata files to make sure they work properly
|
||||
|
||||
|
||||
// Test environment conditions file
|
||||
let result = testscript::run("testdata")
|
||||
.condition("net", true) // Force network to true for testing
|
||||
.auto_detect_programs(&["echo", "mkdir", "ls"])
|
||||
.execute();
|
||||
|
||||
// Note: This might fail if some testdata files have issues,
|
||||
|
||||
// Note: This might fail if some testdata files have issues,
|
||||
// but our specific files should work
|
||||
if let Err(e) = result {
|
||||
println!("Some testdata files failed (expected): {}", e);
|
||||
|
|
@ -131,8 +143,12 @@ stdout "env var is set"
|
|||
.auto_detect_network()
|
||||
.auto_detect_programs(&["echo"])
|
||||
.execute();
|
||||
assert!(result.is_ok(), "Combined condition test failed: {:?}", result);
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Combined condition test failed: {:?}",
|
||||
result
|
||||
);
|
||||
|
||||
// Clean up
|
||||
std::env::remove_var("COMBINED_TEST");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue