You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.6KB

  1. $ErrorActionPreference = "Stop"
  2. $root = $PSScriptRoot
  3. $accepted = Join-Path $root "accepted"
  4. $rejected = Join-Path $root "rejected"
  5. $errors = New-Object System.Collections.Generic.List[string]
  6. function Test-SourceProfile([System.IO.FileInfo]$file) {
  7. if ($file.BaseName.Length -gt 12) {
  8. $errors.Add("$($file.FullName): base name exceeds 12 characters")
  9. }
  10. $bytes = [IO.File]::ReadAllBytes($file.FullName)
  11. if ($bytes.Length -gt 18999) {
  12. $errors.Add("$($file.FullName): $($bytes.Length) bytes exceeds 18999")
  13. }
  14. $text = [Text.Encoding]::ASCII.GetString($bytes)
  15. $lines = $text -split "`r`n|`n|`r"
  16. if ($lines.Count -gt 599) {
  17. $errors.Add("$($file.FullName): $($lines.Count) lines exceeds 599")
  18. }
  19. for ($i = 0; $i -lt $lines.Count; $i++) {
  20. $count = [Text.Encoding]::ASCII.GetByteCount($lines[$i])
  21. if ($count -gt 80) {
  22. $errors.Add("$($file.FullName):$($i + 1): $count bytes exceeds 80")
  23. }
  24. }
  25. }
  26. $acceptedSources = @(Get-ChildItem -LiteralPath $accepted -Filter "*.n8" -File)
  27. $rejectedSources = @(Get-ChildItem -LiteralPath $rejected -Filter "*.n8" -File)
  28. if ($acceptedSources.Count -eq 0) { $errors.Add("no accepted fixtures found") }
  29. if ($rejectedSources.Count -eq 0) { $errors.Add("no rejected fixtures found") }
  30. foreach ($file in $acceptedSources) {
  31. Test-SourceProfile $file
  32. $sidecar = [IO.Path]::ChangeExtension($file.FullName, ".expect")
  33. if (Test-Path -LiteralPath $sidecar) {
  34. $errors.Add("${sidecar}: accepted fixtures must not have diagnostic sidecars")
  35. }
  36. }
  37. foreach ($file in $rejectedSources) {
  38. Test-SourceProfile $file
  39. $sidecar = [IO.Path]::ChangeExtension($file.FullName, ".expect")
  40. if (-not (Test-Path -LiteralPath $sidecar)) {
  41. $errors.Add("$($file.FullName): missing .expect sidecar")
  42. continue
  43. }
  44. $expect = Get-Content -Raw -LiteralPath $sidecar
  45. $matches = [regex]::Matches($expect, '(?m)^diagnostic: ([A-Z][A-Z0-9_]+)$')
  46. if ($matches.Count -ne 1) {
  47. $errors.Add("${sidecar}: expected exactly one symbolic diagnostic")
  48. }
  49. }
  50. $orphanSidecars = @(Get-ChildItem -LiteralPath $rejected -Filter "*.expect" -File |
  51. Where-Object { -not (Test-Path -LiteralPath ([IO.Path]::ChangeExtension($_.FullName, ".n8"))) })
  52. foreach ($orphan in $orphanSidecars) {
  53. $errors.Add("$($orphan.FullName): orphan diagnostic sidecar")
  54. }
  55. if ($errors.Count -gt 0) {
  56. $errors | ForEach-Object { Write-Error $_ }
  57. exit 1
  58. }
  59. Write-Host ("grammar fixtures ok: {0} accepted, {1} rejected" -f
  60. $acceptedSources.Count, $rejectedSources.Count)

Powered by TurnKey Linux.