@@ -23,22 +23,35 @@ function Normalize-Config {
2323 { $_ -in @ (' yaml' , ' yml' ) } {
2424 # For YAML files, preserve the structure and sort within each section
2525 $content = Get-Content $file - Raw
26- $runtimes = ($content | Select-String - Pattern " runtimes:[\s\S]*?tools:" - AllMatches).Matches.Value
27- $tools = ($content | Select-String - Pattern " tools:[\s\S]*?$" - AllMatches).Matches.Value
2826
29- # Sort runtimes section
30- $runtimes = $runtimes -replace " runtimes:" , " " -replace " tools:" , " "
31- $runtimes = $runtimes -split " `n " | Where-Object { $_ -match " ^\s*-\s* " } | Sort-Object
27+ # Extract sections using regex
28+ $runtimesMatch = [ regex ]::Match( $content , " runtimes:([\s\S]*?) tools:" )
29+ $toolsMatch = [ regex ]::Match( $content , " tools:([\s\S]*?)$ " )
3230
33- # Sort tools section
34- $tools = $tools -replace " tools:" , " "
35- $tools = $tools -split " `n " | Where-Object { $_ -match " ^\s*-\s*" } | Sort-Object
36-
37- # Reconstruct the YAML
38- " runtimes:"
39- $runtimes
40- " tools:"
41- $tools
31+ if ($runtimesMatch.Success -and $toolsMatch.Success ) {
32+ # Extract and sort runtimes
33+ $runtimes = $runtimesMatch.Groups [1 ].Value -split " `n " |
34+ Where-Object { $_ -match " ^\s*-\s*" } |
35+ Sort-Object |
36+ ForEach-Object { $_.Trim () }
37+
38+ # Extract and sort tools
39+ $tools = $toolsMatch.Groups [1 ].Value -split " `n " |
40+ Where-Object { $_ -match " ^\s*-\s*" } |
41+ Sort-Object |
42+ ForEach-Object { $_.Trim () }
43+
44+ # Return normalized content
45+ @ (
46+ " runtimes:"
47+ $runtimes | ForEach-Object { " $_ " }
48+ " tools:"
49+ $tools | ForEach-Object { " $_ " }
50+ )
51+ } else {
52+ Write-Error " Failed to parse YAML structure in $file "
53+ exit 1
54+ }
4255 }
4356 { $_ -in @ (' rc' , ' conf' , ' ini' , ' xml' ) } {
4457 Get-Content $file | ForEach-Object {
@@ -73,18 +86,16 @@ function Compare-Files {
7386 $expectedContent = Normalize- Config $_.FullName
7487 $actualContent = Normalize- Config $actualFile
7588
76- # Convert arrays to strings for comparison
77- $expectedStr = $expectedContent -join " `n "
78- $actualStr = $actualContent -join " `n "
79-
80- if ($expectedStr -ne $actualStr ) {
89+ # Compare line by line
90+ $diff = Compare-Object $expectedContent $actualContent - PassThru
91+ if ($diff ) {
8192 Write-Host " ❌ $label /$ ( $_.Name ) does not match expected"
8293 Write-Host " === Expected (normalized) ==="
8394 $expectedContent
8495 Write-Host " === Actual (normalized) ==="
8596 $actualContent
8697 Write-Host " === Diff ==="
87- Compare-Object $expectedContent $actualContent
98+ $diff
8899 Write-Host " ==================="
89100 exit 1
90101 }
0 commit comments