From 22499cb0ee62ff0fadfdabbb780ef44553607189 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Sep 2025 02:46:34 +0000 Subject: [PATCH] Address PR feedback: remove printlns and make [net] condition available by default Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com> --- examples/advanced_conditions.rs | 5 ----- src/lib.rs | 7 +++++-- src/run/params.rs | 8 +++++++- tests/advanced_conditions.rs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/examples/advanced_conditions.rs b/examples/advanced_conditions.rs index a0701ff..34b5110 100644 --- a/examples/advanced_conditions.rs +++ b/examples/advanced_conditions.rs @@ -3,17 +3,13 @@ use testscript_rs::testscript; fn main() -> Result<(), Box> { - println!("Running testscript with advanced condition support..."); - // Example 1: Basic usage with auto-detection - println!("\n=== Example 1: Auto-detect network and programs ==="); testscript::run("testdata") .auto_detect_network() .auto_detect_programs(&["docker", "git", "npm", "echo"]) .execute()?; // 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"); @@ -23,7 +19,6 @@ fn main() -> Result<(), Box> { .condition("docker", command_exists("docker")) .execute()?; - println!("All tests completed successfully!"); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 1a3f526..2ffe754 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,10 +169,13 @@ impl Builder { self } - /// Automatically detect network availability and set the 'net' condition + /// Re-detect network availability and update the 'net' condition + /// + /// The 'net' condition is automatically checked at startup, but this method + /// can be used to refresh the network status if needed. /// /// This will attempt to ping reliable hosts to determine if network - /// connectivity is available and set the condition accordingly. + /// connectivity is available and update the condition accordingly. pub fn auto_detect_network(mut self) -> Self { self.params = self.params.auto_detect_network(); self diff --git a/src/run/params.rs b/src/run/params.rs index 8048dba..90a15b9 100644 --- a/src/run/params.rs +++ b/src/run/params.rs @@ -39,6 +39,9 @@ impl RunParams { conditions.insert("debug".to_string(), cfg!(debug_assertions)); conditions.insert("release".to_string(), !cfg!(debug_assertions)); + // Add network condition - check if network is available by default + conditions.insert("net".to_string(), Self::check_network_available()); + // Check for common programs conditions.insert("exec:cat".to_string(), Self::program_exists("cat")); conditions.insert("exec:echo".to_string(), Self::program_exists("echo")); @@ -86,7 +89,10 @@ impl RunParams { self } - /// Automatically detect network availability and set the 'net' condition + /// Re-detect network availability and update the 'net' condition + /// + /// The 'net' condition is automatically checked at startup, but this method + /// can be used to refresh the network status if needed. pub fn auto_detect_network(mut self) -> Self { self.conditions .insert("net".to_string(), Self::check_network_available()); diff --git a/tests/advanced_conditions.rs b/tests/advanced_conditions.rs index 81ec285..b7632d6 100644 --- a/tests/advanced_conditions.rs +++ b/tests/advanced_conditions.rs @@ -152,3 +152,33 @@ stdout "env var is set" // Clean up std::env::remove_var("COMBINED_TEST"); } + +#[test] +fn test_net_condition_available_by_default() { + let testdata_dir = tempfile::tempdir().unwrap(); + + let test_content = r#" +# Test that [net] condition is available by default +# This should work without calling auto_detect_network() + +[net] exec echo "Network available" +[!net] exec echo "Network not available" + +exec echo "Test completed" +stdout "Test completed" +"#; + + fs::write( + testdata_dir.path().join("net_default_test.txt"), + test_content, + ) + .unwrap(); + + // Test WITHOUT calling auto_detect_network() - should still work + let result = testscript::run(testdata_dir.path().to_string_lossy()).execute(); + assert!( + result.is_ok(), + "Network condition should be available by default: {:?}", + result + ); +}