diff --git a/src/lib.rs b/src/lib.rs index 62c0a70..21e6ab6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,9 +71,9 @@ fn run(params: &mut RunParams, test_data_glob: &str) -> Result<()> { (".", test_data_glob) }; - // Convert glob pattern to a simple matcher + // Convert glob pattern to a simple matcher with Unicode support let pattern_regex = pattern.replace("*", ".*"); - let regex = regex::Regex::new(&format!("^{}$", pattern_regex))?; + let regex = regex::Regex::new(&format!("(?u)^{}$", pattern_regex))?; // Walk the directory and collect matching files for entry in WalkDir::new(base_dir).min_depth(1).max_depth(1) { diff --git a/src/run/commands.rs b/src/run/commands.rs index 0e4c8ed..64c7337 100644 --- a/src/run/commands.rs +++ b/src/run/commands.rs @@ -218,7 +218,14 @@ impl TestEnvironment { /// Search for a pattern in files (like grep) pub fn grep_files(&mut self, pattern: &str, files: &[String]) -> Result<()> { - let regex = Regex::new(pattern) + // Enable Unicode mode for proper Unicode character matching in grep patterns + let pattern_with_flags = if pattern.starts_with("(?") { + // Pattern already has flags, don't add more + pattern.to_string() + } else { + format!("(?u){}", pattern) + }; + let regex = Regex::new(&pattern_with_flags) .map_err(|e| Error::command_error("grep", format!("Invalid regex: {}", e)))?; let mut _found_matches = false; diff --git a/src/run/environment.rs b/src/run/environment.rs index f8352f7..b7ef0ad 100644 --- a/src/run/environment.rs +++ b/src/run/environment.rs @@ -236,7 +236,9 @@ impl TestEnvironment { || expected_substituted.contains('*') || expected_substituted.contains('.') { - let regex_pattern = format!("(?s){}", expected_substituted); // (?s) enables DOTALL mode + // Enable DOTALL mode (?s) for . to match newlines + // Enable Unicode mode (?u) for proper Unicode character matching + let regex_pattern = format!("(?su){}", expected_substituted); let regex = Regex::new(®ex_pattern) .map_err(|e| Error::command_error(output_type, format!("Invalid regex: {}", e)))?; diff --git a/tests/unicode_handling.rs b/tests/unicode_handling.rs index 04918fb..20b0621 100644 --- a/tests/unicode_handling.rs +++ b/tests/unicode_handling.rs @@ -19,7 +19,7 @@ stdout "Success ✓" fs::write(&test_file, test_content).unwrap(); let result = testscript::run(testdata_dir.to_string_lossy()).execute(); - + assert!( result.is_ok(), "Unicode stdout exact match should work: {:?}", @@ -42,7 +42,7 @@ stderr "Error ✗" fs::write(&test_file, test_content).unwrap(); let result = testscript::run(testdata_dir.to_string_lossy()).execute(); - + assert!( result.is_ok(), "Unicode stderr exact match should work: {:?}", @@ -65,7 +65,7 @@ stdout "Success .* completed" fs::write(&test_file, test_content).unwrap(); let result = testscript::run(testdata_dir.to_string_lossy()).execute(); - + assert!( result.is_ok(), "Unicode in regex pattern should work: {:?}", @@ -88,7 +88,7 @@ stdout "Tests: ✓ ✗ ⚠ ℹ" fs::write(&test_file, test_content).unwrap(); let result = testscript::run(testdata_dir.to_string_lossy()).execute(); - + assert!( result.is_ok(), "Multiple Unicode characters should work: {:?}", @@ -111,12 +111,8 @@ stdout "Status: 🎉 Success!" fs::write(&test_file, test_content).unwrap(); let result = testscript::run(testdata_dir.to_string_lossy()).execute(); - - assert!( - result.is_ok(), - "Emoji in output should work: {:?}", - result - ); + + assert!(result.is_ok(), "Emoji in output should work: {:?}", result); } #[test] @@ -134,7 +130,7 @@ stdout "Result: ✓ \(success\)" fs::write(&test_file, test_content).unwrap(); let result = testscript::run(testdata_dir.to_string_lossy()).execute(); - + assert!( result.is_ok(), "Unicode with regex special chars should work: {:?}", @@ -157,10 +153,36 @@ stdout "A.B" fs::write(&test_file, test_content).unwrap(); let result = testscript::run(testdata_dir.to_string_lossy()).execute(); - + assert!( result.is_ok(), "Dot in regex should match Unicode character: {:?}", result ); } + +#[test] +fn test_grep_with_unicode() { + let temp_dir = TempDir::new().unwrap(); + let testdata_dir = temp_dir.path().join("testdata"); + fs::create_dir(&testdata_dir).unwrap(); + + // Test grep command with Unicode content + let test_content = r#"grep "Success.*✓" test.txt +stdout "test.txt:1: Success ✓" + +-- test.txt -- +Success ✓ +"#; + + let test_file = testdata_dir.join("grep_unicode_test.txt"); + fs::write(&test_file, test_content).unwrap(); + + let result = testscript::run(testdata_dir.to_string_lossy()).execute(); + + assert!( + result.is_ok(), + "Grep with Unicode should work: {:?}", + result + ); +}