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