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.

64 lines
3.0KB

  1. # E02-S02: build the lexer test PRG and a fresh D81 holding the fixtures.
  2. # The host reference lexer must reproduce tests/lexer/golden/*.tokens exactly;
  3. # -UpdateGolden rewrites them instead (review the diff before committing).
  4. [CmdletBinding()]
  5. param([switch]$UpdateGolden)
  6. $ErrorActionPreference = "Stop"
  7. $project = Split-Path $PSScriptRoot -Parent
  8. Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
  9. . (Join-Path $project "tests\lexer\reference-lexer.ps1")
  10. $out = Join-Path $project "build\lexer-test"
  11. $golden = Join-Path $project "tests\lexer\golden"
  12. New-Item -ItemType Directory -Force -Path $out, $golden | Out-Null
  13. # Order must match the FIXTURE list in tests/lexer/lexer-test.s.
  14. $grammar = Join-Path $project "tests\grammar"
  15. $fixtures = [ordered]@{
  16. "minimal.n8" = Join-Path $grammar "accepted\minimal.n8"
  17. "decls.n8" = Join-Path $grammar "accepted\decls.n8"
  18. "arrays.n8" = Join-Path $grammar "accepted\arrays.n8"
  19. "exprs.n8" = Join-Path $grammar "accepted\exprs.n8"
  20. "forward.n8" = Join-Path $grammar "accepted\forward.n8"
  21. "nulls.n8" = Join-Path $grammar "accepted\nulls.n8"
  22. "stmts.n8" = Join-Path $grammar "accepted\stmts.n8"
  23. "tokens.n8" = Join-Path $project "tests\lexer\tokens.n8"
  24. "errors.n8" = Join-Path $project "tests\lexer\errors.n8"
  25. "badchar.n8" = Join-Path $grammar "rejected\bad_char.n8"
  26. }
  27. $link = Invoke-Nova128Link -Name "lexer-test" -BuildDir $out `
  28. -Config (Join-Path $project "cfg\compiler.cfg") -Sources @(
  29. (Join-Path $project "src\compiler\mmu.s"),
  30. (Join-Path $project "src\compiler\diskio.s"),
  31. (Join-Path $project "src\compiler\source.s"),
  32. (Join-Path $project "src\compiler\lexer.s"),
  33. (Join-Path $project "tests\lexer\lexer-test.s"))
  34. if ((Get-Nova128Label $link.Labels "test_entry") -ne 0x1C0D) { throw "test_entry is not at `$1C0D" }
  35. $files = @(@{ Name = "lexer-test"; Path = $link.Program; Type = "prg" })
  36. $mismatch = @()
  37. foreach ($name in $fixtures.Keys) {
  38. $bytes = ConvertTo-Nova128Petscii (Get-Content -Raw -LiteralPath $fixtures[$name])
  39. $pet = Join-Path $out ($name -replace '\.n8$', '.pet')
  40. [IO.File]::WriteAllBytes($pet, $bytes)
  41. $files += @{ Name = $name; Path = $pet; Type = "seq" }
  42. $tokens = (Get-ReferenceTokens $bytes) -join "`n"
  43. $goldenPath = Join-Path $golden ($name -replace '\.n8$', '.tokens')
  44. if ($UpdateGolden) {
  45. [IO.File]::WriteAllText($goldenPath, $tokens + "`n")
  46. } elseif (-not (Test-Path -LiteralPath $goldenPath)) {
  47. $mismatch += "$name (no golden file; run with -UpdateGolden and review)"
  48. } elseif (([IO.File]::ReadAllText($goldenPath).TrimEnd("`n")) -ne $tokens) {
  49. $mismatch += "$name (reference lexer differs from golden)"
  50. }
  51. }
  52. if ($mismatch) { throw ("golden check failed:`n " + ($mismatch -join "`n ")) }
  53. $disk = Join-Path $out "lexer-test.d81"
  54. New-Nova128Disk -Path $disk -Files $files
  55. Write-Host ("built {0}" -f $link.Program)
  56. Write-Host ("disk {0} ({1} fixtures); reference lexer matches golden files" -f $disk, $fixtures.Count)

Powered by TurnKey Linux.